Merge branch 'main' into joshmgross/improve-expression-completion

This commit is contained in:
Josh Gross
2022-12-15 10:34:13 -05:00
9 changed files with 65 additions and 51 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "@github/actions-languageserver",
"version": "0.1.55",
"version": "0.1.57",
"description": "Language server for GitHub Actions",
"license": "MIT",
"type": "module",
@@ -38,7 +38,7 @@
"prettier-fix": "prettier --write ."
},
"dependencies": {
"@github/actions-languageservice": "^0.1.55",
"@github/actions-languageservice": "^0.1.57",
"@github/actions-workflow-parser": "*",
"@octokit/rest": "^19.0.5",
"vscode-languageserver": "^8.0.2",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@github/actions-languageservice",
"version": "0.1.55",
"version": "0.1.57",
"description": "Language service for GitHub Actions",
"license": "MIT",
"type": "module",
@@ -31,6 +31,10 @@ describe("expressions", () => {
expect(test("${{ gh |")).toBe(" gh ");
expect(test("${{ gh |}}")).toBe(" gh ");
expect(test("${{ vars| == 'test' }}")).toBe(" vars");
expect(test("${{ fromJso|('test').bar == 'test' }}")).toBe(" fromJso");
expect(test("${{ github.| == 'test' }}")).toBe(" github.");
expect(test("test ${{ github.| == 'test' }}")).toBe(" github.");
expect(test("${{ vars }} ${{ gh |}}")).toBe(" gh ");
});
@@ -71,6 +75,42 @@ describe("expressions", () => {
]);
});
it("single region with existing condition", async () => {
const input = "run-name: ${{ g| == 'test' }}";
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
expect(result.map(x => x.label)).toEqual([
"github",
"inputs",
"vars",
"contains",
"endsWith",
"format",
"fromJson",
"join",
"startsWith",
"toJson"
]);
});
it("multiple regions with partial function", async () => {
const input = "run-name: Run a ${{ inputs.test }} one-line script ${{ from|('test') == inputs.name }}";
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
expect(result.map(x => x.label)).toEqual([
"github",
"inputs",
"vars",
"contains",
"endsWith",
"format",
"fromJson",
"join",
"startsWith",
"toJson"
]);
});
it("multiple regions", async () => {
const input = "run-name: test-${{ github }}-${{ | }}";
const result = await complete(...getPositionFromCursor(input), undefined, contextProviderConfig);
+5 -13
View File
@@ -3,7 +3,7 @@ import {convertWorkflowTemplate, isSequence, isString, parseWorkflow} from "@git
import {ErrorPolicy} from "@github/actions-workflow-parser/model/convert";
import {DefinitionType} from "@github/actions-workflow-parser/templates/schema/definition-type";
import {StringDefinition} from "@github/actions-workflow-parser/templates/schema/string-definition";
import {CLOSE_EXPRESSION, OPEN_EXPRESSION} from "@github/actions-workflow-parser/templates/template-constants";
import {OPEN_EXPRESSION} from "@github/actions-workflow-parser/templates/template-constants";
import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/index";
import {MappingToken} from "@github/actions-workflow-parser/templates/tokens/mapping-token";
import {TokenType} from "@github/actions-workflow-parser/templates/tokens/types";
@@ -14,7 +14,6 @@ import {ContextProviderConfig} from "./context-providers/config";
import {getContext, Mode} from "./context-providers/default";
import {getWorkflowContext, WorkflowContext} from "./context/workflow-context";
import {nullTrace} from "./nulltrace";
import {getAllowedContext} from "./utils/allowed-context";
import {findToken} from "./utils/find-token";
import {mapRange} from "./utils/range";
import {transform} from "./utils/transform";
@@ -29,14 +28,7 @@ export function getExpressionInput(input: string, pos: number): string {
return input;
}
// Find end marker after the cursor position
let endPos = input.indexOf(CLOSE_EXPRESSION, pos);
if (endPos === -1) {
// Assume an unfinished expression like "${{ someinput.|"
endPos = input.length;
}
return input.substring(startPos + OPEN_EXPRESSION.length, endPos);
return input.substring(startPos + OPEN_EXPRESSION.length, pos);
}
export async function complete(
@@ -85,14 +77,14 @@ export async function complete(
if (token.range!.start[0] !== token.range!.end[0]) {
const lines = currentInput.split("\n");
const linesBeforeCusor = lines.slice(0, lineDiff);
relCharPos = linesBeforeCusor.join("\n").length + newPos.character;
relCharPos = linesBeforeCusor.join("\n").length + 1 + newPos.character;
} else {
relCharPos = newPos.character - token.range!.start[1];
relCharPos = newPos.character - token.range!.start[1] + 1;
}
const expressionInput = (getExpressionInput(currentInput, relCharPos) || "").trim();
const allowedContext = getAllowedContext(token, parent);
const allowedContext = token.definitionInfo?.allowedContext || [];
const context = await getContext(allowedContext, contextProviderConfig, workflowContext, Mode.Completion);
return completeExpression(expressionInput, context, []).map(item => {
@@ -1,15 +0,0 @@
import {TemplateToken} from "@github/actions-workflow-parser/templates/tokens/template-token";
export function getAllowedContext(token: TemplateToken, parent: TemplateToken | null | undefined): string[] {
// Workaround for https://github.com/github/c2c-actions-experience/issues/6876
// Context is inherited from the parent
const allowedContext = new Set<string>();
for (const t of [token, parent]) {
if (t?.definition?.readerContext) {
for (const context of t.definition.readerContext) {
allowedContext.add(context);
}
}
}
return Array.from(allowedContext);
}
+1 -4
View File
@@ -24,7 +24,6 @@ import {getWorkflowContext, WorkflowContext} from "./context/workflow-context";
import {AccessError, wrapDictionary} from "./expression-validation/error-dictionary";
import {error} from "./log";
import {nullTrace} from "./nulltrace";
import {getAllowedContext} from "./utils/allowed-context";
import {findToken} from "./utils/find-token";
import {mapRange} from "./utils/range";
import {validateAction} from "./validate-action";
@@ -94,14 +93,12 @@ async function additionalValidations(
const validationToken = key || parent || token;
const validationDefinition = validationToken.definition;
const allowedContext = getAllowedContext(validationToken, parent);
// If this is an expression, validate it
if (isBasicExpression(token)) {
await validateExpression(
diagnostics,
token,
allowedContext,
validationToken.definitionInfo?.allowedContext || [],
config?.contextProviderConfig,
getProviderContext(documentUri, template, root, token)
);
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "browser-playground",
"version": "0.1.55",
"version": "0.1.57",
"description": "",
"private": true,
"main": "index.js",
"type": "module",
"dependencies": {
"@github/actions-languageserver": "^0.1.55",
"@github/actions-languageserver": "^0.1.57",
"monaco-editor-webpack-plugin": "^7.0.1",
"monaco-editor-workers": "^0.34.2",
"monaco-languageclient": "^4.0.3",
+1 -1
View File
@@ -1,5 +1,5 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"version": "0.1.55"
"version": "0.1.57"
}
+13 -13
View File
@@ -16,10 +16,10 @@
},
"actions-languageserver": {
"name": "@github/actions-languageserver",
"version": "0.1.55",
"version": "0.1.57",
"license": "MIT",
"dependencies": {
"@github/actions-languageservice": "^0.1.55",
"@github/actions-languageservice": "^0.1.57",
"@github/actions-workflow-parser": "*",
"@octokit/rest": "^19.0.5",
"vscode-languageserver": "^8.0.2",
@@ -40,7 +40,7 @@
},
"actions-languageservice": {
"name": "@github/actions-languageservice",
"version": "0.1.55",
"version": "0.1.57",
"license": "MIT",
"dependencies": {
"@github/actions-expressions": "*",
@@ -62,10 +62,10 @@
}
},
"browser-playground": {
"version": "0.1.55",
"version": "0.1.57",
"license": "MIT",
"dependencies": {
"@github/actions-languageserver": "^0.1.55",
"@github/actions-languageserver": "^0.1.57",
"monaco-editor-webpack-plugin": "^7.0.1",
"monaco-editor-workers": "^0.34.2",
"monaco-languageclient": "^4.0.3",
@@ -701,9 +701,9 @@
"link": true
},
"node_modules/@github/actions-workflow-parser": {
"version": "0.0.34",
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.34/e369bdaca17cde594ad7420cd0df0efcd2804dc0",
"integrity": "sha512-ttjYUoO2bvi5v/SR267QpDhWJ+I4tXQlSMnscjqUp76IDLxS73I7nCD3KP7g4VxzHmT5j8AxSdjEE25UWpl43g==",
"version": "0.0.35",
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.35/0e88d541486f7c8772c5640fc13fac630cfaeaa8",
"integrity": "sha512-OuNEuqUH4AOfWd2xb8VRl7KwJrtiZu1ic0b27lmadwvK8qgRhPHxvS+QICEc+JtFbbVWpAA2ymh8I1U35639mA==",
"license": "MIT",
"dependencies": {
"@github/actions-expressions": "*",
@@ -13508,7 +13508,7 @@
"@github/actions-languageserver": {
"version": "file:actions-languageserver",
"requires": {
"@github/actions-languageservice": "^0.1.55",
"@github/actions-languageservice": "^0.1.57",
"@github/actions-workflow-parser": "*",
"@octokit/rest": "^19.0.5",
"@types/jest": "^29.0.3",
@@ -13539,9 +13539,9 @@
}
},
"@github/actions-workflow-parser": {
"version": "0.0.34",
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.34/e369bdaca17cde594ad7420cd0df0efcd2804dc0",
"integrity": "sha512-ttjYUoO2bvi5v/SR267QpDhWJ+I4tXQlSMnscjqUp76IDLxS73I7nCD3KP7g4VxzHmT5j8AxSdjEE25UWpl43g==",
"version": "0.0.35",
"resolved": "https://npm.pkg.github.com/download/@github/actions-workflow-parser/0.0.35/0e88d541486f7c8772c5640fc13fac630cfaeaa8",
"integrity": "sha512-OuNEuqUH4AOfWd2xb8VRl7KwJrtiZu1ic0b27lmadwvK8qgRhPHxvS+QICEc+JtFbbVWpAA2ymh8I1U35639mA==",
"requires": {
"@github/actions-expressions": "*",
"yaml": "^2.0.0-8"
@@ -16294,7 +16294,7 @@
"browser-playground": {
"version": "file:browser-playground",
"requires": {
"@github/actions-languageserver": "^0.1.55",
"@github/actions-languageserver": "^0.1.57",
"css-loader": "^6.7.2",
"monaco-editor-webpack-plugin": "^7.0.1",
"monaco-editor-workers": "^0.34.2",