Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby LSP Rails failed to initialize server #514

Closed
AlexVPopov opened this issue Nov 6, 2024 · 26 comments
Closed

Ruby LSP Rails failed to initialize server #514

AlexVPopov opened this issue Nov 6, 2024 · 26 comments

Comments

@AlexVPopov
Copy link

Hello,

Since today, I can't start the Ruby LSP server. Here's the output from the logs:

2024-11-06 17:20:09.075 [info] (platform) The Gemfile's dependencies are satisfied

2024-11-06 17:20:10.791 [info] (platform) Initializing Ruby LSP v0.21.3...
2024-11-06 17:20:10.796 [info] (platform) Auto detected formatter: rubocop
2024-11-06 17:20:10.796 [info] (platform) Auto detected linters: rubocop
2024-11-06 17:20:10.796 [info] (platform) Detected test library: rspec
2024-11-06 17:20:10.796 [info] (platform) Finished initializing Ruby LSP!
2024-11-06 17:20:10.955 [info] (platform) Activating Ruby LSP Rails add-on v0.3.23
2024-11-06 17:20:10.956 [info] (platform) Ruby LSP Rails booting server
2024-11-06 17:20:15.521 [info] (platform) [Error - 5:20:15 PM] Ruby LSP Rails failed to initialize server: /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:295:in `block in read_response': RubyLsp::Rails::RunnerClient::EmptyMessageError (RubyLsp::Rails::RunnerClient::EmptyMessageError)
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:292:in `synchronize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:292:in `read_response'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11637/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11637/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:90:in `initialize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11637/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11637/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:16:in `new'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:16:in `create_client'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11637/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11637/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/addon.rb:41:in `block (3 levels) in initialize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/addon.rb:41:in `synchronize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/addon.rb:41:in `block (2 levels) in initialize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/addon.rb:39:in `synchronize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.23/lib/ruby_lsp/ruby_lsp_rails/addon.rb:39:in `block in initialize'

Server dependent features will not be available

Below is the Ruby LSP debug information. Could you point me to how I can troubleshoot this problem? Thank you. :)

Ruby LSP Information

VS Code Version

1.95.1

Ruby LSP Extension Version

0.8.13

Ruby LSP Server Version

0.21.3

Ruby LSP Addons

  • Ruby LSP Rails

Ruby Version

3.2.4

Ruby Version Manager

rbenv

Installed Extensions

Click to expand
  • copilot (1.243.0)
  • copilot-chat (0.22.1)
  • elixir-ls (0.24.2)
  • gitlens (15.6.3)
  • go (0.42.1)
  • makefile-tools (0.11.13)
  • prettier-sql-vscode (1.6.0)
  • rainbow-csv (3.12.0)
  • ruby-extensions-pack (0.1.12)
  • ruby-lsp (0.8.13)
  • sorbet-vscode-extension (0.3.37)
  • terraform (2.33.0)
  • vscode-fileutils (3.10.3)
  • vscode-graphql (0.12.1)
  • vscode-json-validate (1.5.0)
  • vscode-yaml (1.15.0)

Ruby LSP Settings

Click to expand
Workspace
{}
User
{
  "enableExperimentalFeatures": false,
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": true,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "auto"
  },
  "customRubyCommand": "",
  "formatter": "auto",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "branch": "",
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "/Users/alexanderpopov/.rbenv/shims/ruby",
  "indexing": {},
  "erbSupport": true,
  "useLauncher": false,
  "featureFlags": {}
}
@vinistock
Copy link
Member

Thank you for the report! Can you please try the just released v0.3.24? I believe this is the same as Shopify/ruby-lsp#512.

@AlexVPopov
Copy link
Author

Hey @vinistock, thank you for the quick reply! Unfortunately, this didn't solve the issue for me:

