From d7c19f529d711d052076ce746a47d26504d81bfa Mon Sep 17 00:00:00 2001 From: Jacob Wallraff Date: Fri, 3 Mar 2023 10:32:56 -0800 Subject: [PATCH] Clear whole cache on workspace change --- languageserver/src/connection.ts | 8 ++++---- workflow-parser/src/model/convert.ts | 12 ++++++++---- workflow-parser/src/workflows/workflow-parser.ts | 4 ++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/languageserver/src/connection.ts b/languageserver/src/connection.ts index c527fe5..6b57d43 100644 --- a/languageserver/src/connection.ts +++ b/languageserver/src/connection.ts @@ -28,8 +28,8 @@ import {fetchActionMetadata} from "./utils/action-metadata"; import {TTLCache} from "./utils/cache"; import {timeOperation} from "./utils/timer"; import {valueProviders} from "./value-providers"; -import {clearParsedCacheEntry} from "@github/actions-workflow-parser/workflows/workflow-parser"; -import {clearWorkflowTemplateCacheEntry} from "@github/actions-workflow-parser/model/convert"; +import {clearParsedCache, clearParsedCacheEntry} from "@github/actions-workflow-parser/workflows/workflow-parser"; +import {clearWorkflowTemplateCache, clearWorkflowTemplateCacheEntry} from "@github/actions-workflow-parser/model/convert"; export function initConnection(connection: Connection) { const documents: TextDocuments = new TextDocuments(TextDocument); @@ -96,8 +96,8 @@ export function initConnection(connection: Connection) { connection.onInitialized(() => { if (hasWorkspaceFolderCapability) { connection.workspace.onDidChangeWorkspaceFolders(_event => { - // Invalidate caches? Not sure what to do here, but we should track - connection.console.log('Workspace folder change event received.'); + clearParsedCache(); + clearWorkflowTemplateCache(); }); } }) diff --git a/workflow-parser/src/model/convert.ts b/workflow-parser/src/model/convert.ts index e244174..109d5d2 100644 --- a/workflow-parser/src/model/convert.ts +++ b/workflow-parser/src/model/convert.ts @@ -48,13 +48,13 @@ const defaultOptions: Required = { }; export async function convertWorkflowTemplate( - fileName: string, + uri: string, context: TemplateContext, root: TemplateToken, fileProvider?: FileProvider, options: WorkflowTemplateConverterOptions = defaultOptions ): Promise { - const cachedResult = workflowTemplateCache.get(fileName) + const cachedResult = workflowTemplateCache.get(uri) if (cachedResult) { return cachedResult; } @@ -66,7 +66,7 @@ export async function convertWorkflowTemplate( result.errors = context.errors.getErrors().map(x => ({ Message: x.message })); - workflowTemplateCache.set(fileName, result); + workflowTemplateCache.set(uri, result); return result; } @@ -138,7 +138,7 @@ export async function convertWorkflowTemplate( } } - workflowTemplateCache.set(fileName, result); + workflowTemplateCache.set(uri, result); return result; } @@ -158,4 +158,8 @@ function getOptionsWithDefaults(options: WorkflowTemplateConverterOptions): Requ export function clearWorkflowTemplateCacheEntry(uri: string) { workflowTemplateCache.delete(uri); +} + +export function clearWorkflowTemplateCache() { + workflowTemplateCache.clear(); } \ No newline at end of file diff --git a/workflow-parser/src/workflows/workflow-parser.ts b/workflow-parser/src/workflows/workflow-parser.ts index aca8b72..978f12d 100644 --- a/workflow-parser/src/workflows/workflow-parser.ts +++ b/workflow-parser/src/workflows/workflow-parser.ts @@ -54,3 +54,7 @@ export function parseWorkflow(entryFile: File, contextOrTrace: TraceWriter | Tem export function clearParsedCacheEntry(path: string) { parsedWorkflowCache.delete(path); } + +export function clearParsedCache() { + parsedWorkflowCache.clear(); +}