Skip to content

Commit

Permalink
Move experimental features into global state
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jun 19, 2024
1 parent 54b7e4a commit 15db8bc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
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

0 comments on commit 15db8bc

Please sign in to comment.