Shopify / ruby-lsp-rails

A Ruby LSP addon for Rails
https://shopify.github.io/ruby-lsp-rails/
MIT License
518 stars 21 forks source link

Add support to karafka gem #315

Closed danielgatis closed 3 months ago

danielgatis commented 3 months ago

The Rails server fails to start with the following error: Karafka::Errors::MissingBootFileError. This error occurs because the file .ruby-lsp/karafka.rb does not exist.

vinistock commented 3 months ago

Thank you for the bug report. Can you explain what this file is used for?

Based on what you described, it seems like Karafka is looking for a boot file relative to BUNDLE_GEMFILE, which may not be what the gem wants to do. It might be better to use a relative path in respect to Rails.root or the default gemfile with the unbundled environment. All that is to say, this could be a bug in Karafka.

danielgatis commented 3 months ago

The gem Karafka tries to find a file named "karafka.rb" at the root of the project during Rails initialization. Since ruby-lsp-rails attempts to start the server from the '.ruby-lsp' folder, it cannot find this "karafka.rb" file. One solution I found was to create a symbolic link from the file located at the root of my Rails project to inside the '.ruby-lsp' folder.

vinistock commented 3 months ago

Yes, but if Karafka is joining the file path with Rails.root, then the fact that we launch Rails runner from a different Gemfile shouldn't matter.

I believe the issue happens because Karafka assumes that the Gemfile being used to launch Rails is in the same directory as the project root, which is not necessarily true.

Even if you want to use relative paths to Gemfiles, you can use

Bundler.with_original_env do
  Bundler.default_gemfile
end

which will give you the full path to the original Gemfile of the project.

danielgatis commented 3 months ago

@vinistock thanks!