temp experiment finished. figured out how to catch when files close.

This commit is contained in:
adarshramiyer 2025-06-03 15:41:27 -07:00
parent ceee1831e3
commit 78c86d1e59
6 changed files with 20 additions and 16 deletions

View file

@ -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,

View file

@ -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`,

2
core/index.d.ts vendored
View file

@ -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

View file

@ -103,5 +103,5 @@ export type ToIdeFromWebviewOrCoreProtocol = {
export type ToWebviewOrCoreFromIdeProtocol = {
didChangeActiveTextEditor: [{ filepath: string }, void];
didChangeVisibleTextEditors: [{ filepaths: string[] }, void];
didCloseTextDocument: [{ filepaths: string[] }, void];
};

View file

@ -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);
}
});
}

View file

@ -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) => {