Skip to content

Commit 83ba22a

Browse files
authored
optimize context files (fix) (#1933)
optimize context files
1 parent 2985172 commit 83ba22a

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/integrations/workspace/WorkspaceTracker.ts

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,35 @@ class WorkspaceTracker {
6060

6161
this.disposables.push(watcher)
6262

63-
this.disposables.push(vscode.window.tabGroups.onDidChangeTabs(() => this.workspaceDidReset()))
63+
// Listen for tab changes and call workspaceDidUpdate directly
64+
this.disposables.push(
65+
vscode.window.tabGroups.onDidChangeTabs(() => {
66+
// Reset if workspace path has changed
67+
if (this.prevWorkSpacePath !== this.cwd) {
68+
this.workspaceDidReset()
69+
} else {
70+
// Otherwise just update
71+
this.workspaceDidUpdate()
72+
}
73+
}),
74+
)
6475
}
6576

6677
private getOpenedTabsInfo() {
67-
return vscode.window.tabGroups.all.flatMap((group) =>
68-
group.tabs
69-
.filter((tab) => tab.input instanceof vscode.TabInputText)
70-
.map((tab) => {
71-
const path = (tab.input as vscode.TabInputText).uri.fsPath
72-
return {
78+
return vscode.window.tabGroups.all.reduce(
79+
(acc, group) => {
80+
const groupTabs = group.tabs
81+
.filter((tab) => tab.input instanceof vscode.TabInputText)
82+
.map((tab) => ({
7383
label: tab.label,
7484
isActive: tab.isActive,
75-
path: toRelativePath(path, this.cwd || ""),
76-
}
77-
}),
85+
path: toRelativePath((tab.input as vscode.TabInputText).uri.fsPath, this.cwd || ""),
86+
}))
87+
88+
groupTabs.forEach((tab) => (tab.isActive ? acc.unshift(tab) : acc.push(tab)))
89+
return acc
90+
},
91+
[] as Array<{ label: string; isActive: boolean; path: string }>,
7892
)
7993
}
8094

0 commit comments

Comments
 (0)