From dc805d9b5b34ac2fd9166003975b83e1150731d8 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Thu, 28 Nov 2024 11:22:31 -0500 Subject: [PATCH] Allow opting into specific feature flags (#2931) ### Motivation In the implementation of feature flags, I forgot to check if the user opted into a specific flag. Currently, the code doesn't check for that, which means you can only opt into all of them. ### Implementation We just need to check if the user opted into that specific flag. ### Automated Tests Added a test. --- vscode/src/common.ts | 2 +- vscode/src/test/suite/common.test.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/vscode/src/common.ts b/vscode/src/common.ts index 3ce0d5183..061acae19 100644 --- a/vscode/src/common.ts +++ b/vscode/src/common.ts @@ -126,7 +126,7 @@ export function featureEnabled(feature: keyof typeof FEATURE_FLAGS): boolean { } // If the user opted-in to all features, return true - if (flagConfiguration.all) { + if (flagConfiguration.all || flagConfiguration[feature]) { return true; } diff --git a/vscode/src/test/suite/common.test.ts b/vscode/src/test/suite/common.test.ts index 23f1bc389..db9443e86 100644 --- a/vscode/src/test/suite/common.test.ts +++ b/vscode/src/test/suite/common.test.ts @@ -96,4 +96,18 @@ suite("Common", () => { stub.restore(); assert.strictEqual(result, true); }); + + test("returns true if user opted in to a specific feature", () => { + (FEATURE_FLAGS as any).fakeFeature = 0.02; + + const stub = sandbox.stub(vscode.workspace, "getConfiguration").returns({ + get: () => { + return { fakeFeature: true }; + }, + } as any); + + const result = featureEnabled("fakeFeature" as any); + stub.restore(); + assert.strictEqual(result, true); + }); });