diff --git a/core/autocomplete/util/openedFilesLruCache.ts b/core/autocomplete/util/openedFilesLruCache.ts new file mode 100644 index 000000000..4e7ea9b2c --- /dev/null +++ b/core/autocomplete/util/openedFilesLruCache.ts @@ -0,0 +1,14 @@ +import QuickLRU from "quick-lru"; + +// The cache key and value are both a filepath string +type cacheElementType = string; + +// maximum number of open files that can be cached +const MAX_NUM_OPEN_CONTEXT_FILES = 10; + +export const openedFilesLruCache = new QuickLRU< + cacheElementType, + cacheElementType +>({ + maxSize: MAX_NUM_OPEN_CONTEXT_FILES, +}); diff --git a/core/core.ts b/core/core.ts index 2c13fd6a7..cd1fb4f99 100644 --- a/core/core.ts +++ b/core/core.ts @@ -3,6 +3,7 @@ import * as URI from "uri-js"; import { v4 as uuidv4 } from "uuid"; import { CompletionProvider } from "./autocomplete/CompletionProvider"; +import { openedFilesLruCache } from "./autocomplete/util/openedFilesLruCache"; import { ConfigHandler } from "./config/ConfigHandler"; import { SYSTEM_PROMPT_DOT_FILE } from "./config/getWorkspaceContinueRuleDotFiles"; import { addModel, deleteModel } from "./config/util"; @@ -692,7 +693,10 @@ export class Core { try { const ignore = await shouldIgnore(filepath, this.ide); if (!ignore) { + // Update the recently edited files cache recentlyEditedFilesCache.set(filepath, filepath); + // Update the cache for opened files as well + openedFilesLruCache.set(filepath, filepath); } } catch (e) { console.error( diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 78fa03df8..e516f171e 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -199,7 +199,8 @@ "onnxruntime-common": "1.14.0", "onnxruntime-web": "1.14.0", "ts-jest": "^29.1.1", - "typescript": "^5.6.3" + "typescript": "^5.6.3", + "vitest": "^3.1.4" }, "engines": { "node": ">=20.19.0" diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index 5ca51d183..dcc17d179 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -3,8 +3,6 @@ import { exec } from "node:child_process"; import { Range } from "core"; import { EXTENSION_NAME } from "core/control-plane/env"; -import { GetGhTokenArgs } from "core/protocol/ide"; -import { editConfigFile, getConfigJsonPath } from "core/util/paths"; import * as URI from "uri-js"; import * as vscode from "vscode"; diff --git a/gui/package-lock.json b/gui/package-lock.json index 17f6b1514..1fb8463d7 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -203,7 +203,8 @@ "onnxruntime-common": "1.14.0", "onnxruntime-web": "1.14.0", "ts-jest": "^29.1.1", - "typescript": "^5.6.3" + "typescript": "^5.6.3", + "vitest": "^3.1.4" }, "engines": { "node": ">=20.19.0"