castwide / vscode-solargraph

A Visual Studio Code extension for Solargraph.
Other
425 stars 23 forks source link

Server initialization fails after update #92

Closed gottlike closed 5 years ago

gottlike commented 5 years ago

After updating all gems to the latest version, the solargraph extension isn't working anymore. I was able to get a stack trace by switching to stdio as transport:

Solargraph is listening on stdio PID=14525
undefined method `each' for nil:NilClass
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/lib/solargraph/language_server/host.rb:227:in `prepare_folders'
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/lib/solargraph/language_server/message/initialize.rb:9:in `process'
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/lib/solargraph/language_server/host.rb:79:in `start'
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/lib/solargraph/language_server/transport/adapter.rb:17:in `process'
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/lib/solargraph/language_server/transport/adapter.rb:11:in `block in opening'
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/lib/solargraph/language_server/transport/data_reader.rb:53:in `parse_message_from_buffer'
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/lib/solargraph/language_server/transport/data_reader.rb:31:in `block in receive'
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/lib/solargraph/language_server/transport/data_reader.rb:26:in `each_char'
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/lib/solargraph/language_server/transport/data_reader.rb:26:in `receive'
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/lib/solargraph/language_server/transport/adapter.rb:25:in `sending'
/var/lib/gems/2.5.0/gems/backport-0.2.0/lib/backport/client.rb:32:in `sending'
/var/lib/gems/2.5.0/gems/backport-0.2.0/lib/backport/server/connectable.rb:7:in `block in tick'
/var/lib/gems/2.5.0/gems/backport-0.2.0/lib/backport/server/connectable.rb:5:in `each'
/var/lib/gems/2.5.0/gems/backport-0.2.0/lib/backport/server/connectable.rb:5:in `tick'
/var/lib/gems/2.5.0/gems/backport-0.2.0/lib/backport/machine.rb:56:in `each'
/var/lib/gems/2.5.0/gems/backport-0.2.0/lib/backport/machine.rb:56:in `run_server_thread'
/var/lib/gems/2.5.0/gems/backport-0.2.0/lib/backport/machine.rb:17:in `run'
/var/lib/gems/2.5.0/gems/backport-0.2.0/lib/backport.rb:49:in `run'
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/lib/solargraph/shell.rb:39:in `stdio'
/var/lib/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
/var/lib/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
/var/lib/gems/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
/var/lib/gems/2.5.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
/var/lib/gems/2.5.0/gems/solargraph-0.30.0/bin/solargraph:5:in `<top (required)>'
/usr/local/bin/solargraph:23:in `load'
/usr/local/bin/solargraph:23:in `<main>'
[Error - 12:06:30 PM] Server initialization failed.
  Message: [NoMethodError] undefined method `each' for nil:NilClass
  Code: -32603 
castwide commented 5 years ago

Confirmed. I was able to reproduce by opening VS Code with a single Ruby file instead of a folder. I should be able to fix it in the gem.

(Side note: Patch updates of the gem and extension were released today, but they don't affect this particular issue.)

castwide commented 5 years ago

The language server needs better handling of cases where a Ruby file is not associated with a project (i.e., a workspace folder or a root folder). Fixing it is not trivial, but it's certainly a common use case, so I'll prioritize it and try to have a patch ready by Monday.

Temporary workaround: Start VS Code by opening the folder that contains the Ruby file you want to edit.

castwide commented 5 years ago

The fix is published in gem version 0.30.2.

gottlike commented 5 years ago

Fix confirmed - thanks! :+1: