From 03b980bfa8c567996b333182d69efff2428954eb Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Fri, 22 Nov 2024 10:53:59 -0500 Subject: [PATCH] Make `enabled_feature?` return true when all flags are enabled (#2900) ### Motivation When fixing the mistake on the feature flags object composition, I also noticed that the global state wouldn't return `true` if the user had their configuration set as ```json { "rubyLsp.featureFlags": { "all": true } } ``` which is not correct. If they enabled all flags, then checking with `enabled_feature?` should return `true`. ### Implementation Started returning `true` if `all` is enabled. ### Automated Tests Added a test. --- lib/ruby_lsp/global_state.rb | 2 +- test/global_state_test.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/ruby_lsp/global_state.rb b/lib/ruby_lsp/global_state.rb index df0eee261..004df40d9 100644 --- a/lib/ruby_lsp/global_state.rb +++ b/lib/ruby_lsp/global_state.rb @@ -146,7 +146,7 @@ def apply_options(options) sig { params(flag: Symbol).returns(T.nilable(T::Boolean)) } def enabled_feature?(flag) - @enabled_feature_flags[flag] + @enabled_feature_flags[:all] || @enabled_feature_flags[flag] end sig { returns(String) } diff --git a/test/global_state_test.rb b/test/global_state_test.rb index 02dc0ee66..b655dcbfe 100644 --- a/test/global_state_test.rb +++ b/test/global_state_test.rb @@ -235,6 +235,20 @@ def test_feature_flags_are_processed_by_apply_options assert_nil(state.enabled_feature?(:unknown_flag)) end + def test_enabled_feature_always_returns_true_if_all_are_enabled + state = GlobalState.new + + state.apply_options({ + initializationOptions: { + enabledFeatureFlags: { + all: true, + }, + }, + }) + + assert(state.enabled_feature?(:whatever)) + end + private def stub_direct_dependencies(dependencies)