Skip to content
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

Move experimental features into global state #2209

Merged
merged 1 commit into from
Jun 20, 2024
Merged
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
5 changes: 4 additions & 1 deletion lib/ruby_lsp/global_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GlobalState
attr_reader :encoding

sig { returns(T::Boolean) }
attr_reader :supports_watching_files
attr_reader :supports_watching_files, :experimental_features

sig { returns(TypeInferrer) }
attr_reader :type_inferrer
Expand All @@ -39,6 +39,7 @@ def initialize
@type_inferrer = T.let(TypeInferrer.new(@index), TypeInferrer)
@supported_formatters = T.let({}, T::Hash[String, Requests::Support::Formatter])
@supports_watching_files = T.let(false, T::Boolean)
@experimental_features = T.let(false, T::Boolean)
end

sig { params(identifier: String, instance: Requests::Support::Formatter).void }
Expand Down Expand Up @@ -87,6 +88,8 @@ def apply_options(options)
if file_watching_caps&.dig(:dynamicRegistration) && file_watching_caps&.dig(:relativePatternSupport)
@supports_watching_files = true
end

@experimental_features = options.dig(:initializationOptions, :experimentalFeaturesEnabled) || false
end

sig { returns(String) }
Expand Down
1 change: 0 additions & 1 deletion lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def run_initialize(message)
progress = options.dig(:capabilities, :window, :workDoneProgress)
@store.supports_progress = progress.nil? ? true : progress
configured_features = options.dig(:initializationOptions, :enabledFeatures)
@store.experimental_features = options.dig(:initializationOptions, :experimentalFeaturesEnabled) || false

configured_hints = options.dig(:initializationOptions, :featuresConfiguration, :inlayHint)
T.must(@store.features_configuration.dig(:inlayHint)).configuration.merge!(configured_hints) if configured_hints
Expand Down
4 changes: 0 additions & 4 deletions lib/ruby_lsp/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ class Store
sig { returns(T::Boolean) }
attr_accessor :supports_progress

sig { returns(T::Boolean) }
attr_accessor :experimental_features

sig { returns(T::Hash[Symbol, RequestConfig]) }
attr_accessor :features_configuration

Expand All @@ -21,7 +18,6 @@ class Store
def initialize
@state = T.let({}, T::Hash[String, Document])
@supports_progress = T.let(true, T::Boolean)
@experimental_features = T.let(false, T::Boolean)
@features_configuration = T.let(
{
inlayHint: RequestConfig.new({
Expand Down
11 changes: 11 additions & 0 deletions test/global_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ def test_specifying_empty_linters
assert_empty(state.instance_variable_get(:@linters))
end

def test_apply_options_sets_experimental_features
state = GlobalState.new
refute_predicate(state, :experimental_features)

state.apply_options({
initializationOptions: { experimentalFeaturesEnabled: true },
})

assert_predicate(state, :experimental_features)
end

private

def stub_direct_dependencies(dependencies)
Expand Down
Loading