Skip to content

Commit eb71b18

Browse files
authored
Revert "Merge pull request #320 from actions/allanguigou/default-case" (#332)
This reverts commit 191a7b6, reversing changes made to 448180b.
1 parent 92c5235 commit eb71b18

File tree

5 files changed

+56
-15
lines changed

5 files changed

+56
-15
lines changed

expressions/src/completion.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export function complete(
3535
context: Dictionary,
3636
extensionFunctions: FunctionInfo[],
3737
functions?: Map<string, FunctionDefinition>,
38-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3938
featureFlags?: FeatureFlags
4039
): CompletionItem[] {
4140
// Lex
@@ -67,7 +66,7 @@ export function complete(
6766
const result = contextKeys(context);
6867

6968
// Merge with functions
70-
result.push(...functionItems(extensionFunctions));
69+
result.push(...functionItems(extensionFunctions, featureFlags));
7170

7271
return result;
7372
}
@@ -92,10 +91,15 @@ export function complete(
9291
return contextKeys(result);
9392
}
9493

95-
function functionItems(extensionFunctions: FunctionInfo[]): CompletionItem[] {
94+
function functionItems(extensionFunctions: FunctionInfo[], featureFlags?: FeatureFlags): CompletionItem[] {
9695
const result: CompletionItem[] = [];
96+
const flags = featureFlags ?? new FeatureFlags();
9797

9898
for (const fdef of [...Object.values(wellKnownFunctions), ...extensionFunctions]) {
99+
// Filter out case function if feature is disabled
100+
if (fdef.name === "case" && !flags.isEnabled("allowCaseFunction")) {
101+
continue;
102+
}
99103
result.push({
100104
label: fdef.name,
101105
description: fdef.description,

expressions/src/features.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ describe("FeatureFlags", () => {
5151

5252
it("returns all features when all is enabled", () => {
5353
const flags = new FeatureFlags({all: true});
54-
expect(flags.getEnabledFeatures()).toEqual(["missingInputsQuickfix", "blockScalarChompingWarning"]);
54+
expect(flags.getEnabledFeatures()).toEqual([
55+
"missingInputsQuickfix",
56+
"blockScalarChompingWarning",
57+
"allowCaseFunction"
58+
]);
5559
});
5660
});
5761
});

expressions/src/features.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ export interface ExperimentalFeatures {
2828
* @default false
2929
*/
3030
blockScalarChompingWarning?: boolean;
31+
32+
/**
33+
* Enable the case() function in expressions.
34+
* @default false
35+
*/
36+
allowCaseFunction?: boolean;
3137
}
3238

3339
/**
@@ -39,7 +45,11 @@ export type ExperimentalFeatureKey = Exclude<keyof ExperimentalFeatures, "all">;
3945
* All known experimental feature keys.
4046
* This list must be kept in sync with the ExperimentalFeatures interface.
4147
*/
42-
const allFeatureKeys: ExperimentalFeatureKey[] = ["missingInputsQuickfix", "blockScalarChompingWarning"];
48+
const allFeatureKeys: ExperimentalFeatureKey[] = [
49+
"missingInputsQuickfix",
50+
"blockScalarChompingWarning",
51+
"allowCaseFunction"
52+
];
4353

4454
export class FeatureFlags {
4555
private readonly features: ExperimentalFeatures;

languageservice/src/complete.expressions.test.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2-
import {data, DescriptionDictionary} from "@actions/expressions";
2+
import {data, DescriptionDictionary, FeatureFlags} from "@actions/expressions";
33
import {CompletionItem, CompletionItemKind, MarkupContent} from "vscode-languageserver-types";
44
import {complete, getExpressionInput} from "./complete.js";
55
import {ContextProviderConfig} from "./context-providers/config.js";
@@ -69,7 +69,8 @@ describe("expressions", () => {
6969
it("single region", async () => {
7070
const input = "run-name: ${{ | }}";
7171
const result = await complete(...getPositionFromCursor(input), {
72-
contextProviderConfig
72+
contextProviderConfig,
73+
featureFlags: new FeatureFlags({allowCaseFunction: true})
7374
});
7475

7576
expect(result.map(x => x.label)).toEqual([
@@ -112,7 +113,8 @@ describe("expressions", () => {
112113
it("single region with existing input", async () => {
113114
const input = "run-name: ${{ g| }}";
114115
const result = await complete(...getPositionFromCursor(input), {
115-
contextProviderConfig
116+
contextProviderConfig,
117+
featureFlags: new FeatureFlags({allowCaseFunction: true})
116118
});
117119

118120
expect(result.map(x => x.label)).toEqual([
@@ -133,7 +135,8 @@ describe("expressions", () => {
133135
it("single region with existing condition", async () => {
134136
const input = "run-name: ${{ g| == 'test' }}";
135137
const result = await complete(...getPositionFromCursor(input), {
136-
contextProviderConfig
138+
contextProviderConfig,
139+
featureFlags: new FeatureFlags({allowCaseFunction: true})
137140
});
138141

139142
expect(result.map(x => x.label)).toEqual([
@@ -154,7 +157,8 @@ describe("expressions", () => {
154157
it("multiple regions with partial function", async () => {
155158
const input = "run-name: Run a ${{ inputs.test }} one-line script ${{ from|('test') == inputs.name }}";
156159
const result = await complete(...getPositionFromCursor(input), {
157-
contextProviderConfig
160+
contextProviderConfig,
161+
featureFlags: new FeatureFlags({allowCaseFunction: true})
158162
});
159163

160164
expect(result.map(x => x.label)).toEqual([
@@ -175,7 +179,8 @@ describe("expressions", () => {
175179
it("multiple regions - first region", async () => {
176180
const input = "run-name: test-${{ git| == 1 }}-${{ github.event }}";
177181
const result = await complete(...getPositionFromCursor(input), {
178-
contextProviderConfig
182+
contextProviderConfig,
183+
featureFlags: new FeatureFlags({allowCaseFunction: true})
179184
});
180185

181186
expect(result.map(x => x.label)).toEqual([
@@ -196,7 +201,8 @@ describe("expressions", () => {
196201
it("multiple regions", async () => {
197202
const input = "run-name: test-${{ github }}-${{ | }}";
198203
const result = await complete(...getPositionFromCursor(input), {
199-
contextProviderConfig
204+
contextProviderConfig,
205+
featureFlags: new FeatureFlags({allowCaseFunction: true})
200206
});
201207

202208
expect(result.map(x => x.label)).toEqual([
@@ -1175,7 +1181,8 @@ jobs:
11751181
`;
11761182

11771183
const result = await complete(...getPositionFromCursor(input), {
1178-
contextProviderConfig
1184+
contextProviderConfig,
1185+
featureFlags: new FeatureFlags({allowCaseFunction: true})
11791186
});
11801187
expect(result.map(x => x.label)).toEqual([
11811188
"env",

languageservice/src/complete.test.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {getPositionFromCursor} from "./test-utils/cursor-position.js";
66
import {TestLogger} from "./test-utils/logger.js";
77
import {clearCache} from "./utils/workflow-cache.js";
88
import {ValueProviderConfig, ValueProviderKind} from "./value-providers/config.js";
9+
import {FeatureFlags} from "@actions/expressions/features";
910

1011
registerLogger(new TestLogger());
1112

@@ -897,15 +898,30 @@ jobs:
897898
});
898899

899900
describe("expression completions", () => {
900-
it("includes case function", async () => {
901+
it("include case function when enabled", async () => {
901902
const input = "on: push\njobs:\n build:\n runs-on: ${{ c|";
902-
const result = await complete(...getPositionFromCursor(input));
903+
const result = await complete(...getPositionFromCursor(input), {
904+
featureFlags: new FeatureFlags({allowCaseFunction: true})
905+
});
903906

904907
expect(result).not.toBeUndefined();
905908
// Expression completions starting with 'c': case, contains
906909
const labels = result.map(x => x.label);
907910
expect(labels).toContain("case");
908911
expect(labels).toContain("contains");
909912
});
913+
914+
it("exclude case function when disabled", async () => {
915+
const input = "on: push\njobs:\n build:\n runs-on: ${{ c|";
916+
const result = await complete(...getPositionFromCursor(input), {
917+
featureFlags: new FeatureFlags({allowCaseFunction: false})
918+
});
919+
920+
expect(result).not.toBeUndefined();
921+
// Expression completions starting with 'c': contains
922+
const labels = result.map(x => x.label);
923+
expect(labels).not.toContain("case");
924+
expect(labels).toContain("contains");
925+
});
910926
});
911927
});

0 commit comments

Comments
 (0)