Changesets · Branches · Tags · Compare
| Changeset | ed4a3f5ddb2160b772fa7dd89ff3204b6d8644539bcc5440c314da9e630f10b4 |
|---|---|
| Author | adarshramiyer <adarsh.r.iyer@gmail.com> · 2025-06-09 18:21 -07:00 |
| Committer | adarshramiyer <adarsh.r.iyer@gmail.com> · 2025-06-09 18:21 -07:00 |
| Parents | 2de752aa0793 |
4 files changed
modified core/core.ts +15 −12
| @@ -601,22 +601,25 @@ | ||
| 601 | 601 | |
| 602 | 602 | on("files/closed", async ({ data }) => { |
| 603 | 603 | 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 | + } | |
| 608 | 611 | |
| 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 | + } | |
| 615 | 619 | } |
| 616 | 620 | } |
| 621 | + prevFilepaths.filepaths = filepaths; | |
| 617 | 622 | } |
| 618 | - | |
| 619 | - prevFilepaths.filepaths = filepaths; | |
| 620 | 623 | } catch (e) { |
| 621 | 624 | console.error( |
| 622 | 625 | `didChangeVisibleTextEditors: failed to update openedFilesLruCache`, |
modified core/protocol/core.ts +1 −1
| @@ -181,7 +181,7 @@ | ||
| 181 | 181 | "files/opened": [{ uris?: string[] }, void]; |
| 182 | 182 | "files/created": [{ uris?: string[] }, void]; |
| 183 | 183 | "files/deleted": [{ uris?: string[] }, void]; |
| 184 | - "files/closed": [{ fileUris: string[]; uris?: string[] }, void]; | |
| 184 | + "files/closed": [{ uris?: string[] }, void]; | |
| 185 | 185 | |
| 186 | 186 | // Docs etc. Indexing. TODO move codebase to this |
| 187 | 187 | "indexing/reindex": [{ type: string; id: string }, void]; |
modified extensions/vscode/src/extension/VsCodeExtension.ts +8 −9
| @@ -295,14 +295,10 @@ | ||
| 295 | 295 | }); |
| 296 | 296 | }); |
| 297 | 297 | |
| 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 | + }); | |
| 306 | 302 | }); |
| 307 | 303 | |
| 308 | 304 | vscode.workspace.onDidCreateFiles(async (event) => { |
| @@ -393,7 +389,10 @@ | ||
| 393 | 389 | }); |
| 394 | 390 | |
| 395 | 391 | // 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); | |
| 397 | 396 | this.core.invoke("files/opened", { uris: initialOpenedFilePaths }); |
| 398 | 397 | |
| 399 | 398 | vscode.workspace.onDidChangeConfiguration(async (event) => { |
modified extensions/vscode/src/util/ideUtils.ts +7 −17
| @@ -267,25 +267,15 @@ | ||
| 267 | 267 | return uri.scheme === "file" || uri.scheme === "vscode-remote"; |
| 268 | 268 | } |
| 269 | 269 | |
| 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 | - | |
| 279 | 270 | getOpenFiles(): vscode.Uri[] { |
| 280 | 271 | 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); | |
| 289 | 279 | } |
| 290 | 280 | |
| 291 | 281 | saveFile(uri: vscode.Uri) { |