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

Failure for sorbet-runtime on new Rails app #336

Closed
andyw8 opened this issue Apr 16, 2024 · 8 comments · Fixed by #339
Closed

Failure for sorbet-runtime on new Rails app #336

andyw8 opened this issue Apr 16, 2024 · 8 comments · Fixed by #339

Comments

@andyw8
Copy link
Contributor

andyw8 commented Apr 16, 2024

I noticed when testing on a new Rails app:

2024-04-16 13:17:57.057 [info] (rails7) Ruby LSP Rails failed to initialize server: <internal:/opt/rubies/3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require': cannot load such file -- sorbet-runtime (LoadError)

I suspect this wasn't noticed previously because sorbet-runtime was already being required by something else.

@vinistock
Copy link
Member

This is strange. First, sorbet-runtime is required by ruby-lsp way before we even get close to activating any addons.

Second, this is saying that requiring sorbet-runtime has failed, which can only happen if the gem is not in the $LOAD_PATH, which should be impossible given that we have a dependency on sorbet-runtime.

@andyw8
Copy link
Contributor Author

andyw8 commented Apr 16, 2024

Here's more of the stacktrace:

2024-04-16 13:17:57.057 [info] (rails7) Ruby LSP Rails failed to initialize server: <internal:/opt/rubies/3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require': cannot load such file -- sorbet-runtime (LoadError)
	from <internal:/opt/rubies/3.2.1/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
	from /Users/andyw8/.gem/ruby/3.2.1/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:17:in `require'
	from /Users/andyw8/.gem/ruby/3.2.1/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34:in `require'
	from /Users/andyw8/.gem/ruby/3.2.1/gems/ruby-lsp-rails-0.3.5/lib/ruby_lsp/ruby_lsp_rails/server.rb:4:in `<main>'

So it seems this is because in server.rb we're wrongly assuming that sorbet-runtime will be available in the main Gemfile.lock, when it may only be in .ruby-lsp/Gemfile.lock.

So either:

  • We need to avoid using Sorbet completely within server.rb?
  • We need to run server.rb but use with BUNDLE_GEMFILE set to .ruby-lsp/Gemfile ?

@vinistock
Copy link
Member

Oh, I see the problem now. I'd say we include BUNDLE_GEMFILE when booting Rails runner. We can read the BUNDLE_GEMFILE from the current process and pass that to Rails runner.

@andyw8
Copy link
Contributor Author

andyw8 commented Apr 16, 2024

Something like this? #340

@andyw8
Copy link
Contributor Author

andyw8 commented Apr 18, 2024

FYI @vinistock :

puts "1: #{ENV["BUNDLE_GEMFILE"]}"

Bundler.with_unbundled_env do
  puts "2: #{ENV["BUNDLE_GEMFILE"]}"
end

Bundler.with_original_env do
  puts "3: #{ENV["BUNDLE_GEMFILE"]}"
end
BUNDLE_GEMFILE=.ruby-lsp/Gemfile bundle exec ruby x.rb
1: /Users/andyw8/src/github.com/andyw8/rails7/.ruby-lsp/Gemfile
2: 
3: .ruby-lsp/Gemfile

@j15e
Copy link

j15e commented Apr 22, 2024

We have this problem too where we do not use Sorbet in our application and get his error when the rails lsp server starts

Any way around other than adding the Sorbet gem to our application Gemfile eheh?

Ref: I reported my error on the ruby-lsp repo at first (Shopify/ruby-lsp#1959) you can see my whole stracktrace there

@vinistock
Copy link
Member

Any way around other than adding the Sorbet gem to our application Gemfile eheh?

I wouldn't recommend doing that unless you're actually adopting Sorbet. The only thing you're currently missing out on is the column information on hover (which is the feature that depends on the runtime). The team is looking into fixing this.

@andyw8
Copy link
Contributor Author

andyw8 commented Apr 29, 2024

I've updated the Bundler docs to mention the bundle check behaviour we observed while investigating this: rubygems/rubygems#7613

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

Successfully merging a pull request may close this issue.

3 participants