2024-11-07 13:28:21.469 [info] (platform) Initializing Ruby LSP v0.21.3...
2024-11-07 13:28:21.475 [info] (platform) Auto detected formatter: rubocop
2024-11-07 13:28:21.475 [info] (platform) Auto detected linters: rubocop
2024-11-07 13:28:21.475 [info] (platform) Detected test library: rspec
2024-11-07 13:28:21.475 [info] (platform) Finished initializing Ruby LSP!
2024-11-07 13:28:21.597 [info] (platform) Activating Ruby LSP Rails add-on v0.3.25
2024-11-07 13:28:21.599 [info] (platform) Ruby LSP Rails booting server
2024-11-07 13:28:26.341 [info] (platform) [Error - 1:28:26 PM] Ruby LSP Rails failed to initialize server: /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.25/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:296:in `block in read_response': RubyLsp::Rails::RunnerClient::EmptyMessageError (RubyLsp::Rails::RunnerClient::EmptyMessageError)
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.25/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:293:in `synchronize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.25/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:293:in `read_response'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.25/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:91:in `initialize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.25/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:16:in `new'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.25/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:16:in `create_client'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.25/lib/ruby_lsp/ruby_lsp_rails/addon.rb:41:in `block (3 levels) in initialize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.25/lib/ruby_lsp/ruby_lsp_rails/addon.rb:41:in `synchronize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.25/lib/ruby_lsp/ruby_lsp_rails/addon.rb:41:in `block (2 levels) in initialize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.25/lib/ruby_lsp/ruby_lsp_rails/addon.rb:39:in `synchronize'
	from /home/alexander/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/ruby-lsp-rails-0.3.25/lib/ruby_lsp/ruby_lsp_rails/addon.rb:39:in `block in initialize'

Server dependent features will not be available

@WhoSayIn
Copy link

WhoSayIn commented Nov 7, 2024

I get exactly the same error. My ruby version is 3.3.5, but the rest of the versions are the same as Alex (0.3.25)

Happy to provide more information if needed to resolve this.

@erickguan
Copy link

I have this problem too with v0.3.25. Ruby version 3.2.4.

I dug into the code and rdbg into the LSP client. I know the error handling happens as expected. But I don't have log information nor debugger access to the server process. It would be nice to have some more logs or debugger sockets from the server process too.

@andyw8
Copy link
Contributor

andyw8 commented Nov 7, 2024

#521 may be a contributing factor here.

@erickguan
Copy link

I tried your patch. This problem persists. On my end, I have Mongoid 8.1.6.

@andyw8
Copy link
Contributor

andyw8 commented Nov 7, 2024

Can you share the logs from the Output -> Ruby LSP panel please.

@erickguan
Copy link

Of course. Thanks for looking into it.

cat .ruby-lsp/Gemfile.lock | head -n 7

GIT
  remote: https://github.com/Shopify/ruby-lsp-rails.git
  revision: b5235c3b937300cccaf734809d75f896355039e5
  specs:
    ruby-lsp-rails (0.3.25)
      ruby-lsp (>= 0.21.2, < 0.22.0)
2024-11-07 18:26:54.430 [info] (application) Found rbenv executable at /opt/homebrew/bin
2024-11-07 18:26:54.431 [info] (application) Running command: `/opt/homebrew/bin/rbenv exec ruby -W0 -rjson -e 'STDERR.print("RUBY_LSP_ACTIVATION_SEPARATOR" + { env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION, gemPath: Gem.path }.to_json + "RUBY_LSP_ACTIVATION_SEPARATOR")'` in /Users/erickg/repos/skvk/application using shell: /opt/homebrew/bin/zsh
2024-11-07 18:26:54.881 [info] (application) [Error - 18:26:54] Server process exited with code 0.
2024-11-07 18:26:55.039 [info] (application) Ruby LSP> Skipping custom bundle setup since /Users/erickg/repos/skvk/application/.ruby-lsp/Gemfile.lock already exists and is up to date

2024-11-07 18:26:55.075 [info] (application) Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: ((bundle _2.4.19_ check && bundle _2.4.19_ update ruby-lsp) || bundle _2.4.19_ install) 1>&2

2024-11-07 18:26:55.265 [info] (application) The Gemfile's dependencies are satisfied

2024-11-07 18:26:56.304 [info] (application) Fetching gem metadata from https://rubygems.pkg.github.com/skvk/
2024-11-07 18:26:56.304 [info] (application) .
2024-11-07 18:26:56.305 [info] (application) .
2024-11-07 18:26:56.306 [info] (application) 
Fetching gem metadata from https://gems.contribsys.com/
2024-11-07 18:26:56.306 [info] (application) .
2024-11-07 18:26:56.308 [info] (application) .
2024-11-07 18:26:56.315 [info] (application) 

2024-11-07 18:26:56.690 [info] (application) Fetching gem metadata from https://rubygems.org/
2024-11-07 18:26:56.690 [info] (application) .
2024-11-07 18:26:56.829 [info] (application) .
2024-11-07 18:26:56.862 [info] (application) .
2024-11-07 18:26:56.890 [info] (application) .
2024-11-07 18:26:56.903 [info] (application) .
2024-11-07 18:26:56.906 [info] (application) .
2024-11-07 18:26:56.919 [info] (application) .
2024-11-07 18:26:56.927 [info] (application) .
2024-11-07 18:26:57.266 [info] (application) 

2024-11-07 18:26:57.329 [info] (application) Resolving dependencies...

2024-11-07 18:26:57.591 [info] (application) Using logger 1.6.1 (was 1.6.0)

2024-11-07 18:26:57.890 [info] (application) Bundler attempted to update ruby-lsp but its version stayed the same
Bundle updated!

2024-11-07 18:26:59.156 [info] (application) DEBUGGER: Debugger can attach via UNIX domain socket (/var/folders/bh/3stpknyx3vvc0kj_8k2l4htm0000gn/T/rdbg-501/rdbg-92558)

2024-11-07 18:26:59.176 [info] (application) Initializing Ruby LSP v0.21.3...
2024-11-07 18:26:59.181 [info] (application) Auto detected formatter: rubocop
2024-11-07 18:26:59.181 [info] (application) Auto detected linters: rubocop
2024-11-07 18:26:59.181 [info] (application) Detected test library: rails
2024-11-07 18:26:59.181 [info] (application) Finished initializing Ruby LSP!
2024-11-07 18:27:00.632 [info] (application) Activating Ruby LSP Rails add-on v0.3.25
2024-11-07 18:27:00.640 [info] (application) Ruby LSP Rails booting server
2024-11-07 18:27:02.614 [info] (application) [Error - 18:27:02] Ruby LSP Rails failed to initialize server: /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:296:in `block in read_response': RubyLsp::Rails::RunnerClient::EmptyMessageError (RubyLsp::Rails::RunnerClient::EmptyMessageError)
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:293:in `synchronize'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:293:in `read_response'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:91:in `initialize'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:16:in `new'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373/lib/ruby_lsp/ruby_lsp_rails/runner_client.rb:16:in `create_client'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `bind_call'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/gems/sorbet-runtime-0.5.11641/lib/types/private/methods/_methods.rb:279:in `block in _on_method_added'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373/lib/ruby_lsp/ruby_lsp_rails/addon.rb:41:in `block (3 levels) in initialize'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373/lib/ruby_lsp/ruby_lsp_rails/addon.rb:41:in `synchronize'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373/lib/ruby_lsp/ruby_lsp_rails/addon.rb:41:in `block (2 levels) in initialize'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373/lib/ruby_lsp/ruby_lsp_rails/addon.rb:39:in `synchronize'
	from /Users/erickg/.rbenv/versions/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373/lib/ruby_lsp/ruby_lsp_rails/addon.rb:39:in `block in initialize'

Server dependent features will not be available

@andyw8
Copy link
Contributor

andyw8 commented Nov 7, 2024

Do you see any errors if running this on the command line:

bundle exec rails runner PATH_TO_INSTALLATION/lib/ruby_lsp/ruby_lsp_rails/server.rb start

(get the path using bundle show ruby-lsp-rails)

@erickguan
Copy link

erickguan commented Nov 7, 2024

This works well:

# logs for other initializers from the Rails app
Content-Length: 73

{"result":{"message":"ok","root":"/Users/erickg/repos/skvk/application"}}

I did a simple check via pipe (via mkfifo). I don't have enough time today to send data to it:

Content-Length: 70

{"result":{"columns":["column_a","column"],"primary_keys":["column"]}}

I will come back to this tomorrow.

@andyw8
Copy link
Contributor

andyw8 commented Nov 7, 2024

Thanks. My thought was that the Rails app was failing to start (#519), but it seems that's not the case for you.

@erickguan
Copy link

Truly. Again, thanks for checking in. I know Shopify has a larger Rails application. Mine is smaller. But it is indeed peculiar. Happy to either dig this deeper or pair on the problem with you somehow.

@andyw8
Copy link
Contributor

andyw8 commented Nov 7, 2024

If you can try create a vanilla Rails app with ActiveRecord instead of Mongoid, then it may help narrow the cause.

@erickguan
Copy link

erickguan commented Nov 8, 2024

I bootstraped a 7.2.2 Rails with sqlite3. ruby-lsp-rails commit b5235c3b937300cccaf734809d75f896355039e5.

Logs from VS Code Ruby LSP
2024-11-08 13:06:00.722 [info] (testapp) Found rbenv executable at /opt/homebrew/bin
2024-11-08 13:06:00.724 [info] (testapp) Running command: `/opt/homebrew/bin/rbenv exec ruby -W0 -rjson -e 'STDERR.print("RUBY_LSP_ACTIVATION_SEPARATOR" + { env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION, gemPath: Gem.path }.to_json + "RUBY_LSP_ACTIVATION_SEPARATOR")'` in /Users/erickg/repos/skvk/testapp using shell: /opt/homebrew/bin/zsh
2024-11-08 13:06:00.772 [info] (testapp) [Error - 13:06:00] Server process exited with code 0.
2024-11-08 13:06:01.241 [info] (testapp) Ruby LSP> Skipping custom bundle setup since /Users/erickg/repos/skvk/testapp/.ruby-lsp/Gemfile.lock already exists and is up to date

2024-11-08 13:06:01.283 [info] (testapp) Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle _2.4.19_ check || bundle _2.4.19_ install) 1>&2

2024-11-08 13:06:01.455 [info] (testapp) The Gemfile's dependencies are satisfied

2024-11-08 13:06:02.452 [info] (testapp) Initializing Ruby LSP v0.21.3...
2024-11-08 13:06:02.457 [info] (testapp) Auto detected formatter: rubocop
2024-11-08 13:06:02.458 [info] (testapp) Auto detected linters: rubocop
2024-11-08 13:06:02.458 [info] (testapp) Detected test library: rails
2024-11-08 13:06:02.458 [info] (testapp) Finished initializing Ruby LSP!
2024-11-08 13:06:02.470 [info] (testapp) Activating Ruby LSP Rails add-on v0.3.25
2024-11-08 13:06:02.475 [info] (testapp) Ruby LSP Rails booting server
2024-11-08 13:06:03.580 [info] (testapp) Finished booting Ruby LSP Rails server
2024-11-08 13:06:40.219 [info] (testapp) Found rbenv executable at /opt/homebrew/bin
2024-11-08 13:06:40.219 [info] (testapp) Running command: `/opt/homebrew/bin/rbenv exec ruby -W0 -rjson -e 'STDERR.print("RUBY_LSP_ACTIVATION_SEPARATOR" + { env: ENV.to_h, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION, gemPath: Gem.path }.to_json + "RUBY_LSP_ACTIVATION_SEPARATOR")'` in /Users/erickg/repos/skvk/testapp using shell: /opt/homebrew/bin/zsh
2024-11-08 13:06:40.525 [info] (testapp) Shutting down Ruby LSP...
2024-11-08 13:06:40.526 [info] (testapp) Ruby LSP Rails shutting down server
2024-11-08 13:06:41.047 [info] (testapp) [Error - 13:06:41] Server process exited with code 0.
2024-11-08 13:06:41.250 [info] (testapp) Ruby LSP> Skipping custom bundle setup since /Users/erickg/repos/skvk/testapp/.ruby-lsp/Gemfile.lock already exists and is up to date

2024-11-08 13:06:41.324 [info] (testapp) Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle _2.4.19_ check || bundle _2.4.19_ install) 1>&2

2024-11-08 13:06:41.495 [info] (testapp) The Gemfile's dependencies are satisfied

2024-11-08 13:06:42.504 [info] (testapp) DEBUGGER: Debugger can attach via UNIX domain socket (/var/folders/bh/3stpknyx3vvc0kj_8k2l4htm0000gn/T/rdbg-501/rdbg-55875)

2024-11-08 13:06:42.509 [info] (testapp) Initializing Ruby LSP v0.21.3...
2024-11-08 13:06:42.512 [info] (testapp) Auto detected formatter: rubocop
2024-11-08 13:06:42.512 [info] (testapp) Auto detected linters: rubocop
2024-11-08 13:06:42.512 [info] (testapp) Detected test library: rails
2024-11-08 13:06:42.512 [info] (testapp) Finished initializing Ruby LSP!
2024-11-08 13:06:42.526 [info] (testapp) Activating Ruby LSP Rails add-on v0.3.25
2024-11-08 13:06:42.531 [info] (testapp) Ruby LSP Rails booting server
2024-11-08 13:06:43.490 [info] (testapp) Finished booting Ruby LSP Rails server

Everything looks fine. Then I did bundle show ruby-lsp-rails.

/Users/erickg/.local/share/mise/installs/ruby/3.2.4/lib/ruby/gems/3.2.0/bundler/gems/ruby-lsp-rails-b5235c3b9373

Running bundle exec rails runner lib/ruby_lsp/ruby_lsp_rails/server.rb start

Same message:

Content-Length: 69

{"result":{"message":"ok","root":"/Users/erickg/repos/skvk/testapp"}}

Both repo has a direnv setup:

use rbenv

layout ruby

PATH_add bin

This is a bit bizzare. So I suspected my environment. I have both mise and rbenv. I use rbenv in Ruby LSP but not in an interactive shell. My direnv uses rbenv. So I disabled mise and applied the same check again. Now that Ruby LSP Rails seems to run.

Perhaps a secondary problem is what "bundle" Ruby LSP picks up. When mise is available, mise overwrites the 'direnv' bundle. I know this will cause undefined behavior.

Working on reproduction steps.

@erickguan
Copy link

erickguan commented Nov 8, 2024

Continued discovery. I can still reproduce the problem without mise. My environment:

  • macOS: 15.1
  • zsh: zsh 5.9 (arm-apple-darwin22.1.0)
  • rbenv: rbenv 1.3.0
  • direnv: 2.35.0
  • VS Code: 1.95.2
Partial `env` output
COLORTERM=truecolor
COMMAND_MODE=unix2003
HOME=/Users/erickg
KITTY_INSTALLATION_DIR=/Applications/kitty.app/Contents/Resources/kitty
KITTY_PID=41548
KITTY_PUBLIC_KEY=1:u34?y=T}LXIY4n?e_yx^nehEVH;m4QezD+45t~P9
KITTY_WINDOW_ID=1
LANG=en_US.UTF-8
LOGNAME=erickg
MANPATH=:/usr/share/man:/usr/local/share/man:/Applications/kitty.app/Contents/Resources/man:
PATH=/Users/erickg/repos/skvk/testapp/bin:/Users/erickg/repos/skvk/testapp/.direnv/bin:/Users/erickg/repos/skvk/testapp/.direnv/ruby/bin:/Users/erickg/.rbenv/shims:/Users/erickg/.pyenv/shims:/Users/erickg/.local/bin:/opt/homebrew/bin:/Users/erickg/.local/bin:/Users/erickg/.pyenv/bin:/Users/erickg/.local/state/fnm_multishells/87368_1731069195543/bin:/Users/erickg/.fnm:/Users/erickg/.rbenv/shims:/Users/erickg/.rbenv/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/Applications/kitty.app/Contents/MacOS:/Users/erickg/.local/bin
PWD=/Users/erickg/repos/skvk/testapp
SHELL=/bin/zsh
TERM=tmux-256color
TERMINFO=/Applications/kitty.app/Contents/Resources/kitty/terminfo
TERM_PROGRAM=tmux
TERM_PROGRAM_VERSION=3.5a
TMPDIR=/var/folders/bh/3stpknyx3vvc0kj_8k2l4htm0000gn/T/
TMUX=/private/tmp/tmux-501/default,41776,0
TMUX_PANE=%29
USER=erickg
WINDOWID=7010
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
__CFBundleIdentifier=net.kovidgoyal.kitty
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
color_dark=colour250
color_status_text=colour253
color_window_off_status_bg=colour55
color_window_off_status_current_bg=colour14
SHLVL=1
OLDPWD=/Users/erickg/repos/skvk/testapp
HOMEBREW_PREFIX=/opt/homebrew
HOMEBREW_CELLAR=/opt/homebrew/Cellar
HOMEBREW_REPOSITORY=/opt/homebrew
INFOPATH=/opt/homebrew/share/info:
FNM_MULTISHELL_PATH=/Users/erickg/.local/state/fnm_multishells/87368_1731069195543
FNM_VERSION_FILE_STRATEGY=local
FNM_DIR=/Users/erickg/Library/Application Support/fnm
FNM_LOGLEVEL=info
FNM_NODE_DIST_MIRROR=https://nodejs.org/dist
FNM_COREPACK_ENABLED=false
FNM_RESOLVE_ENGINES=false
FNM_ARCH=arm64
PYENV_ROOT=/Users/erickg/.pyenv
PYENV_SHELL=zsh
ZSH_HOME=/Users/erickg/.zsh
LC_ALL=en_US.UTF-8
P9K_TTY=old
_P9K_TTY=/dev/ttys004
ZSH_AUTOSUGGEST_MANUAL_REBIND=1
ZSH=/Users/erickg/.zsh/oh-my-zsh
PAGER=less
LESS=-R
LSCOLORS=Gxfxcxdxbxegedabagacad
LS_COLORS=di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43
SSH_AGENT_PID=1415
FZF_DEFAULT_COMMAND=fd --type f --hidden --exclude .git
P9K_SSH=0
_P9K_SSH_TTY=/dev/ttys004
HOMEBREW_NO_ANALYTICS=1
DOTNET_CLI_TELEMETRY_OPTOUT=1
DIRENV_DIR=-/Users/erickg/repos/skvk/testapp
DIRENV_FILE=/Users/erickg/repos/skvk/testapp/.envrc
DIRENV_WATCHES=...
GEM_HOME=/Users/erickg/repos/skvk/testapp/.direnv/ruby
DIRENV_DIFF=...
RBENV_SHELL=bash
BUNDLE_BIN=/Users/erickg/repos/skvk/testapp/.direnv/bin
_=/usr/bin/env

Reproduction steps:

  1. Install rbenv and direnv

  2. Install rbenv install 3.2.4.

  3. Clone this repo https://github.com/erickguan/repro-ruby-lsp-rails git clone [email protected]:erickguan/repro-ruby-lsp-rails.git

    • I set up the repo with rails new testapp --minimal test.
    • Then added .envrc to use "direnv".
  4. bundle install (ruby-lsp-rails, b5235c3b937300cccaf734809d75f896355039e5).

  5. docker compose up -d (brings up the MongoDB server)

  6. In the repo, HEAD 307619e (with Mongoid instead of sqlite3) should produce the same error message in Ruby LSP. RubyLsp::Rails::RunnerClient::EmptyMessageError (RubyLsp::Rails::RunnerClient::EmptyMessageError.

  7. The previous commit 7d5b7b4 should not have this error.

@andyw8
Copy link
Contributor

andyw8 commented Nov 8, 2024

That app doesn't seem to start:

repro-ruby-lsp-rails main % bin/rails c
/Users/andyw8/.gem/ruby/3.3.4/gems/bundler-2.4.19/lib/bundler/rubygems_integration.rb:280:in `block (2 levels) in replace_gem': Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? sqlite3 is not part of the bundle. Add it to your Gemfile. (LoadError)
        from /Users/andyw8/.gem/ruby/3.3.4/gems/activerecord-7.2.2/lib/active_record/connection_adapters/sqlite3_adapter.rb:14:in `<top (required)>'

@andyw8
Copy link
Contributor

andyw8 commented Nov 8, 2024

I can boot it if comment out the active_record Railtie and the mentions in development.rb. Continuing to investigate...

@andyw8
Copy link
Contributor

andyw8 commented Nov 8, 2024

Sorry, I still can't reproduce. I don't expect direnv is a factor, but I tried with it just to be sure.

(I didn't try with rbenv, as I don't want to risk breaking my current setup, but again I don't think that's a factor).

I still think the underlying cause is that your app is failing to boot when running via the add-on.

You can perhaps try with some older versions of ruby-lsp-rails to see if there's a release where this started failing.

@erickguan
Copy link

erickguan commented Nov 8, 2024

Sorry my bad, I didn't include the config. I pushed the new commit 307619e. I suspect it's a Mongoid-related issue. I have included the docker compose with the exact mongoid version in the test app. Can you try my new commit?

@andyw8
Copy link
Contributor

andyw8 commented Nov 8, 2024

Can you check this for me on your system, in your local terminal:

bin/rails runner 'puts User.count'

@erickguan
Copy link

Yep, it's 22.

@andyw8
Copy link
Contributor

andyw8 commented Nov 8, 2024

Can you try edit your local installation of the gem, and add this debug output in runner_client.rb:

      sig { returns(T.nilable(Integer)) }
      def read_content_length
        headers = @stdout.gets("\r\n\r\n")
        $stderr.puts "headers: #{headers}" # <<< add this

Then restart VS Code and see what's shown in the Output panel.

@erickguan
Copy link

I cleared my environment and tried again. ruby-lsp-rails works.
After comparing with my colleague's environment, ruby-lsp-rails works when it resides in .direnv. When ruby-lsp-rails resides in rbenv environment, it doesn't work.

@AlexVPopov
Copy link
Author

Meanwhile I don't have the problem, running on 0.3.26:

2024-11-09 07:17:59.034 [info] (platform) Initializing Ruby LSP v0.21.3...
2024-11-09 07:17:59.041 [info] (platform) Auto detected formatter: rubocop
2024-11-09 07:17:59.041 [info] (platform) Auto detected linters: rubocop
2024-11-09 07:17:59.041 [info] (platform) Detected test library: rspec
2024-11-09 07:17:59.041 [info] (platform) Finished initializing Ruby LSP!
2024-11-09 07:17:59.178 [info] (platform) Activating Ruby LSP Rails add-on v0.3.26
2024-11-09 07:17:59.179 [info] (platform) Ruby LSP Rails booting server
2024-11-09 07:18:04.835 [info] (platform) Finished booting Ruby LSP Rails server
2024-11-09 07:18:04.836 [info] (platform) [dry-types] Dry::Types::Type#safe is deprecated and will be removed in the next major version

2024-11-09 07:18:04.836 [info] (platform) Please use Dry::Types::Type#lax instead.

2024-11-09 07:18:04.836 [info] (platform) /home/alexander/Toptal/platform/config/application.rb:12:in `<main>'

2024-11-09 07:18:04.836 [info] (platform) your 131072x1 screen size is bogus. expect trouble

@erickguan
Copy link

Great, we can close the issue. Thanks for helping.

@AlexVPopov
Copy link
Author

Closing as the problem is no longer reproducible in 0.3.26. Thank you, @erickguan, for helping! 🙇 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants