Support Ruby on Rails detection based on Rails individual gems
I have checked that this feature is not already implemented
- [X] 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:
https://github.com/Shopify/ruby-lsp/blob/410d58453a20089c131eed81a0d5485e0a6b65a7/lib/ruby_lsp/setup_bundler.rb#L151-L153
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:
actionpackactivemodelactiverecordactivesupportrailties
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:
actioncableactionmailboxactionmaileractiontextactivejobactivestorage
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.
I think matching on class Application < Rails::Application in config/application.rb should be reliable?
Yes
@louim feel free to open a PR for that, should be fairly straightforward.
@andyw8 I'll have a look!
Note: this PR started checking for bin/rails instead https://github.com/Shopify/ruby-lsp/pull/2126.
It's better than the specific gems, but it's not the behaviour with config/application.rb yet.
This issue is being marked as stale because there was no activity in the last 2 months