From cecf4243bff01569ebe760568612c74ece633b45 Mon Sep 17 00:00:00 2001
From: domingo2000
Date: Wed, 21 May 2025 22:15:08 -0400
Subject: [PATCH] Allow to disable any addon in the addon settings.
---
lib/ruby_lsp/addon.rb | 6 ++++++
test/addon_test.rb | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
diff --git a/lib/ruby_lsp/addon.rb b/lib/ruby_lsp/addon.rb
index b620d78f4c..1e0a72888c 100644
--- a/lib/ruby_lsp/addon.rb
+++ b/lib/ruby_lsp/addon.rb
@@ -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|
diff --git a/test/addon_test.rb b/test/addon_test.rb
index 1be42e0c5a..2528fc74aa 100644
--- a/test/addon_test.rb
+++ b/test/addon_test.rb
@@ -10,6 +10,7 @@ def setup
attr_reader :activated, :field, :settings
def initialize
+ @activated = false
@field = 123
super
end
@@ -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)
@@ -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