@actions/languageserver 0.3.35 → 0.3.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.bundle.cjs +73 -41
  2. package/package.json +4 -4
@@ -18091,8 +18091,9 @@ var ErrorType;
18091
18091
  ErrorType2[ErrorType2["ErrorExceededMaxLength"] = 4] = "ErrorExceededMaxLength";
18092
18092
  ErrorType2[ErrorType2["ErrorTooFewParameters"] = 5] = "ErrorTooFewParameters";
18093
18093
  ErrorType2[ErrorType2["ErrorTooManyParameters"] = 6] = "ErrorTooManyParameters";
18094
- ErrorType2[ErrorType2["ErrorUnrecognizedContext"] = 7] = "ErrorUnrecognizedContext";
18095
- ErrorType2[ErrorType2["ErrorUnrecognizedFunction"] = 8] = "ErrorUnrecognizedFunction";
18094
+ ErrorType2[ErrorType2["ErrorEvenParameters"] = 7] = "ErrorEvenParameters";
18095
+ ErrorType2[ErrorType2["ErrorUnrecognizedContext"] = 8] = "ErrorUnrecognizedContext";
18096
+ ErrorType2[ErrorType2["ErrorUnrecognizedFunction"] = 9] = "ErrorUnrecognizedFunction";
18096
18097
  })(ErrorType || (ErrorType = {}));
