Skip to content

Commit 6f83f74

Browse files
authored
Add feature flag support to GlobalState (#2826)
### Motivation This PR starts passing the enabled feature flags to the server and storing it in the global state. That way the Ruby LSP and its add-ons can check for specific feature flags. This also allows users of other editors to opt into features through `initializationOptions`. ### Implementation - Started passing all enabled flag information to the server - Started storing this information in the global state ### Automated Tests Added unit tests to verify feature flag processing and retrieval functionality.
1 parent 2044b7c commit 6f83f74

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

lib/ruby_lsp/global_state.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def initialize
5353
T::Boolean,
5454
)
5555
@client_capabilities = T.let(ClientCapabilities.new, ClientCapabilities)
56+
@enabled_feature_flags = T.let({}, T::Hash[Symbol, T::Boolean])
5657
end
5758

5859
sig { params(addon_name: String).returns(T.nilable(T::Hash[Symbol, T.untyped])) }
@@ -139,9 +140,17 @@ def apply_options(options)
139140
@addon_settings.merge!(addon_settings)
140141
end
141142

143+
enabled_flags = options.dig(:initializationOptions, :enabledFeatureFlags)
144+
@enabled_feature_flags = enabled_flags if enabled_flags
145+
142146
notifications
143147
end
144148

149+
sig { params(flag: Symbol).returns(T.nilable(T::Boolean)) }
150+
def enabled_feature?(flag)
151+
@enabled_feature_flags[flag]
152+
end
153+
145154
sig { returns(String) }
146155
def workspace_path
147156
T.must(@workspace_uri.to_standardized_path)

test/global_state_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,23 @@ def test_delegates_supports_watching_files_to_client_capabilities
229229
global_state.supports_watching_files
230230
end
231231

232+
def test_feature_flags_are_processed_by_apply_options
233+
state = GlobalState.new
234+
235+
state.apply_options({
236+
initializationOptions: {
237+
enabledFeatureFlags: {
238+
semantic_highlighting: true,
239+
code_lens: false,
240+
},
241+
},
242+
})
243+
244+
assert(state.enabled_feature?(:semantic_highlighting))
245+
refute(state.enabled_feature?(:code_lens))
246+
assert_nil(state.enabled_feature?(:unknown_flag))
247+
end
248+
232249
private
233250

234251
def stub_direct_dependencies(dependencies)

vscode/src/client.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import {
3535
ClientInterface,
3636
Addon,
3737
SUPPORTED_LANGUAGE_IDS,
38+
FEATURE_FLAGS,
39+
featureEnabled,
3840
} from "./common";
3941
import { Ruby } from "./ruby";
4042
import { WorkspaceChannel } from "./workspaceChannel";
@@ -50,6 +52,14 @@ interface ServerErrorTelemetryEvent {
5052

5153
type ServerTelemetryEvent = ServerErrorTelemetryEvent;
5254

55+
function enabledFeatureFlags() {
56+
const allKeys = Object.keys(FEATURE_FLAGS) as (keyof typeof FEATURE_FLAGS)[];
57+
58+
return allKeys.map((key) => {
59+
return { [key]: featureEnabled(key) };
60+
});
61+
}
62+
5363
// Get the executables to start the server based on the user's configuration
5464
function getLspExecutables(
5565
workspaceFolder: vscode.WorkspaceFolder,
@@ -216,6 +226,7 @@ function collectClientOptions(
216226
linters: configuration.get("linters"),
217227
indexing: configuration.get("indexing"),
218228
addonSettings: configuration.get("addonSettings"),
229+
enabledFeatureFlags: enabledFeatureFlags(),
219230
},
220231
};
221232
}

0 commit comments

Comments
 (0)