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

uninitialized constant SyntaxTree::BraceBlock #2346

Closed
tvdeyen opened this issue Jul 23, 2024 · 9 comments
Closed

uninitialized constant SyntaxTree::BraceBlock #2346

tvdeyen opened this issue Jul 23, 2024 · 9 comments
Assignees
Labels
bug Something isn't working

Comments

@tvdeyen
Copy link

tvdeyen commented Jul 23, 2024

Description

Reproduction steps

  1. Start the Ruby LSP using VSCode
  2. Open a Ruby file
  3. Wait until the Ruby LSP server launches
  4. Open Output Panel

This error message appears

2024-07-23 18:01:21.656 [info] (<Project>) [Info  - 18:01:21] Connection to server got closed. Server will restart.
2024-07-23 18:01:21.658 [info] (<Project>) false
2024-07-23 18:01:21.989 [info] (<Project>) Ruby LSP> Skipping custom bundle setup since /Users/tvd/code/<client>/<project>/.ruby-lsp/Gemfile.lock already exists and is up to date

2024-07-23 18:01:22.004 [info] (<Project>) Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: (bundle check || bundle install) 1>&2

2024-07-23 18:01:22.268 [info] (<Project>) The Gemfile's dependencies are satisfied

2024-07-23 18:01:22.827 [info] (<Project>) Starting Ruby LSP...

2024-07-23 18:01:24.516 [info] (<Project>) bundler: failed to load command: ruby-lsp (/Users/tvd/.gem/ruby/3.3.3/bin/ruby-lsp)

