@actions/languageserver 0.3.26 → 0.3.28

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 +138 -14
  2. package/package.json +4 -4
@@ -23412,6 +23412,7 @@ function getJobContext(workflowContext) {
23412
23412
  jobContext.add("services", servicesContext);
23413
23413
  }
23414
23414
  jobContext.add("status", new data_exports.Null());
23415
+ jobContext.add("check_run_id", new data_exports.Null());
23415
23416
  return jobContext;
23416
23417
  }
23417
23418
  function createContainerContext(container, isServices) {
@@ -24454,13 +24455,13 @@ var DefinitionValueMode;
24454
24455
  DefinitionValueMode2[DefinitionValueMode2["Parent"] = 0] = "Parent";
24455
24456
  DefinitionValueMode2[DefinitionValueMode2["Key"] = 1] = "Key";
24456
24457
  })(DefinitionValueMode = DefinitionValueMode || (DefinitionValueMode = {}));
24457
- function definitionValues(def, indentation, mode) {
24458
+ function definitionValues(def, indentation, mode, tokenStructure) {
24458
24459
  const schema2 = getWorkflowSchema();
24459
24460
  if (def instanceof MappingDefinition) {
24460
24461
  return mappingValues(def, schema2.definitions, indentation, mode);
24461
24462
  }
24462
24463
  if (def instanceof OneOfDefinition) {
24463
- return oneOfValues(def, schema2.definitions, indentation, mode);
24464
+ return oneOfValues(def, schema2.definitions, indentation, mode, tokenStructure);
24464
24465
  }
24465
24466
  if (def instanceof BooleanDefinition) {
24466
24467
  return stringsToValues(["true", "false"]);
@@ -24511,14 +24512,12 @@ ${indentation}${indentation}`;
24511
24512
  ${indentation}`;
24512
24513
  }
24513
24514
  break;
24514
- case DefinitionType.OneOf:
24515
- if (mode == DefinitionValueMode.Key) {
24516
- insertText = `
24517
- ${indentation}${key}: `;
24518
- } else {
24519
- insertText = `${key}: `;
24520
- }
24521
- break;
24515
+ case DefinitionType.OneOf: {
24516
+ const oneOfDef = typeDef;
24517
+ const expanded = expandOneOfToCompletions(oneOfDef, definitions, key, description, indentation, mode);
24518
+ properties.push(...expanded);
24519
+ continue;
24520
+ }
24522
24521
  case DefinitionType.String:
24523
24522
  case DefinitionType.Boolean:
24524
24523
  if (mode == DefinitionValueMode.Key) {
@@ -24541,10 +24540,20 @@ ${indentation}${key}: `;
24541
24540
  }
24542
24541
  return properties;
24543
24542
  }
24544
- function oneOfValues(oneOfDefinition, definitions, indentation, mode) {
24543
+ function oneOfValues(oneOfDefinition, definitions, indentation, mode, tokenStructure) {
24545
24544
  const values = [];
24546
24545
  for (const key of oneOfDefinition.oneOf) {
24547
- values.push(...definitionValues(definitions[key], indentation, mode));
24546
+ const variantDef = definitions[key];
24547
+ if (!variantDef) {
24548
+ continue;
24549
+ }
24550
+ if (tokenStructure) {
24551
+ const variantBucket = getStructuralBucket(variantDef.definitionType);
24552
+ if (variantBucket !== tokenStructure) {
24553
+ continue;
24554
+ }
24555
+ }
24556
+ values.push(...definitionValues(variantDef, indentation, mode, tokenStructure));
24548
24557
  }
24549
24558
  return distinctValues(values);
24550
24559
  }
@@ -24555,6 +24564,74 @@ function distinctValues(values) {
24555
24564
  }
24556
24565
  return Array.from(map.values());
24557
24566
  }
24567
+ function getStructuralBucket(defType) {
24568
+ switch (defType) {
24569
+ case DefinitionType.Sequence:
24570
+ return "sequence";
24571
+ case DefinitionType.Mapping:
24572
+ return "mapping";
24573
+ default:
24574
+ return "scalar";
24575
+ }
24576
+ }
24577
+ function expandOneOfToCompletions(oneOfDef, definitions, key, description, indentation, mode) {
24578
+ const buckets = {
24579
+ scalar: false,
24580
+ sequence: false,
24581
+ mapping: false
24582
+ };
24583
+ let scalarIsOnlyNull = true;
24584
+ for (const variantKey of oneOfDef.oneOf) {
24585
+ const variantDef = definitions[variantKey];
24586
+ if (variantDef) {
24587
+ const bucket = getStructuralBucket(variantDef.definitionType);
24588
+ buckets[bucket] = true;
24589
+ if (bucket === "scalar" && !(variantDef instanceof NullDefinition)) {
24590
+ scalarIsOnlyNull = false;
24591
+ }
24592
+ }
24593
+ }
24594
+ const results = [];
24595
+ const bucketCount = [buckets.scalar, buckets.sequence, buckets.mapping].filter(Boolean).length;
24596
+ const needsQualifier = bucketCount > 1;
24597
+ const skipNullOnlyScalar = mode === DefinitionValueMode.Key && scalarIsOnlyNull;
24598
+ if (buckets.scalar && !skipNullOnlyScalar) {
24599
+ const insertText = mode === DefinitionValueMode.Key ? `
24600
+ ${indentation}${key}: ` : `${key}: `;
24601
+ results.push({
24602
+ label: key,
24603
+ description,
24604
+ insertText
24605
+ });
24606
+ }
24607
+ if (buckets.sequence) {
24608
+ const insertText = mode === DefinitionValueMode.Key ? `
24609
+ ${indentation}${key}:
24610
+ ${indentation}${indentation}- ` : `${key}:
24611
+ ${indentation}- `;
24612
+ results.push({
24613
+ label: needsQualifier ? `${key} (list)` : key,
24614
+ description,
24615
+ insertText,
24616
+ filterText: needsQualifier ? key : void 0,
24617
+ sortText: needsQualifier ? `${key} 1` : void 0
24618
+ });
24619
+ }
24620
+ if (buckets.mapping) {
24621
+ const insertText = mode === DefinitionValueMode.Key ? `
24622
+ ${indentation}${key}:
24623
+ ${indentation}${indentation}` : `${key}:
24624
+ ${indentation}`;
24625
+ results.push({
24626
+ label: needsQualifier ? `${key} (full syntax)` : key,
24627
+ description,
24628
+ insertText,
24629
+ filterText: needsQualifier ? key : void 0,
24630
+ sortText: needsQualifier ? `${key} 2` : void 0
24631
+ });
24632
+ }
24633
+ return results;
24634
+ }
24558
24635
 
24559
24636
  // ../languageservice/dist/complete.js
24560
24637
  function getExpressionInput(input, pos) {
@@ -24619,6 +24696,8 @@ async function complete2(textDocument, position, config) {
24619
24696
  const newText = value.insertText || value.label;
24620
24697
  const item = {
24621
24698
  label: value.label,
24699
+ filterText: value.filterText,
24700
+ sortText: value.sortText,
24622
24701
  documentation: value.description && {
24623
24702
  kind: "markdown",
24624
24703
  value: value.description
@@ -24651,9 +24730,35 @@ async function getValues(token, keyToken, parent, valueProviderConfig, workflowC
24651
24730
  if (!def) {
24652
24731
  return [];
24653
24732
  }
24654
- const values = definitionValues(def, indentation, keyToken ? DefinitionValueMode.Key : DefinitionValueMode.Parent);
24733
+ const tokenStructure = getTokenStructure(token);
24734
+ const values = definitionValues(def, indentation, keyToken ? DefinitionValueMode.Key : DefinitionValueMode.Parent, tokenStructure);
24655
24735
  return filterAndSortCompletionOptions(values, existingValues);
24656
24736
  }
24737
+ function getTokenStructure(token) {
24738
+ if (!token) {
24739
+ return void 0;
24740
+ }
24741
+ switch (token.templateTokenType) {
24742
+ case TokenType2.Mapping:
24743
+ return "mapping";
24744
+ case TokenType2.Sequence:
24745
+ return "sequence";
24746
+ case TokenType2.Null:
24747
+ return void 0;
24748
+ case TokenType2.String: {
24749
+ const stringToken = token.assertString("getTokenStructure expected string token");
24750
+ if (stringToken.value === "") {
24751
+ return void 0;
24752
+ }
24753
+ return "scalar";
24754
+ }
24755
+ case TokenType2.Boolean:
24756
+ case TokenType2.Number:
24757
+ return "scalar";
24758
+ default:
24759
+ return void 0;
24760
+ }
24761
+ }
24657
24762
  function getExistingValues(token, parent) {
24658
24763
  if (token) {
24659
24764
  if (!isString(token)) {
@@ -24702,7 +24807,7 @@ function getExpressionCompletionItems(token, context, pos) {
24702
24807
  }
24703
24808
  function filterAndSortCompletionOptions(options, existingValues) {
24704
24809
  options = options.filter((x) => !existingValues?.has(x.label));
24705
- options.sort((a, b) => a.label.localeCompare(b.label));
24810
+ options.sort((a, b) => (a.sortText ?? a.label).localeCompare(b.sortText ?? b.label));
24706
24811
  return options;
24707
24812
  }
24708
24813
  function mapExpressionCompletionItem(item, charAfterPos) {
@@ -25744,6 +25849,23 @@ function validateCronExpression(diagnostics, token) {
25744
25849
  });
25745
25850
  }
25746
25851
  }
25852
+ var SHORT_SHA_PATTERN = /^[0-9a-f]{7,8}$/i;
25853
+ var SHORT_SHA_DOCS_URL = "https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-third-party-actions";
25854
+ function warnIfShortSha(diagnostics, token, ref) {
25855
+ if (SHORT_SHA_PATTERN.test(ref)) {
25856
+ diagnostics.push({
25857
+ message: `The provided ref '${ref}' may be a shortened commit SHA. If so, please use the full 40-character commit SHA instead, as short SHAs are not supported.`,
25858
+ severity: import_vscode_languageserver_types3.DiagnosticSeverity.Warning,
25859
+ range: mapRange(token.range),
25860
+ code: "short-sha-ref",
25861
+ codeDescription: {
25862
+ href: SHORT_SHA_DOCS_URL
25863
+ }
25864
+ });
25865
+ return true;
25866
+ }
25867
+ return false;
25868
+ }
25747
25869
  function validateStepUsesFormat(diagnostics, token) {
25748
25870
  const uses = token.value;
25749
25871
  if (!uses) {
@@ -25785,6 +25907,7 @@ function validateStepUsesFormat(diagnostics, token) {
25785
25907
  });
25786
25908
  return;
25787
25909
  }
25910
+ warnIfShortSha(diagnostics, token, gitRef);
25788
25911
  }
25789
25912
  function addStepUsesFormatError(diagnostics, token) {
25790
25913
  diagnostics.push({
@@ -25873,6 +25996,7 @@ function validateWorkflowUsesFormat(diagnostics, token) {
25873
25996
  addWorkflowUsesFormatError(diagnostics, token, "invalid workflow file name");
25874
25997
  return;
25875
25998
  }
25999
+ warnIfShortSha(diagnostics, token, version);
25876
26000
  }
25877
26001
  function addWorkflowUsesFormatError(diagnostics, token, reason) {
25878
26002
  diagnostics.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actions/languageserver",
3
- "version": "0.3.26",
3
+ "version": "0.3.28",
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.26",
52
- "@actions/workflow-parser": "^0.3.26",
51
+ "@actions/languageservice": "^0.3.28",
52
+ "@actions/workflow-parser": "^0.3.28",
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": "c0062e5287fdb80b0856bc209e8dad064564bc70"
81
+ "gitHead": "a06ceee92b19cc7432ed25f63e8b4968b8ecb9ef"
82
82
  }