diff --git a/languageservice/src/complete.ts b/languageservice/src/complete.ts index 0a8301f..bfc4e16 100644 --- a/languageservice/src/complete.ts +++ b/languageservice/src/complete.ts @@ -28,7 +28,7 @@ import {transform} from "./utils/transform"; import {Value, ValueProviderConfig} from "./value-providers/config"; import {defaultValueProviders} from "./value-providers/default"; import {definitionValues} from "./value-providers/definition"; -import {getParsedWorkflow, getWorkflowTemplate} from "./utils/workflow-cache"; +import {fetchOrParseWorkflow, fetchOrConvertWorkflowTemplate} from "./utils/workflow-cache"; export function getExpressionInput(input: string, pos: number): string { // Find start marker around the cursor position @@ -69,12 +69,12 @@ export async function complete( content: newDoc.getText() }; - const parsedWorkflow = getParsedWorkflow(file, textDocument.uri); + const parsedWorkflow = fetchOrParseWorkflow(file, textDocument.uri); if (!parsedWorkflow) { return []; } - const template = await getWorkflowTemplate(file, parsedWorkflow, textDocument.uri, config, { + const template = await fetchOrConvertWorkflowTemplate(file, parsedWorkflow, textDocument.uri, config, { fetchReusableWorkflowDepth: config?.fileProvider ? 1 : 0, errorPolicy: ErrorPolicy.TryConversion }); diff --git a/languageservice/src/document-links.ts b/languageservice/src/document-links.ts index 8cbe2a2..bd14ce1 100644 --- a/languageservice/src/document-links.ts +++ b/languageservice/src/document-links.ts @@ -5,7 +5,7 @@ import {TextDocument} from "vscode-languageserver-textdocument"; import {DocumentLink} from "vscode-languageserver-types"; import {parseActionReference} from "./action"; import {mapRange} from "./utils/range"; -import {getParsedWorkflow, getWorkflowTemplate} from "./utils/workflow-cache"; +import {fetchOrParseWorkflow, fetchOrConvertWorkflowTemplate} from "./utils/workflow-cache"; export async function documentLinks(document: TextDocument): Promise { const file: File = { @@ -13,12 +13,12 @@ export async function documentLinks(document: TextDocument): Promise(); const workflowTemplateCache = new Map(); -export function cacheParsedWorkflow(uri: string, parsedWorkflowResult: ParseWorkflowResult) { - parsedWorkflowCache.set(uri, parsedWorkflowResult); -} - -export function getParsedWorkflowCacheEntry(uri: string): ParseWorkflowResult | undefined { - return parsedWorkflowCache.get(uri); -} - export function clearParsedCacheEntry(uri: string) { parsedWorkflowCache.delete(uri); } @@ -25,14 +17,6 @@ export function clearParsedCache() { parsedWorkflowCache.clear(); } -export function cacheWorkflowTemplate(uri: string, workflowTemplate: WorkflowTemplate) { - workflowTemplateCache.set(uri, workflowTemplate); -} - -export function getWorkflowTemplateCacheEntry(uri: string): WorkflowTemplate | undefined { - return workflowTemplateCache.get(uri); -} - export function clearWorkflowTemplateCacheEntry(uri: string) { workflowTemplateCache.delete(uri); } @@ -41,23 +25,23 @@ export function clearWorkflowTemplateCache() { workflowTemplateCache.clear(); } -export function getParsedWorkflow(file: File, uri: string): ParseWorkflowResult | undefined { - let result = getParsedWorkflowCacheEntry(uri); +export function fetchOrParseWorkflow(file: File, uri: string): ParseWorkflowResult | undefined { + let result = parsedWorkflowCache.get(uri); if (!result || !result.value) { result = parseWorkflow(file, nullTrace); if (!result.value) { return undefined; } - cacheParsedWorkflow(uri, result) + parsedWorkflowCache.set(uri, result); } return result; } -export async function getWorkflowTemplate(file: File, parsedWorkflow: ParseWorkflowResult, uri: string, config?: CompletionConfig, options?: WorkflowTemplateConverterOptions): Promise { - let template = getWorkflowTemplateCacheEntry(uri); +export async function fetchOrConvertWorkflowTemplate(file: File, parsedWorkflow: ParseWorkflowResult, uri: string, config?: CompletionConfig, options?: WorkflowTemplateConverterOptions): Promise { + let template = workflowTemplateCache.get(uri); if (!template) { template = await convertWorkflowTemplate(file.name, parsedWorkflow.context, parsedWorkflow.value!, config?.fileProvider, options); - cacheWorkflowTemplate(uri, template); + workflowTemplateCache.set(uri, template); } return template; } \ No newline at end of file diff --git a/languageservice/src/validate.ts b/languageservice/src/validate.ts index e785a4d..10441c6 100644 --- a/languageservice/src/validate.ts +++ b/languageservice/src/validate.ts @@ -26,7 +26,7 @@ import {mapRange} from "./utils/range"; import {validateAction} from "./validate-action"; import {ValueProviderConfig, ValueProviderKind} from "./value-providers/config"; import {defaultValueProviders} from "./value-providers/default"; -import { getParsedWorkflow, getWorkflowTemplate } from "./utils/workflow-cache"; +import {fetchOrParseWorkflow, fetchOrConvertWorkflowTemplate} from "./utils/workflow-cache"; export type ValidationConfig = { valueProviderConfig?: ValueProviderConfig; @@ -50,14 +50,14 @@ export async function validate(textDocument: TextDocument, config?: ValidationCo const diagnostics: Diagnostic[] = []; try { - const parsedWorkflow = getParsedWorkflow(file, textDocument.uri); + const parsedWorkflow = fetchOrParseWorkflow(file, textDocument.uri); if (!parsedWorkflow) { return []; } if (parsedWorkflow.value) { // Errors will be updated in the context. Attempt to do the conversion anyway in order to give the user more information - const template = await getWorkflowTemplate(file, parsedWorkflow, textDocument.uri, config, { + const template = await fetchOrConvertWorkflowTemplate(file, parsedWorkflow, textDocument.uri, config, { fetchReusableWorkflowDepth: config?.fileProvider ? 1 : 0, errorPolicy: ErrorPolicy.TryConversion });