diff --git a/lib/ruby_lsp/addon.rb b/lib/ruby_lsp/addon.rb index af3171ce3..d9ec2a84b 100644 --- a/lib/ruby_lsp/addon.rb +++ b/lib/ruby_lsp/addon.rb @@ -54,14 +54,24 @@ def inherited(child_class) end # Discovers and loads all add-ons. Returns a list of errors when trying to require add-ons - sig { params(global_state: GlobalState, outgoing_queue: Thread::Queue).returns(T::Array[StandardError]) } - def load_addons(global_state, outgoing_queue) + sig do + params( + global_state: GlobalState, + outgoing_queue: Thread::Queue, + include_project_addons: T::Boolean, + ).returns(T::Array[StandardError]) + end + def load_addons(global_state, outgoing_queue, include_project_addons: true) # Require all add-ons entry points, which should be placed under # `some_gem/lib/ruby_lsp/your_gem_name/addon.rb` or in the workspace under # `your_project/ruby_lsp/project_name/addon.rb` - errors = Gem.find_files("ruby_lsp/**/addon.rb") - .concat(Dir.glob(File.join(global_state.workspace_path, "**", "ruby_lsp/**/addon.rb"))) - .filter_map do |addon_path| + addon_files = Gem.find_files("ruby_lsp/**/addon.rb") + + if include_project_addons + addon_files.concat(Dir.glob(File.join(global_state.workspace_path, "**", "ruby_lsp/**/addon.rb"))) + end + + errors = addon_files.filter_map do |addon_path| # Avoid requiring this file twice. This may happen if you're working on the Ruby LSP itself and at the same # time have `ruby-lsp` installed as a vendored gem next if File.basename(File.dirname(addon_path)) == "ruby_lsp" diff --git a/lib/ruby_lsp/server.rb b/lib/ruby_lsp/server.rb index bf3aedaea..2f08a7693 100644 --- a/lib/ruby_lsp/server.rb +++ b/lib/ruby_lsp/server.rb @@ -123,9 +123,9 @@ def process_message(message) send_log_message("Error processing #{message[:method]}: #{e.full_message}", type: Constant::MessageType::ERROR) end - sig { void } - def load_addons - errors = Addon.load_addons(@global_state, @outgoing_queue) + sig { params(include_project_addons: T::Boolean).void } + def load_addons(include_project_addons: true) + errors = Addon.load_addons(@global_state, @outgoing_queue, include_project_addons: include_project_addons) if errors.any? send_log_message( diff --git a/lib/ruby_lsp/test_helper.rb b/lib/ruby_lsp/test_helper.rb index d01d2dc3b..fb21805ac 100644 --- a/lib/ruby_lsp/test_helper.rb +++ b/lib/ruby_lsp/test_helper.rb @@ -42,7 +42,7 @@ def with_server(source = nil, uri = Kernel.URI("file:///fake.rb"), stub_no_typec RubyIndexer::IndexablePath.new(nil, T.must(uri.to_standardized_path)), source, ) - server.load_addons if load_addons + server.load_addons(include_project_addons: false) if load_addons block.call(server, uri) ensure if load_addons