Skip to content

Commit

Permalink
Make enabled_feature? return true when all flags are enabled (#2900)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
vinistock authored Nov 22, 2024
1 parent 4a05b2c commit 03b980b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ruby_lsp/global_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
14 changes: 14 additions & 0 deletions test/global_state_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 03b980b

Please sign in to comment.