From ebe59fb1b657f9dbb8235f00151948e29e60c6d1 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Tue, 20 Aug 2024 09:50:55 -0400 Subject: [PATCH] Revert "Make Rails app detection based on Rails::Application superclass (#2218)" This reverts commit 392d1aaff431878333dc574dfd24012c467016cd. --- lib/ruby_lsp/setup_bundler.rb | 19 ++++--------------- test/fixtures/rails_application.rb | 4 ---- test/setup_bundler_test.rb | 6 ------ 3 files changed, 4 insertions(+), 25 deletions(-) delete mode 100644 test/fixtures/rails_application.rb diff --git a/lib/ruby_lsp/setup_bundler.rb b/lib/ruby_lsp/setup_bundler.rb index 9f1ba0397..55f5fe059 100644 --- a/lib/ruby_lsp/setup_bundler.rb +++ b/lib/ruby_lsp/setup_bundler.rb @@ -50,7 +50,6 @@ def initialize(project_path, **options) @last_updated_path = T.let(@custom_dir + "last_updated", Pathname) @dependencies = T.let(load_dependencies, T::Hash[String, T.untyped]) - @rails_app = T.let(rails_app?, T::Boolean) @retry = T.let(false, T::Boolean) end @@ -63,7 +62,7 @@ def setup! # Do not set up a custom bundle if LSP dependencies are already in the Gemfile if @dependencies["ruby-lsp"] && @dependencies["debug"] && - (@rails_app ? @dependencies["ruby-lsp-rails"] : true) + (@dependencies["rails"] ? @dependencies["ruby-lsp-rails"] : true) $stderr.puts( "Ruby LSP> Skipping custom bundle setup since LSP dependencies are already in #{@gemfile}", ) @@ -149,7 +148,7 @@ def write_custom_gemfile parts << 'gem "debug", require: false, group: :development, platforms: :mri' end - if @rails_app && !@dependencies["ruby-lsp-rails"] + if @dependencies["rails"] && !@dependencies["ruby-lsp-rails"] parts << 'gem "ruby-lsp-rails", require: false, group: :development' end @@ -210,7 +209,7 @@ def run_bundle_install(bundle_gemfile = @gemfile) command << " && bundle update " command << "ruby-lsp " unless @dependencies["ruby-lsp"] command << "debug " unless @dependencies["debug"] - command << "ruby-lsp-rails " if @rails_app && !@dependencies["ruby-lsp-rails"] + command << "ruby-lsp-rails " if @dependencies["rails"] && !@dependencies["ruby-lsp-rails"] command << "--pre" if @experimental command.delete_suffix!(" ") command << ")" @@ -245,7 +244,7 @@ def run_bundle_install(bundle_gemfile = @gemfile) def should_bundle_update? # If `ruby-lsp`, `ruby-lsp-rails` and `debug` are in the Gemfile, then we shouldn't try to upgrade them or else it # will produce version control changes - if @rails_app + if @dependencies["rails"] return false if @dependencies.values_at("ruby-lsp", "ruby-lsp-rails", "debug").all? # If the custom lockfile doesn't include `ruby-lsp`, `ruby-lsp-rails` or `debug`, we need to run bundle install @@ -281,15 +280,5 @@ def correct_relative_remote_paths @custom_lockfile.write(content) end - - # Detects if the project is a Rails app by looking if the superclass of the main class is `Rails::Application` - sig { returns(T::Boolean) } - def rails_app? - config = Pathname.new("config/application.rb").expand_path - application_contents = config.read if config.exist? - return false unless application_contents - - /class .* < (::)?Rails::Application/.match?(application_contents) - end end end diff --git a/test/fixtures/rails_application.rb b/test/fixtures/rails_application.rb deleted file mode 100644 index 27eff561a..000000000 --- a/test/fixtures/rails_application.rb +++ /dev/null @@ -1,4 +0,0 @@ -module MyApp - class Application < Rails::Application - end -end diff --git a/test/setup_bundler_test.rb b/test/setup_bundler_test.rb index 09b1f2760..6b9a06fe1 100644 --- a/test/setup_bundler_test.rb +++ b/test/setup_bundler_test.rb @@ -79,9 +79,6 @@ def test_creates_custom_bundle_for_a_rails_app bundle_env(".ruby-lsp/Gemfile"), "(bundle check || bundle install) 1>&2", ).returns(true) - - FileUtils.mkdir("config") - FileUtils.cp("test/fixtures/rails_application.rb", "config/application.rb") Bundler::LockfileParser.any_instance.expects(:dependencies).returns({ "rails" => true }).at_least_once run_script @@ -94,7 +91,6 @@ def test_creates_custom_bundle_for_a_rails_app assert_match("ruby-lsp-rails", File.read(".ruby-lsp/Gemfile")) ensure FileUtils.rm_r(".ruby-lsp") if Dir.exist?(".ruby-lsp") - FileUtils.rm_r("config") if Dir.exist?("config") end def test_changing_lockfile_causes_custom_bundle_to_be_rebuilt @@ -484,8 +480,6 @@ def test_ensures_lockfile_remotes_are_relative_to_default_gemfile def test_ruby_lsp_rails_is_automatically_included_in_rails_apps Dir.mktmpdir do |dir| - FileUtils.mkdir("#{dir}/config") - FileUtils.cp("test/fixtures/rails_application.rb", "#{dir}/config/application.rb") Dir.chdir(dir) do File.write(File.join(dir, "Gemfile"), <<~GEMFILE) source "https://rubygems.org"