ruby-lsp-rails icon indicating copy to clipboard operation
ruby-lsp-rails copied to clipboard

Ruby LSP Rails failed to initialize server

Open reppiee opened this issue 1 year ago • 5 comments

I've installed ruby-lsp and successfully using that using the Ruby LSP VSCode extension, however Ruby LSP Rails fails to initialize its server with the following error:

2024-09-16 11:47:06.554 [info] (core) Ruby LSP Rails failed to initialize server: 
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.11/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:94:in `rescue in initialize'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.11/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:43:in `initialize'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11422/lib/types/private/methods/_methods.rb:279:in `bind_call'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11422/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.11/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:16:in `new'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.11/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:16:in `create_client'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11422/lib/types/private/methods/_methods.rb:279:in `bind_call'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11422/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.11/lib/ruby_lsp/ruby_lsp_rails/addon.rb:36:in `block in activate'
Server dependent features will not be available

Any ideas on why or what I could do to fix it?

reppiee avatar Sep 16 '24 09:09 reppiee

Thank you for the bug report! The backtrace seems to be incomplete for whatever reason, so it's hard to tell what's going on without the error message.

I do see that you're on v0.3.11 of ruby-lsp-rails, which is not the latest. Can you please try upgrading? Alternatively, do you see the error message printed anywhere?

vinistock avatar Sep 16 '24 13:09 vinistock

Yeah the incompleteness is also what's throwing me off - I have no idea where to look for the problem.

I've tried updating to the latest, but still getting the same error:

2024-09-18 13:31:30.557 [info] (core) Finished initializing Ruby LSP!
2024-09-18 13:31:30.585 [info] (core) Activating Ruby LSP Rails addon v0.3.15

2024-09-18 13:31:30.591 [info] (core) Ruby LSP Rails booting server

2024-09-18 13:31:31.654 [info] (core) Ruby LSP Rails is retrying initialize (1)
Ruby LSP Rails failed to initialize server: 
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.15/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:96:in `rescue in initialize'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.15/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:43:in `initialize'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11422/lib/types/private/methods/_methods.rb:279:in `bind_call'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11422/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.15/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:16:in `new'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.15/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:16:in `create_client'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11422/lib/types/private/methods/_methods.rb:279:in `bind_call'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11422/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.15/lib/ruby_lsp/ruby_lsp_rails/addon.rb:41:in `block in activate'
Server dependent features will not be available

reppiee avatar Sep 18 '24 11:09 reppiee

Yeah, it's really hard to tell without the full trace (and I'm not sure why it's only printed the partial trace).

If you have time, trying to launch the runtime server manually might help us figure out what's wrong. Essentially, you just need to execute the server with rails runner, which should hopefully break in the same way and print the full trace:

  1. Figure out the full path to the server.rb file for your ruby-lsp-rails installation: BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle show ruby-lsp-rails (prints the path to the gem installation)
  2. After you have the path to the gem root, you are looking for this file
  3. With the full path in hand, spawn the server using Rails runner. This is what we do in the addon
bin/rails runner /path/to/gems/ruby-lsp-rails-0.3.15/lib/ruby_lsp/ruby_lsp_rails/server.rb start

vinistock avatar Sep 18 '24 12:09 vinistock

Hi, sorry it took a while to get back to this!

I've tried your suggestions:

  1. Locating the full path
❯ BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle show ruby-lsp-rails
/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.15
  1. Use rails runner
❯ bin/rails runner "/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.15" start
Please specify a valid ruby command or the path of a script to run.
Run 'rails runner -h' for help.

/usr/local/bundle/gems/railties-6.1.7.8/lib/rails/commands/runner/runner_command.rb:45: unknown regexp options - tv
/Users/steven/.asdf/installs/ruby/3.2.5/li...
      ^~~~~~~
/usr/local/bundle/gems/railties-6.1.7.8/lib/rails/commands/runner/runner_command.rb:45: syntax error, unexpected '.'
/Users/steven/.asdf/installs/ruby/3.2.5/lib/...
              ^

Probably doing something wrong, since I don't expect that to be the actual error. Posting here just in case it does explain something - but will revisit next week to try and actually run it to get logging/stacktrace of error.

reppiee avatar Sep 27 '24 14:09 reppiee

You need to specify the path to the server.rb file, so it's almost there. It should be

bin/rails runner "/Users/steven/.asdf/installs/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.15/lib/ruby_lsp/ruby_lsp_rails/server.rb" start

vinistock avatar Sep 30 '24 14:09 vinistock

Sorry for not coming back to this - a colleague of mine went down the rabbithole and figured out that it was not starting properly due to customised rails bin stubs that we use.

Apologies and thanks for the help!

reppiee avatar Oct 15 '24 06:10 reppiee