18097
18098
  var ExpressionError = class extends Error {
18098
18099
  constructor(typ, tok) {
@@ -18118,6 +18119,8 @@ function errorDescription(typ) {
18118
18119
  return "Too few parameters supplied";
18119
18120
  case ErrorType.ErrorTooManyParameters:
18120
18121
  return "Too many parameters supplied";
18122
+ case ErrorType.ErrorEvenParameters:
18123
+ return "Even number of parameters supplied, requires an odd number of parameters";
18121
18124
  case ErrorType.ErrorUnrecognizedContext:
18122
18125
  return "Unrecognized named-value";
18123
18126
  case ErrorType.ErrorUnrecognizedFunction:
@@ -18129,6 +18132,26 @@ function errorDescription(typ) {
18129
18132
  var ExpressionEvaluationError = class extends Error {
18130
18133
  };
18131
18134
 
18135
+ // ../expressions/dist/funcs/case.js
18136
+ var caseFunc = {
18137
+ name: "case",
18138
+ description: "`case( pred1, val1, pred2, val2, ..., default )`\n\nEvaluates predicates in order and returns the value corresponding to the first predicate that evaluates to `true`. If no predicate matches, it returns the last argument as the default value.",
18139
+ minArgs: 3,
18140
+ maxArgs: Number.MAX_SAFE_INTEGER,
18141
+ call: (...args) => {
18142
+ for (let i = 0; i < args.length - 1; i += 2) {
18143
+ const predicate = args[i];
18144
+ if (predicate.kind !== Kind.Boolean) {
18145
+ throw new Error("case predicate must evaluate to a boolean value");
18146
+ }
18147
+ if (predicate.value) {
18148
+ return args[i + 1];
18149
+ }
18150
+ }
18151
+ return args[args.length - 1];
18152
+ }
18153
+ };
18154
+
18132
18155
  // ../expressions/dist/result.js
18133
18156
  function falsy(d) {
18134
18157
  switch (d.kind) {
@@ -18510,6 +18533,7 @@ var tojson = {
18510
18533
 
18511
18534
  // ../expressions/dist/funcs.js
18512
18535
  var wellKnownFunctions = {
18536
+ case: caseFunc,
18513
18537
  contains,
18514
18538
  endswith,
18515
18539
  format,
@@ -18537,6 +18561,9 @@ function validateFunction(context, identifier, argCount) {
18537
18561
  if (argCount > f.maxArgs) {
18538
18562
  throw new ExpressionError(ErrorType.ErrorTooManyParameters, identifier);
18539
18563
  }
18564
+ if (name === "case" && argCount % 2 === 0) {
18565
+ throw new ExpressionError(ErrorType.ErrorEvenParameters, identifier);
18566
+ }
18540
18567
  }
18541
18568
 
18542
18569
  // ../expressions/dist/idxHelper.js
@@ -18730,6 +18757,40 @@ function objectAccess(obj, idx) {
18730
18757
  return new Null();
18731
18758
  }
18732
18759
 
18760
+ // ../expressions/dist/features.js
18761
+ var allFeatureKeys = [
18762
+ "missingInputsQuickfix",
18763
+ "blockScalarChompingWarning",
18764
+ "actionScaffoldingSnippets",
18765
+ "allowCaseFunction"
18766
+ ];
18767
+ var FeatureFlags = class {
18768
+ constructor(features) {
18769
+ this.features = features ?? {};
18770
+ }
18771
+ /**
18772
+ * Check if an experimental feature is enabled.
18773
+ *
18774
+ * Resolution order:
18775
+ * 1. Explicit feature flag (if set)
18776
+ * 2. `all` flag (if set)
18777
+ * 3. false (default)
18778
+ */
18779
+ isEnabled(feature) {
18780
+ const explicit = this.features[feature];
18781
+ if (explicit !== void 0) {
18782
+ return explicit;
18783
+ }
18784
+ return this.features.all ?? false;
18785
+ }
18786
+ /**
18787
+ * Returns list of all enabled experimental features.
18788
+ */
18789
+ getEnabledFeatures() {
18790
+ return allFeatureKeys.filter((key) => this.isEnabled(key));
18791
+ }
18792
+ };
18793
+
18733
18794
  // ../expressions/dist/parser.js
18734
18795
  var Parser = class {
18735
18796
  /**
@@ -18991,7 +19052,7 @@ var Parser = class {
18991
19052
  };
18992
19053
 
18993
19054
  // ../expressions/dist/completion.js
18994
- function complete(input, context, extensionFunctions, functions) {
19055
+ function complete(input, context, extensionFunctions, functions, featureFlags) {
18995
19056
  const lexer = new Lexer(input);
18996
19057
  const lexResult = lexer.lex();
18997
19058
  const tokenInputVector = trimTokenVector(lexResult.tokens);
@@ -19008,7 +19069,7 @@ function complete(input, context, extensionFunctions, functions) {
19008
19069
  }
19009
19070
  if (tokenIdx < 0) {
19010
19071
  const result2 = contextKeys(context);
19011
- result2.push(...functionItems(extensionFunctions));
19072
+ result2.push(...functionItems(extensionFunctions, featureFlags));
19012
19073
  return result2;
19013
19074
  }
19014
19075
  const pathTokenVector = tokenInputVector.slice(0, tokenIdx);
@@ -19019,9 +19080,13 @@ function complete(input, context, extensionFunctions, functions) {
19019
19080
  const result = ev.evaluate();
19020
19081
  return contextKeys(result);
19021
19082
  }
19022
- function functionItems(extensionFunctions) {
19083
+ function functionItems(extensionFunctions, featureFlags) {
19023
19084
  const result = [];
19085
+ const flags = featureFlags ?? new FeatureFlags();
19024
19086
  for (const fdef of [...Object.values(wellKnownFunctions), ...extensionFunctions]) {
19087
+ if (fdef.name === "case" && !flags.isEnabled("allowCaseFunction")) {
19088
+ continue;
19089
+ }
19025
19090
  result.push({
19026
19091
  label: fdef.name,
19027
19092
  description: fdef.description,
@@ -19109,39 +19174,6 @@ var DescriptionDictionary = class extends Dictionary {
19109
19174
  }
19110
19175
  };
19111
19176
 
19112
- // ../expressions/dist/features.js
19113
- var allFeatureKeys = [
19114
- "missingInputsQuickfix",
19115
- "blockScalarChompingWarning",
19116
- "actionScaffoldingSnippets"
19117
- ];
19118
- var FeatureFlags = class {
19119
- constructor(features) {
19120
- this.features = features ?? {};
19121
- }
19122
- /**
19123
- * Check if an experimental feature is enabled.
19124
- *
19125
- * Resolution order:
19126
- * 1. Explicit feature flag (if set)
19127
- * 2. `all` flag (if set)
19128
- * 3. false (default)
19129
- */
19130
- isEnabled(feature) {
19131
- const explicit = this.features[feature];
19132
- if (explicit !== void 0) {
19133
- return explicit;
19134
- }
19135
- return this.features.all ?? false;
19136
- }
19137
- /**
19138
- * Returns list of all enabled experimental features.
19139
- */
19140
- getEnabledFeatures() {
19141
- return allFeatureKeys.filter((key) => this.isEnabled(key));
19142
- }
19143
- };
19144
-
19145
19177
  // ../workflow-parser/dist/templates/tokens/types.js
19146
19178
  var TokenType2;
19147
19179
  (function(TokenType3) {
@@ -25570,7 +25602,7 @@ async function complete2(textDocument, position, config) {
25570
25602
  if (token && (isBasicExpression(token) || isPotentiallyExpression(token))) {
25571
25603
  const allowedContext = token.definitionInfo?.allowedContext || [];
25572
25604
  const context = isAction ? getActionExpressionContext(allowedContext, config?.contextProviderConfig, actionContext, Mode.Completion) : await getWorkflowExpressionContext(allowedContext, config?.contextProviderConfig, workflowContext, Mode.Completion);
25573
- return getExpressionCompletionItems(token, context, newPos);
25605
+ return getExpressionCompletionItems(token, context, newPos, config?.featureFlags);
25574
25606
  }
25575
25607
  const indentation = guessIndentation(newDoc, 2, true);
25576
25608
  const indentString = " ".repeat(indentation.tabSize);
@@ -25797,7 +25829,7 @@ function getExistingValues(token, parent) {
25797
25829
  return mapKeys;
25798
25830
  }
25799
25831
  }
25800
- function getExpressionCompletionItems(token, context, pos) {
25832
+ function getExpressionCompletionItems(token, context, pos, featureFlags) {
25801
25833
  if (!token.range) {
25802
25834
  return [];
25803
25835
  }
@@ -25811,7 +25843,7 @@ function getExpressionCompletionItems(token, context, pos) {
25811
25843
  const cursorOffset = getOffsetInContent(token.range, currentInput, pos);
25812
25844
  const expressionInput = (getExpressionInput(currentInput, cursorOffset) || "").trim();
25813
25845
  try {
25814
- return complete(expressionInput, context, [], validatorFunctions).map((item) => mapExpressionCompletionItem(item, currentInput[cursorOffset]));
25846
+ return complete(expressionInput, context, [], validatorFunctions, featureFlags).map((item) => mapExpressionCompletionItem(item, currentInput[cursorOffset]));
25815
25847
  } catch (e) {
25816
25848
  error(`Error while completing expression: '${e?.message || "<no details>"}'`);
25817
25849
  return [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actions/languageserver",
3
- "version": "0.3.35",
3
+ "version": "0.3.36",
4
4
  "description": "Language server for GitHub Actions",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -48,8 +48,8 @@
48
48
  "actions-languageserver": "./bin/actions-languageserver"
49
49
  },
50
50
  "dependencies": {
51
- "@actions/languageservice": "^0.3.35",
52
- "@actions/workflow-parser": "^0.3.35",
51
+ "@actions/languageservice": "^0.3.36",
52
+ "@actions/workflow-parser": "^0.3.36",
53
53
  "@octokit/rest": "^21.1.1",
54
54
  "@octokit/types": "^9.0.0",
55
55
  "vscode-languageserver": "^8.0.2",
@@ -78,5 +78,5 @@
78
78
  "ts-jest": "^29.0.3",
79
79
  "typescript": "^4.8.4"
80
80
  },
81
- "gitHead": "1baa74a67edfb7d408f60973333cca930e8a5044"
81
+ "gitHead": "67dd4fbd61b5077780774c13cf834a5a39286a9f"
82
82
  }