diff --git a/lib/ruby_lsp/global_state.rb b/lib/ruby_lsp/global_state.rb index b17de2c18..520f10b1a 100644 --- a/lib/ruby_lsp/global_state.rb +++ b/lib/ruby_lsp/global_state.rb @@ -53,6 +53,7 @@ def initialize T::Boolean, ) @client_capabilities = T.let(ClientCapabilities.new, ClientCapabilities) + @enabled_feature_flags = T.let({}, T::Hash[Symbol, T::Boolean]) end sig { params(addon_name: String).returns(T.nilable(T::Hash[Symbol, T.untyped])) } @@ -139,9 +140,18 @@ def apply_options(options) @addon_settings.merge!(addon_settings) end + enabled_flags = options.dig(:initializationOptions, :enabledFeatureFlags) + @enabled_feature_flags = enabled_flags if enabled_flags + $stderr.puts(@enabled_feature_flags) + notifications end + sig { params(flag: Symbol).returns(T.nilable(T::Boolean)) } + def enabled_feature_flag?(flag) + @enabled_feature_flags[flag] + end + sig { returns(String) } def workspace_path T.must(@workspace_uri.to_standardized_path) diff --git a/test/global_state_test.rb b/test/global_state_test.rb index 4f96347cc..d965ebc5b 100644 --- a/test/global_state_test.rb +++ b/test/global_state_test.rb @@ -229,6 +229,23 @@ def test_delegates_supports_watching_files_to_client_capabilities global_state.supports_watching_files end + def test_feature_flags_are_processed_by_apply_options + state = GlobalState.new + + state.apply_options({ + initializationOptions: { + enabledFeatureFlags: { + semantic_highlighting: true, + code_lens: false, + }, + }, + }) + + assert(state.enabled_feature_flag?(:semantic_highlighting)) + refute(state.enabled_feature_flag?(:code_lens)) + assert_nil(state.enabled_feature_flag?(:unknown_flag)) + end + private def stub_direct_dependencies(dependencies) diff --git a/vscode/src/client.ts b/vscode/src/client.ts index 02983c799..49263d415 100644 --- a/vscode/src/client.ts +++ b/vscode/src/client.ts @@ -35,6 +35,8 @@ import { ClientInterface, Addon, SUPPORTED_LANGUAGE_IDS, + FEATURE_FLAGS, + featureEnabled, } from "./common"; import { Ruby } from "./ruby"; import { WorkspaceChannel } from "./workspaceChannel"; @@ -50,6 +52,14 @@ interface ServerErrorTelemetryEvent { type ServerTelemetryEvent = ServerErrorTelemetryEvent; +function enabledFeatureFlags() { + const allKeys = Object.keys(FEATURE_FLAGS) as (keyof typeof FEATURE_FLAGS)[]; + + return allKeys.map((key) => { + return { [key]: featureEnabled(key) }; + }); +} + // Get the executables to start the server based on the user's configuration function getLspExecutables( workspaceFolder: vscode.WorkspaceFolder, @@ -216,6 +226,7 @@ function collectClientOptions( linters: configuration.get("linters"), indexing: configuration.get("indexing"), addonSettings: configuration.get("addonSettings"), + enabledFeatureFlags: enabledFeatureFlags(), }, }; }