Elffuss BraidHub

kikocis/continue public

restored files/closed data passing and unified util functions for getting open tabs
Changeseted4a3f5ddb2160b772fa7dd89ff3204b6d8644539bcc5440c314da9e630f10b4
Authoradarshramiyer <adarsh.r.iyer@gmail.com> · 2025-06-09 18:21 -07:00
Committeradarshramiyer <adarsh.r.iyer@gmail.com> · 2025-06-09 18:21 -07:00
Parents2de752aa0793

Browse the files at this changeset

4 files changed

modified core/core.ts +15 −12
@@ -601,22 +601,25 @@
601601
602602 on("files/closed", async ({ data }) => {
603603 try {
604- const filepaths = data.fileUris;
605- if (!prevFilepaths.filepaths.length) {
606- prevFilepaths.filepaths = filepaths;
607- }
604+ const fileUris = await this.ide.getOpenFiles();
605+ if (fileUris) {
606+ const filepaths = fileUris.map((uri) => uri.toString());
607+
608+ if (!prevFilepaths.filepaths.length) {
609+ prevFilepaths.filepaths = filepaths;
610+ }
608611
609- // If there is a removal, including if the number of tabs is the same (which can happen with temp tabs)
610- if (filepaths.length <= prevFilepaths.filepaths.length) {
611- // Remove files from cache that are no longer open (i.e. in the cache but not in the list of opened tabs)
612- for (const [key, _] of openedFilesLruCache.entriesDescending()) {
613- if (!filepaths.includes(key)) {
614- openedFilesLruCache.delete(key);
612+ // If there is a removal, including if the number of tabs is the same (which can happen with temp tabs)
613+ if (filepaths.length <= prevFilepaths.filepaths.length) {
614+ // Remove files from cache that are no longer open (i.e. in the cache but not in the list of opened tabs)
615+ for (const [key, _] of openedFilesLruCache.entriesDescending()) {
616+ if (!filepaths.includes(key)) {
617+ openedFilesLruCache.delete(key);
618+ }
615619 }
616620 }
621+ prevFilepaths.filepaths = filepaths;
617622 }
618-
619- prevFilepaths.filepaths = filepaths;
620623 } catch (e) {
621624 console.error(
622625 `didChangeVisibleTextEditors: failed to update openedFilesLruCache`,
modified core/protocol/core.ts +1 −1
@@ -181,7 +181,7 @@
181181 "files/opened": [{ uris?: string[] }, void];
182182 "files/created": [{ uris?: string[] }, void];
183183 "files/deleted": [{ uris?: string[] }, void];
184- "files/closed": [{ fileUris: string[]; uris?: string[] }, void];
184+ "files/closed": [{ uris?: string[] }, void];
185185
186186 // Docs etc. Indexing. TODO move codebase to this
187187 "indexing/reindex": [{ type: string; id: string }, void];
modified extensions/vscode/src/extension/VsCodeExtension.ts +8 −9
@@ -295,14 +295,10 @@
295295 });
296296 });
297297
298- vscode.workspace.onDidCloseTextDocument((document) => {
299- if (document) {
300- let openFiles = this.ideUtils.getOpenFileUrisAsStrings();
301- this.core.invoke("files/closed", {
302- uris: [document.uri.toString()],
303- fileUris: openFiles,
304- });
305- }
298+ vscode.workspace.onDidCloseTextDocument(async (event) => {
299+ this.core.invoke("files/closed", {
300+ uris: [event.uri.toString()],
301+ });
306302 });
307303
308304 vscode.workspace.onDidCreateFiles(async (event) => {
@@ -393,7 +389,10 @@
393389 });
394390
395391 // initializes openedFileLruCache with files that are already open when the extension is activated
396- let initialOpenedFilePaths = this.ideUtils.getOpenFileUrisAsStrings();
392+ let initialOpenedFilePaths = this.ideUtils
393+ .getOpenFiles()
394+ .map((uri) => uri.toString());
395+ console.log("initial", initialOpenedFilePaths);
397396 this.core.invoke("files/opened", { uris: initialOpenedFilePaths });
398397
399398 vscode.workspace.onDidChangeConfiguration(async (event) => {
modified extensions/vscode/src/util/ideUtils.ts +7 −17
@@ -267,25 +267,15 @@
267267 return uri.scheme === "file" || uri.scheme === "vscode-remote";
268268 }
269269
270- // Gets the URIs of open tabs in the editor
271- // Stricter criteria than getOpenFiles()
272- getOpenFileUrisAsStrings(): string[] {
273- return vscode.window.tabGroups.all
274- .flatMap((group) => group.tabs)
275- .filter((tab) => tab.input instanceof vscode.TabInputText)
276- .map((tab) => (tab.input as vscode.TabInputText).uri.toString());
277- }
278-
279270 getOpenFiles(): vscode.Uri[] {
280271 return vscode.window.tabGroups.all
281- .map((group) => {
282- return group.tabs.map((tab) => {
283- return (tab.input as any)?.uri;
284- });
285- })
286- .flat()
287- .filter(Boolean) // filter out undefined values
288- .filter((uri) => this.documentIsCode(uri)); // Filter out undesired documents
272+ .flatMap((group) => group.tabs)
273+ .filter(
274+ (tab) =>
275+ tab.input instanceof vscode.TabInputText &&
276+ this.documentIsCode((tab.input as vscode.TabInputText).uri),
277+ )
278+ .map((tab) => (tab.input as vscode.TabInputText).uri);
289279 }
290280
291281 saveFile(uri: vscode.Uri) {