optimize context files (fix) (#1933)

optimize context files
This commit is contained in:
aheizi 2025-03-24 22:30:16 +08:00 committed by GitHub
parent 2985172c61
commit 83ba22a44c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -60,21 +60,35 @@ class WorkspaceTracker {
this.disposables.push(watcher)
this.disposables.push(vscode.window.tabGroups.onDidChangeTabs(() => this.workspaceDidReset()))
// Listen for tab changes and call workspaceDidUpdate directly
this.disposables.push(
vscode.window.tabGroups.onDidChangeTabs(() => {
// Reset if workspace path has changed
if (this.prevWorkSpacePath !== this.cwd) {
this.workspaceDidReset()
} else {
// Otherwise just update
this.workspaceDidUpdate()
}
}),
)
}
private getOpenedTabsInfo() {
return vscode.window.tabGroups.all.flatMap((group) =>
group.tabs
.filter((tab) => tab.input instanceof vscode.TabInputText)
.map((tab) => {
const path = (tab.input as vscode.TabInputText).uri.fsPath
return {
return vscode.window.tabGroups.all.reduce(
(acc, group) => {
const groupTabs = group.tabs
.filter((tab) => tab.input instanceof vscode.TabInputText)
.map((tab) => ({
label: tab.label,
isActive: tab.isActive,
path: toRelativePath(path, this.cwd || ""),
}
}),
path: toRelativePath((tab.input as vscode.TabInputText).uri.fsPath, this.cwd || ""),
}))
groupTabs.forEach((tab) => (tab.isActive ? acc.unshift(tab) : acc.push(tab)))
return acc
},
[] as Array<{ label: string; isActive: boolean; path: string }>,
)
}