Combine methods
This commit is contained in:
@@ -28,12 +28,7 @@ import {fetchActionMetadata} from "./utils/action-metadata";
|
|||||||
import {TTLCache} from "./utils/cache";
|
import {TTLCache} from "./utils/cache";
|
||||||
import {timeOperation} from "./utils/timer";
|
import {timeOperation} from "./utils/timer";
|
||||||
import {valueProviders} from "./value-providers";
|
import {valueProviders} from "./value-providers";
|
||||||
import {
|
import {clearCacheEntry, clearCache} from "@github/actions-languageservice/utils/workflow-cache";
|
||||||
clearParsedCache,
|
|
||||||
clearParsedCacheEntry,
|
|
||||||
clearWorkflowTemplateCache,
|
|
||||||
clearWorkflowTemplateCacheEntry
|
|
||||||
} from "@github/actions-languageservice/utils/workflow-cache";
|
|
||||||
|
|
||||||
export function initConnection(connection: Connection) {
|
export function initConnection(connection: Connection) {
|
||||||
const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
|
const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
|
||||||
@@ -100,8 +95,7 @@ export function initConnection(connection: Connection) {
|
|||||||
connection.onInitialized(() => {
|
connection.onInitialized(() => {
|
||||||
if (hasWorkspaceFolderCapability) {
|
if (hasWorkspaceFolderCapability) {
|
||||||
connection.workspace.onDidChangeWorkspaceFolders(_event => {
|
connection.workspace.onDidChangeWorkspaceFolders(_event => {
|
||||||
clearParsedCache();
|
clearCache();
|
||||||
clearWorkflowTemplateCache();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -109,8 +103,7 @@ export function initConnection(connection: Connection) {
|
|||||||
// The content of a text document has changed. This event is emitted
|
// The content of a text document has changed. This event is emitted
|
||||||
// when the text document first opened or when its content has changed.
|
// when the text document first opened or when its content has changed.
|
||||||
documents.onDidChangeContent(change => {
|
documents.onDidChangeContent(change => {
|
||||||
clearParsedCacheEntry(change.document.uri);
|
clearCacheEntry(change.document.uri);
|
||||||
clearWorkflowTemplateCacheEntry(change.document.uri);
|
|
||||||
return timeOperation("validation", async () => await validateTextDocument(change.document));
|
return timeOperation("validation", async () => await validateTextDocument(change.document));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import {registerLogger} from "./log";
|
|||||||
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
||||||
import {TestLogger} from "./test-utils/logger";
|
import {TestLogger} from "./test-utils/logger";
|
||||||
import {testFileProvider} from "./test-utils/test-file-provider";
|
import {testFileProvider} from "./test-utils/test-file-provider";
|
||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "./utils/workflow-cache";
|
import {clearCache} from "./utils/workflow-cache";
|
||||||
|
|
||||||
const contextProviderConfig: ContextProviderConfig = {
|
const contextProviderConfig: ContextProviderConfig = {
|
||||||
getContext: async (context: string) => {
|
getContext: async (context: string) => {
|
||||||
@@ -26,8 +26,7 @@ const contextProviderConfig: ContextProviderConfig = {
|
|||||||
registerLogger(new TestLogger());
|
registerLogger(new TestLogger());
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("expressions", () => {
|
describe("expressions", () => {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import {CompletionItem, MarkupContent} from "vscode-languageserver-types";
|
|||||||
import {complete} from "./complete";
|
import {complete} from "./complete";
|
||||||
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
||||||
import {testFileProvider} from "./test-utils/test-file-provider";
|
import {testFileProvider} from "./test-utils/test-file-provider";
|
||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "./utils/workflow-cache";
|
import {clearCache} from "./utils/workflow-cache";
|
||||||
|
|
||||||
function mapResult(result: CompletionItem[]) {
|
function mapResult(result: CompletionItem[]) {
|
||||||
return result.map(x => {
|
return result.map(x => {
|
||||||
@@ -11,8 +11,7 @@ function mapResult(result: CompletionItem[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("completion with reusable workflows", () => {
|
describe("completion with reusable workflows", () => {
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ import {registerLogger} from "./log";
|
|||||||
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
||||||
import {TestLogger} from "./test-utils/logger";
|
import {TestLogger} from "./test-utils/logger";
|
||||||
import {ValueProviderConfig, ValueProviderKind} from "./value-providers/config";
|
import {ValueProviderConfig, ValueProviderKind} from "./value-providers/config";
|
||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "./utils/workflow-cache";
|
import {clearCache} from "./utils/workflow-cache";
|
||||||
|
|
||||||
registerLogger(new TestLogger());
|
registerLogger(new TestLogger());
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("completion", () => {
|
describe("completion", () => {
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import {documentLinks} from "./document-links";
|
import {documentLinks} from "./document-links";
|
||||||
import {createDocument} from "./test-utils/document";
|
import {createDocument} from "./test-utils/document";
|
||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "./utils/workflow-cache";
|
import {clearCache} from "./utils/workflow-cache";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("documentLinks", () => {
|
describe("documentLinks", () => {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {hover} from "./hover";
|
|||||||
import {registerLogger} from "./log";
|
import {registerLogger} from "./log";
|
||||||
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
||||||
import {TestLogger} from "./test-utils/logger";
|
import {TestLogger} from "./test-utils/logger";
|
||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "./utils/workflow-cache";
|
import {clearCache} from "./utils/workflow-cache";
|
||||||
|
|
||||||
const contextProviderConfig: ContextProviderConfig = {
|
const contextProviderConfig: ContextProviderConfig = {
|
||||||
getContext: async (context: string) => {
|
getContext: async (context: string) => {
|
||||||
@@ -36,8 +36,7 @@ const contextProviderConfig: ContextProviderConfig = {
|
|||||||
registerLogger(new TestLogger());
|
registerLogger(new TestLogger());
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("hover.expressions", () => {
|
describe("hover.expressions", () => {
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import {hover} from "./hover";
|
import {hover} from "./hover";
|
||||||
import {testHoverConfig} from "./hover.test";
|
import {testHoverConfig} from "./hover.test";
|
||||||
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "./utils/workflow-cache";
|
import {clearCache} from "./utils/workflow-cache";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("hover.reusable-workflow", () => {
|
describe("hover.reusable-workflow", () => {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import {StringToken} from "@github/actions-workflow-parser/templates/tokens/stri
|
|||||||
import {DescriptionProvider, hover, HoverConfig} from "./hover";
|
import {DescriptionProvider, hover, HoverConfig} from "./hover";
|
||||||
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
import {getPositionFromCursor} from "./test-utils/cursor-position";
|
||||||
import {testFileProvider} from "./test-utils/test-file-provider";
|
import {testFileProvider} from "./test-utils/test-file-provider";
|
||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "./utils/workflow-cache";
|
import {clearCache} from "./utils/workflow-cache";
|
||||||
|
|
||||||
export function testHoverConfig(tokenValue: string, tokenKey: string, description?: string) {
|
export function testHoverConfig(tokenValue: string, tokenKey: string, description?: string) {
|
||||||
return {
|
return {
|
||||||
@@ -24,8 +24,7 @@ export function testHoverConfig(tokenValue: string, tokenKey: string, descriptio
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("hover", () => {
|
describe("hover", () => {
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "../utils/workflow-cache";
|
import {clearCache} from "../utils/workflow-cache";
|
||||||
import {getPositionFromCursor} from "./cursor-position";
|
import {getPositionFromCursor} from "./cursor-position";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getPositionFromCursor", () => {
|
describe("getPositionFromCursor", () => {
|
||||||
|
|||||||
@@ -9,19 +9,13 @@ import {CompletionConfig} from "../complete";
|
|||||||
const parsedWorkflowCache = new Map<string, ParseWorkflowResult>();
|
const parsedWorkflowCache = new Map<string, ParseWorkflowResult>();
|
||||||
const workflowTemplateCache = new Map<string, WorkflowTemplate>();
|
const workflowTemplateCache = new Map<string, WorkflowTemplate>();
|
||||||
|
|
||||||
export function clearParsedCacheEntry(uri: string) {
|
export function clearCacheEntry(uri: string) {
|
||||||
parsedWorkflowCache.delete(uri);
|
parsedWorkflowCache.delete(uri);
|
||||||
}
|
|
||||||
|
|
||||||
export function clearParsedCache() {
|
|
||||||
parsedWorkflowCache.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
export function clearWorkflowTemplateCacheEntry(uri: string) {
|
|
||||||
workflowTemplateCache.delete(uri);
|
workflowTemplateCache.delete(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearWorkflowTemplateCache() {
|
export function clearCache() {
|
||||||
|
parsedWorkflowCache.clear();
|
||||||
workflowTemplateCache.clear();
|
workflowTemplateCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ import {createDocument} from "./test-utils/document";
|
|||||||
import {TestLogger} from "./test-utils/logger";
|
import {TestLogger} from "./test-utils/logger";
|
||||||
import {validate, ValidationConfig} from "./validate";
|
import {validate, ValidationConfig} from "./validate";
|
||||||
import {ValueProviderKind} from "./value-providers/config";
|
import {ValueProviderKind} from "./value-providers/config";
|
||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "./utils/workflow-cache";
|
import {clearCache} from "./utils/workflow-cache";
|
||||||
|
|
||||||
registerLogger(new TestLogger());
|
registerLogger(new TestLogger());
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const validationConfig: ValidationConfig = {
|
const validationConfig: ValidationConfig = {
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ import {registerLogger} from "./log";
|
|||||||
import {createDocument} from "./test-utils/document";
|
import {createDocument} from "./test-utils/document";
|
||||||
import {TestLogger} from "./test-utils/logger";
|
import {TestLogger} from "./test-utils/logger";
|
||||||
import {validate, ValidationConfig} from "./validate";
|
import {validate, ValidationConfig} from "./validate";
|
||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "./utils/workflow-cache";
|
import {clearCache} from "./utils/workflow-cache";
|
||||||
|
|
||||||
registerLogger(new TestLogger());
|
registerLogger(new TestLogger());
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("expression validation", () => {
|
describe("expression validation", () => {
|
||||||
|
|||||||
@@ -2,11 +2,10 @@ import {Diagnostic, DiagnosticSeverity} from "vscode-languageserver-types";
|
|||||||
import {createDocument} from "./test-utils/document";
|
import {createDocument} from "./test-utils/document";
|
||||||
import {validate} from "./validate";
|
import {validate} from "./validate";
|
||||||
import {defaultValueProviders} from "./value-providers/default";
|
import {defaultValueProviders} from "./value-providers/default";
|
||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "./utils/workflow-cache";
|
import {clearCache} from "./utils/workflow-cache";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("validation", () => {
|
describe("validation", () => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import {Evaluator, ExpressionEvaluationError, Lexer, Parser} from "@github/actions-expressions";
|
import {Evaluator, ExpressionEvaluationError, Lexer, Parser} from "@github/actions-expressions";
|
||||||
import {Expr} from "@github/actions-expressions/ast";
|
import {Expr} from "@github/actions-expressions/ast";
|
||||||
import {isBasicExpression, isString, WorkflowTemplate} from "@github/actions-workflow-parser";
|
import {isBasicExpression, isString, ParseWorkflowResult, WorkflowTemplate} from "@github/actions-workflow-parser";
|
||||||
import {ErrorPolicy} from "@github/actions-workflow-parser/model/convert";
|
import {ErrorPolicy} from "@github/actions-workflow-parser/model/convert";
|
||||||
import {splitAllowedContext} from "@github/actions-workflow-parser/templates/allowed-context";
|
import {splitAllowedContext} from "@github/actions-workflow-parser/templates/allowed-context";
|
||||||
import {BasicExpressionToken} from "@github/actions-workflow-parser/templates/tokens/basic-expression-token";
|
import {BasicExpressionToken} from "@github/actions-workflow-parser/templates/tokens/basic-expression-token";
|
||||||
@@ -46,24 +46,24 @@ export async function validate(textDocument: TextDocument, config?: ValidationCo
|
|||||||
const diagnostics: Diagnostic[] = [];
|
const diagnostics: Diagnostic[] = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const parsedWorkflow = fetchOrParseWorkflow(file, textDocument.uri);
|
const result: ParseWorkflowResult | undefined = fetchOrParseWorkflow(file, textDocument.uri);
|
||||||
if (!parsedWorkflow) {
|
if (!result) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedWorkflow.value) {
|
if (result.value) {
|
||||||
// Errors will be updated in the context. Attempt to do the conversion anyway in order to give the user more information
|
// Errors will be updated in the context. Attempt to do the conversion anyway in order to give the user more information
|
||||||
const template = await fetchOrConvertWorkflowTemplate(parsedWorkflow, textDocument.uri, config, {
|
const template = await fetchOrConvertWorkflowTemplate(result, textDocument.uri, config, {
|
||||||
fetchReusableWorkflowDepth: config?.fileProvider ? 1 : 0,
|
fetchReusableWorkflowDepth: config?.fileProvider ? 1 : 0,
|
||||||
errorPolicy: ErrorPolicy.TryConversion
|
errorPolicy: ErrorPolicy.TryConversion
|
||||||
});
|
});
|
||||||
|
|
||||||
// Validate expressions and value providers
|
// Validate expressions and value providers
|
||||||
await additionalValidations(diagnostics, textDocument.uri, template, parsedWorkflow.value, config);
|
await additionalValidations(diagnostics, textDocument.uri, template, result.value, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// For now map parser errors directly to diagnostics
|
// For now map parser errors directly to diagnostics
|
||||||
for (const error of parsedWorkflow.context.errors.getErrors()) {
|
for (const error of result.context.errors.getErrors()) {
|
||||||
let range = mapRange(error.range);
|
let range = mapRange(error.range);
|
||||||
|
|
||||||
diagnostics.push({
|
diagnostics.push({
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import {createDocument} from "./test-utils/document";
|
import {createDocument} from "./test-utils/document";
|
||||||
import {testFileProvider} from "./test-utils/test-file-provider";
|
import {testFileProvider} from "./test-utils/test-file-provider";
|
||||||
import {clearParsedCache, clearWorkflowTemplateCache} from "./utils/workflow-cache";
|
import {clearCache} from "./utils/workflow-cache";
|
||||||
import {validate} from "./validate";
|
import {validate} from "./validate";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
clearWorkflowTemplateCache();
|
clearCache();
|
||||||
clearParsedCache();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("workflow references validation", () => {
|
describe("workflow references validation", () => {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import {File} from "./file";
|
|||||||
import {WORKFLOW_ROOT} from "./workflow-constants";
|
import {WORKFLOW_ROOT} from "./workflow-constants";
|
||||||
import {getWorkflowSchema} from "./workflow-schema";
|
import {getWorkflowSchema} from "./workflow-schema";
|
||||||
import {YamlObjectReader} from "./yaml-object-reader";
|
import {YamlObjectReader} from "./yaml-object-reader";
|
||||||
|
|
||||||
export interface ParseWorkflowResult {
|
export interface ParseWorkflowResult {
|
||||||
context: TemplateContext;
|
context: TemplateContext;
|
||||||
value: TemplateToken | undefined;
|
value: TemplateToken | undefined;
|
||||||
@@ -27,17 +26,15 @@ export function parseWorkflow(entryFile: File, contextOrTrace: TraceWriter | Tem
|
|||||||
for (const err of reader.errors) {
|
for (const err of reader.errors) {
|
||||||
context.error(fileId, err.message, err.range);
|
context.error(fileId, err.message, err.range);
|
||||||
}
|
}
|
||||||
const result = {
|
return {
|
||||||
context,
|
context,
|
||||||
value: undefined
|
value: undefined
|
||||||
};
|
};
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
const templateToken = templateReader.readTemplate(context, WORKFLOW_ROOT, reader, fileId);
|
const result = templateReader.readTemplate(context, WORKFLOW_ROOT, reader, fileId);
|
||||||
|
|
||||||
const result = {
|
return <ParseWorkflowResult>{
|
||||||
context,
|
context,
|
||||||
value: templateToken
|
value: result
|
||||||
} satisfies ParseWorkflowResult;
|
};
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user