Skip to content

Commit 5b3647f

Browse files
authored
Add active files to file context menu (RooCodeInc#4048)
* Add active files to file context menu Add support to include active files (open tabs) within the WorkspaceTracker. This enables the tracker to send the webview with a file list that has active files listed at the top. The changes include: - Listening for tab group changes using `vscode.window.tabGroups.onDidChangeTabs` to trigger workspace updates. - Introducing an `activeFiles` getter that retrieves the file paths of all currently open text editor tabs. - Modifying the `workspaceDidUpdate` function to include both `activeFiles` and `filePaths` when posting the `workspaceUpdated` message to the webview. * use set * add changeset
1 parent 14b6e71 commit 5b3647f

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.changeset/eleven-monkeys-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": minor
3+
---
4+
5+
Prioritize active files in file context menu

src/integrations/workspace/WorkspaceTracker.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ class WorkspaceTracker {
1010
private disposables: vscode.Disposable[] = []
1111
private filePaths: Set<string> = new Set()
1212

13+
private get activeFiles() {
14+
return new Set(
15+
vscode.window.tabGroups.activeTabGroup.tabs
16+
.filter((tab) => tab.input instanceof vscode.TabInputText)
17+
.map((tab) => (tab.input as vscode.TabInputText).uri.fsPath),
18+
)
19+
}
20+
1321
constructor(private readonly postMessageToWebview: (message: ExtensionMessage) => Promise<void>) {
1422
this.postMessageToWebview = postMessageToWebview
1523
this.registerListeners()
@@ -36,6 +44,9 @@ class WorkspaceTracker {
3644
// Listen for file renaming
3745
this.disposables.push(vscode.workspace.onDidRenameFiles(this.onFilesRenamed.bind(this)))
3846

47+
// Listen for tab groups changes
48+
this.disposables.push(vscode.window.tabGroups.onDidChangeTabs(this.workspaceDidUpdate.bind(this)))
49+
3950
/*
4051
An event that is emitted when a workspace folder is added or removed.
4152
**Note:** this event will not fire if the first workspace folder is added, removed or changed,
@@ -86,7 +97,7 @@ class WorkspaceTracker {
8697
}
8798
this.postMessageToWebview({
8899
type: "workspaceUpdated",
89-
filePaths: Array.from(this.filePaths).map((file) => {
100+
filePaths: Array.from(new Set([...this.activeFiles, ...this.filePaths])).map((file) => {
90101
const relativePath = path.relative(cwd, file).toPosix()
91102
return file.endsWith("/") ? relativePath + "/" : relativePath
92103
}),

0 commit comments

Comments
 (0)