2024-07-23 18:01:24.518 [info] (<Project>) /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/requests/folding_ranges.rb:17:in `<class:FoldingRanges>': uninitialized constant SyntaxTree::BraceBlock (NameError)

        SyntaxTree::BraceBlock,
                  ^^^^^^^^^^^^
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/requests/folding_ranges.rb:14:in `<module:Requests>'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/requests/folding_ranges.rb:4:in `<module:RubyLsp>'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/requests/folding_ranges.rb:3:in `<top (required)>'
	from /Users/tvd/.rubies/ruby-3.3.3/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
	from /Users/tvd/.rubies/ruby-3.3.3/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:106:in `block in respond_with_folding_ranges'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/document.rb:25:in `cache_fetch'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/store.rb:40:in `cache_fetch'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:105:in `respond_with_folding_ranges'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/cli.rb:50:in `block (2 levels) in start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:45:in `handle'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:30:in `block (2 levels) in start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:161:in `with_telemetry'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:30:in `block in start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/language_server-protocol-3.17.0.3/lib/language_server/protocol/transport/io/reader.rb:20:in `read'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:29:in `start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/cli.rb:78:in `start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/exe/ruby-lsp:8:in `<top (required)>'
	from /Users/tvd/.gem/ruby/3.3.3/bin/ruby-lsp:25:in `load'
	from /Users/tvd/.gem/ruby/3.3.3/bin/ruby-lsp:25:in `<top (required)>'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli/exec.rb:58:in `load'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli/exec.rb:23:in `run'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli.rb:455:in `exec'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli.rb:35:in `dispatch'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli.rb:29:in `start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/exe/bundle:28:in `block in <top (required)>'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/exe/bundle:20:in `<top (required)>'
	from /Users/tvd/.gem/ruby/3.3.3/bin/bundle:25:in `load'
	from /Users/tvd/.gem/ruby/3.3.3/bin/bundle:25:in `<main>'

2024-07-23 18:01:24.524 [info] (<Project>) [Error - 18:01:24] Server process exited with code 1.
@tvdeyen tvdeyen added the bug Something isn't working label Jul 23, 2024
@andyw8
Copy link
Contributor

andyw8 commented Jul 23, 2024

@tvdeyen The logs indicate a very old version of ruby-lsp from more than 2 years ago. The extension attempts to use the latest version, so it's likely that something in your bundle is constraining it.

To help troubleshoot, can you try temporarily add the latest version in your Gemfile (v0.17.8) and run bundle update?

@andyw8
Copy link
Contributor

andyw8 commented Jul 23, 2024

(please re-open if you need further assistance)

@andyw8 andyw8 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2024
@tvdeyen
Copy link
Author

tvdeyen commented Jul 23, 2024

@andyw8 I have not installed ruby-lsp in our Gemfile in the first place. I followed the instructions in the README for VSCode where it says to not manually install the Gem.

Since you asked, I now did anyway and it bundled correctly, so there seem to be no Bundler related issues.

I started VSCode and it says it now uses the latest version (0.17.8).

I then removed the gem from the Gemfile and all versions from my Ruby and started VSCode again.

It then shows this in the logs:

2024-07-23 18:18:08.435 [info] (<Project>) Discovered Ruby version ruby-3.3.3 from /Users/tvd/code/<client>/<project>/.ruby-version
2024-07-23 18:18:08.448 [info] (<Project>) Discovered Ruby installation at /Users/tvd/.rubies/ruby-3.3.3/bin/ruby
2024-07-23 18:18:08.448 [info] (<Project>) Running command: `/Users/tvd/.rubies/ruby-3.3.3/bin/ruby -W0 -rjson -e 'user_dir = Gem.user_dir;paths = Gem.path;if paths.length > 2;  paths.delete(Gem.default_dir);  paths.delete(Gem.user_dir);  if paths[0];    user_dir = paths[0] if Dir.exist?(paths[0]);  end;end;newer_gem_home = File.join(File.dirname(user_dir), "3.3.3");gems = (Dir.exist?(newer_gem_home) ? newer_gem_home : user_dir);data = { defaultGems: Gem.default_dir, gemHome: gems, yjit: !!defined?(RubyVM::YJIT), version: RUBY_VERSION };STDERR.print(JSON.dump(data))'` in /Users/tvd/code/<client>/<project> using shell: /bin/zsh
2024-07-23 18:18:08.565 [info] (<Project>) Activated Ruby environment: defaultGems=/Users/tvd/.rubies/ruby-3.3.3/lib/ruby/gems/3.3.0 gemHome=/Users/tvd/.gem/ruby/3.3.3 yjit=true
2024-07-23 18:18:12.544 [info] (<Project>) Ruby LSP> Skipping custom bundle setup since /Users/tvd/code/<client>/<project>/.ruby-lsp/Gemfile.lock already exists and is up to date

2024-07-23 18:18:12.558 [info] (<Project>) Ruby LSP> Running bundle install for the custom bundle. This may take a while...
Ruby LSP> Command: ((bundle check && bundle update ruby-lsp) || bundle install) 1>&2

2024-07-23 18:18:12.795 [info] (<Project>) The Gemfile's dependencies are satisfied

2024-07-23 18:18:13.607 [info] (<Project>) Fetching gem metadata from https://gems.contribsys.com/
2024-07-23 18:18:13.608 [info] (<Project>) .
2024-07-23 18:18:13.612 [info] (<Project>) .
2024-07-23 18:18:13.615 [info] (<Project>) 

2024-07-23 18:18:14.030 [info] (<Project>) Fetching gem metadata from https://rubygems.org/.
2024-07-23 18:18:14.204 [info] (<Project>) .
2024-07-23 18:18:14.270 [info] (<Project>) .
2024-07-23 18:18:14.337 [info] (<Project>) .
2024-07-23 18:18:14.355 [info] (<Project>) .
2024-07-23 18:18:14.359 [info] (<Project>) .
2024-07-23 18:18:14.360 [info] (<Project>) .
2024-07-23 18:18:14.360 [info] (<Project>) .
2024-07-23 18:18:14.361 [info] (<Project>) .
2024-07-23 18:18:14.361 [info] (<Project>) .
2024-07-23 18:18:15.301 [info] (<Project>) 

2024-07-23 18:18:15.414 [info] (<Project>) Resolving dependencies...

2024-07-23 18:18:22.963 [info] (<Project>) Resolving dependencies...

2024-07-23 18:18:26.645 [info] (<Project>) Fetching ruby-lsp 0.0.3 (was 0.17.8)

2024-07-23 18:18:26.776 [info] (<Project>) Installing ruby-lsp 0.0.3 (was 0.17.8)

2024-07-23 18:18:26.794 [info] (<Project>) Note: ruby-lsp version regressed from 0.17.8 to 0.0.3
Bundle updated!

2024-07-23 18:18:27.425 [info] (<Project>) Starting Ruby LSP...

2024-07-23 18:20:52.003 [info] (<Project>) bundler: failed to load command: ruby-lsp (/Users/tvd/.gem/ruby/3.3.3/bin/ruby-lsp)

2024-07-23 18:20:52.004 [info] (<Project>) /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/store.rb:17:in `unescape': no implicit conversion of nil into String (TypeError)

      set(uri, File.binread(CGI.unescape(URI.parse(uri).path)))
                                         ^^^^^^^^^^^^^^^^^^^
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/store.rb:17:in `get'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/store.rb:40:in `cache_fetch'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:137:in `send_diagnostics'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/cli.rb:34:in `block (2 levels) in start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:45:in `handle'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:30:in `block (2 levels) in start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:161:in `with_telemetry'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:30:in `block in start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/language_server-protocol-3.17.0.3/lib/language_server/protocol/transport/io/reader.rb:20:in `read'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/handler.rb:29:in `start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/lib/ruby_lsp/cli.rb:78:in `start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/ruby-lsp-0.0.3/exe/ruby-lsp:8:in `<top (required)>'
	from /Users/tvd/.gem/ruby/3.3.3/bin/ruby-lsp:25:in `load'
	from /Users/tvd/.gem/ruby/3.3.3/bin/ruby-lsp:25:in `<top (required)>'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli/exec.rb:58:in `load'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli/exec.rb:58:in `kernel_load'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli/exec.rb:23:in `run'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli.rb:455:in `exec'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/vendor/thor/lib/thor/command.rb:28:in `run'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/vendor/thor/lib/thor.rb:527:in `dispatch'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli.rb:35:in `dispatch'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/vendor/thor/lib/thor/base.rb:584:in `start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/cli.rb:29:in `start'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/exe/bundle:28:in `block in <top (required)>'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/lib/bundler/friendly_errors.rb:117:in `with_friendly_errors'
	from /Users/tvd/.gem/ruby/3.3.3/gems/bundler-2.5.13/exe/bundle:20:in `<top (required)>'
	from /Users/tvd/.gem/ruby/3.3.3/bin/bundle:25:in `load'
	from /Users/tvd/.gem/ruby/3.3.3/bin/bundle:25:in `<main>'

