Skip to content

Commit

Permalink
Allow for under development feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jan 31, 2025
1 parent 943d78e commit c2ba939
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
10 changes: 8 additions & 2 deletions vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ export const SUPPORTED_LANGUAGE_IDS = ["ruby", "erb"];
// A list of feature flags where the key is the name and the value is the rollout percentage.
//
// Note: names added here should also be added to the `rubyLsp.optedOutFeatureFlags` enum in the `package.json` file
// Note 2: -1 is a special value used to indicate under development features. Those can only be enabled explicitly and
// are not impacted by the user's choice of opting into all flags
export const FEATURE_FLAGS = {
tapiocaAddon: 0.3,
launcher: 0.05,
Expand Down Expand Up @@ -127,12 +129,16 @@ export function featureEnabled(feature: keyof typeof FEATURE_FLAGS): boolean {
return false;
}

const percentage = FEATURE_FLAGS[feature];

// If the user opted-in to all features, return true
if (flagConfiguration.all || flagConfiguration[feature]) {
if (
(flagConfiguration.all && percentage !== -1) ||
flagConfiguration[feature]
) {
return true;
}

const percentage = FEATURE_FLAGS[feature];
const machineId = vscode.env.machineId;
// Create a digest of the concatenated machine ID and feature name, which will generate a unique hash for this
// user-feature combination
Expand Down
28 changes: 28 additions & 0 deletions vscode/src/test/suite/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,32 @@ suite("Common", () => {
stub.restore();
assert.strictEqual(result, true);
});

test("only returns true if explicitly opting into under development flags", () => {
(FEATURE_FLAGS as any).fakeFeature = -1;

// With only `all` enabled
const firstStub = sandbox
.stub(vscode.workspace, "getConfiguration")
.returns({
get: () => {
return { all: true };
},
} as any);

firstStub.restore();
assert.strictEqual(featureEnabled("fakeFeature" as any), false);

// With fakeFeature enabled
const secondStub = sandbox
.stub(vscode.workspace, "getConfiguration")
.returns({
get: () => {
return { all: true, fakeFeature: true };
},
} as any);

assert.strictEqual(featureEnabled("fakeFeature" as any), true);
secondStub.restore();
});
});

0 comments on commit c2ba939

Please sign in to comment.