Skip to content

Commit

Permalink
Provide a way for addon developers to get an addon by name (#2216)
Browse files Browse the repository at this point in the history
  • Loading branch information
andyw8 authored Jun 20, 2024
1 parent 8830833 commit 4abb4e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/ruby_lsp/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ def load_addons(global_state, outgoing_queue)
addon.add_error(e)
end
end

# Intended for use by tests for addons
sig { params(addon_name: String).returns(Addon) }
def get(addon_name)
addon = addons.find { |addon| addon.name == addon_name }
raise "Could not find addon '#{addon_name}'" unless addon

addon
end
end

sig { void }
Expand Down
11 changes: 11 additions & 0 deletions test/addon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,16 @@ def workspace_did_change_watched_files(changes); end
Addon.file_watcher_addons.clear
end
end

def test_get_an_addon_by_name
addon = Addon.get("My Addon")
assert_equal("My Addon", addon.name)
end

def test_raises_if_an_addon_cannot_be_found
assert_raises do
Addon.get("Invalid Addon")
end
end
end
end

0 comments on commit 4abb4e1

Please sign in to comment.