ruby-lsp icon indicating copy to clipboard operation
ruby-lsp copied to clipboard

Support Ruby on Rails detection based on Rails individual gems

Open louim opened this issue 1 year ago • 6 comments

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:

  • 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 avatar May 29 '24 14:05 louim

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.

rafaelfranca avatar May 29 '24 16:05 rafaelfranca

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

andyw8 avatar May 29 '24 17:05 andyw8

Yes

rafaelfranca avatar May 29 '24 17:05 rafaelfranca

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

andyw8 avatar May 29 '24 17:05 andyw8

@andyw8 I'll have a look!

louim avatar May 30 '24 13:05 louim

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.

vinistock avatar Jun 11 '24 16:06 vinistock

This issue is being marked as stale because there was no activity in the last 2 months

github-actions[bot] avatar Aug 11 '24 12:08 github-actions[bot]