2024-07-23 18:20:52.007 [info] (<Project>) [Error - 18:20:52] Server process exited with code 1.
2024-07-23 18:20:52.213 [info] (<Project>) [Error - 18:20:52] Request textDocument/foldingRange failed.
2024-07-23 18:20:52.213 [info] (<Project>) Error: Connection is disposed.
    at _t (/Users/tvd/.vscode/extensions/shopify.ruby-lsp-0.7.14/out/extension.js:31:476)
    at Object.sendRequest (/Users/tvd/.vscode/extensions/shopify.ruby-lsp-0.7.14/out/extension.js:31:2496)
    at /Users/tvd/.vscode/extensions/shopify.ruby-lsp-0.7.14/out/extension.js:39:114027
    at /Users/tvd/.vscode/extensions/shopify.ruby-lsp-0.7.14/out/extension.js:54:1059
    at hs.benchmarkMiddleware (/Users/tvd/.vscode/extensions/shopify.ruby-lsp-0.7.14/out/extension.js:50:1388)
    at sendRequest (/Users/tvd/.vscode/extensions/shopify.ruby-lsp-0.7.14/out/extension.js:54:1031)
    at hs.sendRequest (/Users/tvd/.vscode/extensions/shopify.ruby-lsp-0.7.14/out/extension.js:39:113947)
    at Z.provideFoldingRanges (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/api/node/extensionHostProcess.js:154:126701)

Now it is a different error.

I then tried with Ruby 3.3.4 and that works.

Maybe a Ruby 3.3.3 issue?

@vinistock
Copy link
Member

You're still running on the extremely old v0.0.3

2024-07-23 18:18:26.794 [info] (<Project>) Note: ruby-lsp version regressed from 0.17.8 to 0.0.3
Bundle updated!

As Andy mentioned, something in your bundle is locking the ruby-lsp gem to a super old version.

If you have the ruby-lsp in your Gemfile, remove it and reload the VS Code window.

If you don't, try to update the gem and check why that's failing.

BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle update ruby-lsp

If that command does not upgrade it to v0.17.8, then the project may be constraining one of the Ruby LSP's runtime dependencies, which are

  • rbs
  • sorbet-runtime
  • prism

@tvdeyen
Copy link
Author

tvdeyen commented Jul 23, 2024

@vinistock that actually worked 🎉

› BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle update ruby-lsp
Fetching gem metadata from https://gems.contribsys.com/..
Fetching gem metadata from https://rubygems.org/..........
Resolving dependencies...
Resolving dependencies...
Using ruby-lsp 0.17.8 (was 0.0.3)
Bundle updated!

Since I do not have ruby-lsp in my Gemfile and none of the above mentioned gems I am not sure it's an issue on my end. I just installed the extension since it was released and kept it up to date since. 🤷🏻

My guess is Ruby 3.3.3 (that has issues with installing correct gems, no?)

@tvdeyen
Copy link
Author

tvdeyen commented Jul 23, 2024

Anyhow it works for me now, but maybe worth adding to the TROUBLESHOOTING section or making sure the extension updates the ruby-lsp gem to the latest version on startup?

@vinistock
Copy link
Member

It does try to update the gem on boot, not sure what was failing there.

Better than surfacing this in TROUBLESHOOTING, I would love if we could warn users that we attempted to upgrade, but that didn't work. Maybe Bundler can inform us that's the case?

@chrishiestand
Copy link

I also had this problem and I just wiped my .ruby-lsp folders and I restarted the code workspace and it worked after that. I'm not sure if this could be problematic for some cases? Seems like an easy solution though.

@vinistock
Copy link
Member

There's no detriment to removing the .ruby-lsp directory. It will just be re-generated from scratch and re-composing the bundle from a clean state probably fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants