Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Oct 2, 2024
1 parent 6013a61 commit 1bb4eec
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
20 changes: 15 additions & 5 deletions lib/ruby_lsp/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_lsp/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1bb4eec

Please sign in to comment.