Skip to content

Allow to disable any addon in the addon settings. #3523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/ruby_lsp/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def load_addons(global_state, outgoing_queue, include_project_addons: true)
self.addons = addon_classes.map(&:new)
self.file_watcher_addons = addons.select { |addon| addon.respond_to?(:workspace_did_change_watched_files) }

# Disable addons with { "rubyLsp.addonSettings": {"Addon Name": { enabled: false }}}
self.addons = addons.filter do |addon|
addon_settings = global_state.settings_for_addon(addon.name) || {}
addon_settings.fetch(:enabled, true)
end

# Activate each one of the discovered add-ons. If any problems occur in the add-ons, we don't want to
# fail to boot the server
addons.each do |addon|
Expand Down
42 changes: 42 additions & 0 deletions test/addon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def setup
attr_reader :activated, :field, :settings

def initialize
@activated = false
@field = 123
super
end
Expand Down Expand Up @@ -100,6 +101,10 @@ def activate(global_state, outgoing_queue); end
def deactivate; end

def workspace_did_change_watched_files(changes); end

def name
"Some Addon"
end
end

Addon.load_addons(@global_state, @outgoing_queue)
Expand Down Expand Up @@ -190,5 +195,42 @@ def version
assert_predicate(addon, :hello)
end
end

def test_disabled_addons_are_not_loaded
@global_state = GlobalState.new
@global_state.apply_options({
initializationOptions: {
addonSettings: {
"My Add-on": {
enabled: false,
},
},
},
})

Addon.load_addons(@global_state, @outgoing_queue)

assert_raises(Addon::AddonNotFoundError) do
Addon.get("My Add-on", "0.1.0")
end
end

def test_enabled_addons_are_loaded
@global_state = GlobalState.new
@global_state.apply_options({
initializationOptions: {
addonSettings: {
"My Add-on": {
enabled: true,
},
},
},
})

Addon.load_addons(@global_state, @outgoing_queue)

addon = Addon.get("My Add-on", "0.1.0")
assert_equal("My Add-on", addon.name)
end
end
end