I'm trying to use solargraph with Sublime LSP. For some reason I can't get this working.
{
"clients":
{
"solargraph":
{
"enabled": true,
"command":
[
"solargraph",
"socket",
],
"languageid": "ruby",
"scopes":
[
"source.ruby"
],
"syntaxes": [
"Packages/Ruby/Ruby.sublime-syntax"
],
}
},
}
Using the pretty straightforward config, two things happen. It successfully starts the server and sends the initialize message over stdio. After that, nothing happens. Qutting, Sublime, will also leave the server running. I've also tried connecting over TCP by specify the port "tcp_port": 7658. It then seems to connect after initialize but blows up with the following stacktrace:
LSP: starting ['solargraph', 'socket', '--host=localhost']
LSP: connecting to localhost:7658
LSP: --> initialize
LSP: socket send
server: /usr/local/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.5/lib/eventmachine.rb:530:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
server: from /usr/local/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.5/lib/eventmachine.rb:530:in `start_server'
server: from /usr/local/lib/ruby/gems/2.5.0/gems/solargraph-0.18.2/lib/solargraph/shell.rb:56:in `block in socket'
server: from /usr/local/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.5/lib/eventmachine.rb:194:in `run_machine'
server: from /usr/local/lib/ruby/gems/2.5.0/gems/eventmachine-1.2.5/lib/eventmachine.rb:194:in `run'
server: from /usr/local/lib/ruby/gems/2.5.0/gems/solargraph-0.18.2/lib/solargraph/shell.rb:49:in `socket'
server: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
server: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
server: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
server: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/base.rb:466:in `start'
server: from /usr/local/lib/ruby/gems/2.5.0/gems/solargraph-0.18.2/bin/solargraph:5:in `<top (required)>'
server: from /usr/local/bin/solargraph:23:in `load'
server: from /usr/local/bin/solargraph:23:in `<main>'
LSP: LSP stderr process ended.
Any ideas of what's going on? If I can, I'd like to help in anyway possible. 馃檪
It looks like another solargraph socket process is already running on port 7658. It could either be an old server from one of your previous attempts, or if you started the server manually, Sublime's language client might be trying to start its own process. (As I understand the specification, clients typically assume responsibility for starting and stopping the server.)
I haven't tested the LSP server in clients other than VSCode, so any help or feedback is appreciated.
@castwide sorry, I accidentally pasted the wrong stacktrace. This is what I was getting:
LSP: starting ['solargraph', 'socket', '--host=localhost']
LSP: connecting to localhost:7658
Package Control: Skipping automatic upgrade, last run at 2018-04-11 17:38:40, next run at 2018-04-11 18:38:40 or after
server: Solargraph is listening PORT=7658 PID=42912
LSP: --> initialize
LSP: socket send
server: no implicit conversion of nil into Hash
server: /usr/local/lib/ruby/gems/2.5.0/gems/solargraph-0.18.2/lib/solargraph/language_server/host.rb:31:in `merge!'
server: /usr/local/lib/ruby/gems/2.5.0/gems/solargraph-0.18.2/lib/solargraph/language_server/host.rb:31:in `configure'
server: /usr/local/lib/ruby/gems/2.5.0/gems/solargraph-0.18.2/lib/solargraph/language_server/message/initialize.rb:6:in `process'
server: /usr/local/lib/ruby/gems/2.5.0/gems/solargraph-0.18.2/lib/solargraph/language_server/host.rb:54:in `start'
server: /usr/local/lib/ruby/gems/2.5.0/gems/solargraph-0.18.2/lib/solargraph/language_server/transport/socket.rb:28:in `block in process'
LSP: {'code': -32603, 'message': 'no implicit conversion of nil into Hash'}
This is what I'm getting when actually specifying the port. Trying to use the stdio-mode does not work at all. For reference: Here is the code used when using stdio-mode: https://github.com/tomv564/LSP/blob/master/plugin/core/rpc.py#L52
The entrypoint of the client is here: https://github.com/tomv564/LSP/blob/master/plugin/core/main.py#L184
Ah, I see the problem now. The server assumes that the client's initialize method includes an initializationOptions parameter, but Sublime isn't sending one. There should be an easy fix for that. I'll make a patch for it.
There might be a workaround in the meantime. Sublime should have some mechanism for passing options. The error might go away if you set one. The server accepts any key/value pair.
I can pass initializationOptions via the config. What parameters are needed? I tried setting it to an empty {}. But that didn't do it.
The only active option is diagnostics, which will activate RuboCop linting if it's set to 'rubocop'. Any JSON key and value should satisfy the server, though.
Pushed a commit to fix this in the next version: https://github.com/castwide/solargraph/commit/121aab6dde8f64b9175e580f9ebf1ebc3f1b1a17
@castwide thanks a lot! 馃憤 I got it working now.
Hey @KevinSjoberg! Is it still working for you? How did you configure sublime? I'm trying to make it work here but no success so far =(
@douglas I just tried my previous setup and it's not working. Nothing is happening anymore. I'll invest further when I have time.
@douglas @KevinSjoberg If there are any error messages or other information that might help me troubleshoot, please let me know.
@castwide I'm not sure this is a solargraph issue. Could very well be the Sublime LSP plugin. Will investigate further.
I opened an issue for Sublime LSP (I extended the config for Rails support btw).
See it here (plus debug output):
https://github.com/tomv564/LSP/issues/354
Maybe we can figure out on which side the problem is. I'm tempted to say Sublime LSP as solargraph works for Atom and VSCode for me.
Okay the problem with Sublime LSP comes from the sublime plugin.
It partially works for me until this error is triggered: https://github.com/tomv564/LSP/issues/348
@tomv564 is working on a fix.
As soon as the issue on the plugin side is fixed I'll create a pull request there to get the ruby/rails config working out of the box.
I can use refactoring, references, completion etc. with these LSP settings (though currently unstable):
{
"clients":
{
"ruby":
{
"command":
[
"solargraph",
"socket"
],
"tcp_port": 7658,
"enabled": true,
"languageId": "ruby",
"scopes":
[
"source.ruby",
"source.ruby.rails"
],
"syntaxes":
[
"Packages/Ruby/Ruby.sublime-syntax",
"Packages/Rails/Ruby on Rails.sublime-syntax"
]
}
}
}
FYI, the completions broke in LSP as solargraph sends completionItemKinds that we didn't support yet. Instead of strictly trying to catch unknown values, we now ignore them, hoping that our users/contributors point out new additions :)
The LSP support has been fixed and it was working fine for me (see screenshot). Unfortunately the update to 0.23.0 broke the support again for Sublime. If I downgrade to 0.22.0 it works again using my config.
Seems to me like a bug or do I need a different config now?

EDIT: I checked vscode support for 0.23.0 and this one still works.
@gobijan Confirmed. The problem was a bug in the Solargraph LSP. The initial capabilities were not getting configured for clients that do not use dynamic registration, including Sublime and Atom.
I fast-tracked a patch and updated to gem version 0.23.2. Please let me know if the problem persists.
Works! Perfect! Thanks a lot.
The problems related to this issue should all be addressed. If anyone still has problems integrating Solargraph into Sublime, please feel free to open a new issue.
Most helpful comment
Okay the problem with Sublime LSP comes from the sublime plugin.
It partially works for me until this error is triggered: https://github.com/tomv564/LSP/issues/348
@tomv564 is working on a fix.
As soon as the issue on the plugin side is fixed I'll create a pull request there to get the ruby/rails config working out of the box.
I can use refactoring, references, completion etc. with these LSP settings (though currently unstable):