diff --git a/core/autocomplete/util/openedFilesLruCache.ts b/core/autocomplete/util/openedFilesLruCache.ts index 07df57b56..2ef27d276 100644 --- a/core/autocomplete/util/openedFilesLruCache.ts +++ b/core/autocomplete/util/openedFilesLruCache.ts @@ -1,13 +1,10 @@ import QuickLRU from "quick-lru"; -import { ToWebviewOrCoreFromIdeProtocol } from "../../protocol/ide.js"; - // The cache key and value are both a filepath string -export type cacheElementType = - ToWebviewOrCoreFromIdeProtocol["didChangeActiveTextEditor"][0]["filepath"]; +export type cacheElementType = string; // maximum number of open files that can be cached -const MAX_NUM_OPEN_CONTEXT_FILES = 10; +const MAX_NUM_OPEN_CONTEXT_FILES = 20; export const openedFilesLruCache = new QuickLRU< cacheElementType, diff --git a/core/core.ts b/core/core.ts index 7ad19ed48..c34da634c 100644 --- a/core/core.ts +++ b/core/core.ts @@ -695,7 +695,7 @@ export class Core { if (!ignore) { recentlyEditedFilesCache.set(filepath, filepath); - // Update the cache for opened files + // Set the active filepath as most recently used in the opened files cache openedFilesLruCache.set(filepath, filepath); } } catch (e) { @@ -705,9 +705,11 @@ export class Core { } }); - on("didChangeVisibleTextEditors", async ({ data: { filepaths } }) => { + on("didCloseTextDocument", async ({ data: { filepaths } }) => { try { - // LOGIC FOR DEALING WITH FILEPATHS HERE (UPDATE #2) + console.log("Visible", filepaths.length); + + // Remove the closed files from the opened files cache: TODO, UPDATE #2 } catch (e) { console.error( `didChangeVisibleTextEditors: failed to update openedFilesLruCache`, diff --git a/core/index.d.ts b/core/index.d.ts index 1ced5227c..9dec0ac51 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -814,7 +814,7 @@ export interface IDE { // Callbacks onDidChangeActiveTextEditor(callback: (fileUri: string) => void): void; - onDidChangeVisibleTextEditors(callback: (fileUris: string[]) => void): void; + onDidCloseTextDocument(callback: (fileUris: string[]) => void): void; } // Slash Commands diff --git a/core/protocol/ide.ts b/core/protocol/ide.ts index 08b867850..cb8e15aa4 100644 --- a/core/protocol/ide.ts +++ b/core/protocol/ide.ts @@ -103,5 +103,5 @@ export type ToIdeFromWebviewOrCoreProtocol = { export type ToWebviewOrCoreFromIdeProtocol = { didChangeActiveTextEditor: [{ filepath: string }, void]; - didChangeVisibleTextEditors: [{ filepaths: string[] }, void]; + didCloseTextDocument: [{ filepaths: string[] }, void]; }; diff --git a/extensions/vscode/src/VsCodeIde.ts b/extensions/vscode/src/VsCodeIde.ts index 9752556d3..5e2784891 100644 --- a/extensions/vscode/src/VsCodeIde.ts +++ b/extensions/vscode/src/VsCodeIde.ts @@ -94,10 +94,15 @@ class VsCodeIde implements IDE { }); } - onDidChangeVisibleTextEditors(callback: (uris: string[]) => void): void { - vscode.window.onDidChangeActiveTextEditor((editor) => { - if (editor) { - // extract list of opened files + onDidCloseTextDocument(callback: (uris: string[]) => void): void { + vscode.workspace.onDidCloseTextDocument((document) => { + if (document) { + let openFilePaths = vscode.window.tabGroups.all // get tab groups + .flatMap((group) => group.tabs) // extract tabs from tab groups + .filter((tab) => tab.input instanceof vscode.TabInputText) // filter irrelevant tabs (settings, etc.) + .map((tab) => (tab.input as vscode.TabInputText).uri.fsPath); // get filepaths + + callback(openFilePaths); } }); } diff --git a/extensions/vscode/src/extension/VsCodeExtension.ts b/extensions/vscode/src/extension/VsCodeExtension.ts index be4359656..7705f9a5c 100644 --- a/extensions/vscode/src/extension/VsCodeExtension.ts +++ b/extensions/vscode/src/extension/VsCodeExtension.ts @@ -386,8 +386,8 @@ export class VsCodeExtension { void this.core.invoke("didChangeActiveTextEditor", { filepath }); }); - this.ide.onDidChangeVisibleTextEditors((filepaths) => { - void this.core.invoke("didChangeVisibleTextEditors", { filepaths }); + this.ide.onDidCloseTextDocument((filepaths) => { + void this.core.invoke("didCloseTextDocument", { filepaths }); }); vscode.workspace.onDidChangeConfiguration(async (event) => {