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

Support Ruby on Rails detection based on Rails individual gems #2096

Open
1 task done
louim opened this issue May 29, 2024 · 6 comments · May be fixed by #2218
Open
1 task done

Support Ruby on Rails detection based on Rails individual gems #2096

louim opened this issue May 29, 2024 · 6 comments · May be fixed by #2218
Assignees
Labels
enhancement New feature or request

Comments

@louim
Copy link

louim commented May 29, 2024

I have checked that this feature is not already implemented

  • This feature does not exist

Use case

Currently, ruby-lsp detects if a project uses Rails and will automatically bundle the ruby-lsp-rails gem.

It would be useful if this detection was not only done for the rails gem, but also on a combination of sub gems commonly used to run Rails.

Description

Having the the ruby-lsp-rails automatically bundled when a subset of gems are use to run Rails would be useful.

Implementation

It is possible to run Rails without requiring the Rails gem directly. Here is one such example in Discourse.
The current detection:

if @dependencies["rails"] && !@dependencies["ruby-lsp-rails"]
parts << 'gem "ruby-lsp-rails", require: false, group: :development'
end

Could also check if a combination of gem is included in the gemfile and in this case also bundle ruby-lsp-rails. I think checking for:

  • actionpack
  • activemodel
  • activerecord
  • activesupport
  • railties

Would be enough to ensure that the app is actually running Rails. The other gems included by the Rails gem are not strictly required to run Rails and will sometimes be absent:

  • actioncable
  • actionmailbox
  • actionmailer
  • actiontext
  • activejob
  • activestorage
@louim louim added the enhancement New feature or request label May 29, 2024
@rafaelfranca
Copy link
Member

We can detect it is a Rails app without the rails gem but we should not use the others gems to do that. A project can have:

actionpack
activemodel
activerecord
activesupport
railties

And not be a Rails app. See the Rails repository itself. Sinatra apps can also have those dependencies if they plan to mount any Rails engine.

We should detect for the config/application file and its content, not which gems are being used.

@andyw8
Copy link
Contributor

andyw8 commented May 29, 2024

I think matching on class Application < Rails::Application in config/application.rb should be reliable?

@rafaelfranca
Copy link
Member

Yes

@andyw8
Copy link
Contributor

andyw8 commented May 29, 2024

@louim feel free to open a PR for that, should be fairly straightforward.

@louim
Copy link
Author

louim commented May 30, 2024

@andyw8 I'll have a look!

@vinistock
Copy link
Member

Note: this PR started checking for bin/rails instead #2126.

It's better than the specific gems, but it's not the behaviour with config/application.rb yet.

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

Successfully merging a pull request may close this issue.

5 participants