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

Allow for under development feature flags #3119

Merged
merged 1 commit into from
Feb 3, 2025
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
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.5,
launcher: 0.1,
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();
});
});