-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Rails app detection based on Rails::Application superclass
This change makes the Rails app detection based on the superclass of the main class being `Rails::Application`. This is a more reliable way to detect Rails apps than looking for the presence of the `rails` gem in the Gemfile. Application can require some of the Rails components without requiring the `rails` gem itself. co-authored-by: Earlopain <[email protected]>
- Loading branch information
Showing
3 changed files
with
91 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module RubyLsp | ||
module Listeners | ||
class RailsApp | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
attr_reader :rails_app | ||
|
||
sig { params(dispatcher: Prism::Dispatcher).void } | ||
def initialize(dispatcher) | ||
@rails_app = T.let(false, T::Boolean) | ||
dispatcher.register(self, :on_class_node_enter) | ||
end | ||
|
||
sig { params(node: Prism::ClassNode).void } | ||
def on_class_node_enter(node) | ||
superclass = node.superclass | ||
case superclass | ||
when Prism::ConstantPathNode | ||
@rails_app = true if superclass.full_name == "Rails::Application" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters