-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix workspace tracking when RooCode is moved to new window #7872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add workspace refresh when webview becomes visible - Listen for workspace folder changes and refresh accordingly - Update workspace path when active editor changes to different workspace - Fixes issue where RooCode loses track of workspace folder when moved to new VSCode window Fixes #7871
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self-Review: When I Move Windows, I Forget Where I Am 🪟➡️🤔
Well, this is awkward... reviewing my own code. It's like looking in a mirror and realizing you've had spinach in your teeth all day.
The Good News 🎉
The fix works! I successfully added workspace refresh logic at the right moments. When RooCode moves to a new window, it now remembers where it lives. No more existential crisis about workspace paths.
The "What Was I Thinking?" Parts 🤦
But in my eagerness to fix the issue, I may have gotten a bit overzealous with the async/await keywords (classic me, always trying to be too asynchronous for my own good). Also, I might have forgotten that multiple events firing at once could cause a refresh stampede.
Areas for Improvement
- Unnecessary async/await in event handlers adds overhead
- Potential race conditions from multiple simultaneous refresh calls
- Missing error handling for workspace refresh operations
- Incomplete test coverage for the new functionality
Overall
The implementation solves the reported issue (#7871), but there's room for improvement in terms of code efficiency and robustness. The core logic is sound - just needs some polish.
I'll add specific inline suggestions for improvements.
if (this.view?.visible) { | ||
// Update workspace path when view becomes visible (e.g., when moved to new window) | ||
await this.refreshWorkspace() | ||
this.postMessageToWebview({ type: "action", action: "didBecomeVisible" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The async wrapper here isn't necessary since we're not awaiting the result. Consider:
const viewStateDisposable = webviewView.onDidChangeViewState(() => {
if (this.view?.visible) {
// Fire and forget the refresh, but catch errors
this.refreshWorkspace().catch(error =>
this.log(`Failed to refresh workspace on view state change: ${error}`)
)
this.postMessageToWebview({ type: "action", action: "didBecomeVisible" })
}
})
This avoids the overhead of creating an async function when we don't need to wait for completion.
if (this.view?.visible) { | ||
// Update workspace path when view becomes visible (e.g., when moved to new window) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same async pattern issue here. Also, consider debouncing these refresh calls to prevent rapid successive updates:
const visibilityDisposable = webviewView.onDidChangeVisibility(() => {
if (this.view?.visible) {
this.refreshWorkspace().catch(error =>
this.log(`Failed to refresh workspace on visibility change: ${error}`)
)
this.postMessageToWebview({ type: "action", action: "didBecomeVisible" })
}
})
For debouncing, you could create a debounced version of refreshWorkspace to handle rapid visibility changes.
// Check if workspace path has changed | ||
const newWorkspacePath = getWorkspacePath() | ||
if (newWorkspacePath !== this.currentWorkspacePath) { | ||
await this.refreshWorkspace() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good addition of workspace path checking! Consider adding error handling here too:
const activeEditorSubscription = vscode.window.onDidChangeActiveTextEditor(() => {
// Update subscription when workspace might have changed
this.updateCodeIndexStatusSubscription()
// Check if workspace path has changed
try {
const newWorkspacePath = getWorkspacePath()
if (newWorkspacePath !== this.currentWorkspacePath) {
this.refreshWorkspace().catch(error =>
this.log(`Failed to refresh workspace on editor change: ${error}`)
)
}
} catch (error) {
this.log(`Error getting workspace path: ${error}`)
}
})
This ensures that any errors in getWorkspacePath()
won't crash the event handler.
@@ -165,6 +165,7 @@ vi.mock("vscode", () => ({ | |||
onDidChangeTextDocument: vi.fn(() => ({ dispose: vi.fn() })), | |||
onDidOpenTextDocument: vi.fn(() => ({ dispose: vi.fn() })), | |||
onDidCloseTextDocument: vi.fn(() => ({ dispose: vi.fn() })), | |||
onDidChangeWorkspaceFolders: vi.fn(() => ({ dispose: vi.fn() })), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job updating the mocks! Consider adding actual test cases to verify the behavior:
test("refreshes workspace when workspace folders change", async () => {
const mockRefreshWorkspace = vi.spyOn(provider, 'refreshWorkspace').mockResolvedValue(undefined)
await provider.resolveWebviewView(mockWebviewView)
// Get the registered handler
const onDidChangeWorkspaceFolders = vi.mocked(vscode.workspace.onDidChangeWorkspaceFolders)
const changeHandler = onDidChangeWorkspaceFolders.mock.calls[0][0]
// Trigger the event
await changeHandler()
// Verify refresh was called
expect(mockRefreshWorkspace).toHaveBeenCalled()
})
test("handles errors during workspace refresh", async () => {
const mockLog = vi.spyOn(provider, 'log')
vi.spyOn(provider, 'refreshWorkspace').mockRejectedValue(new Error("Refresh failed"))
await provider.resolveWebviewView(mockWebviewView)
// Trigger visibility change
const onDidChangeVisibility = vi.mocked(webviewView.onDidChangeVisibility)
const handler = onDidChangeVisibility.mock.calls[0][0]
await handler()
// Verify error was logged
expect(mockLog).toHaveBeenCalledWith(expect.stringContaining("Failed to refresh workspace"))
})
This would ensure the fix actually works as intended.
Description
This PR fixes an issue where RooCode loses track of its workspace folder when the tab is moved to a new VSCode window, which is problematic for multi-monitor workflows.
Problem
When users move the RooCode tab to a new window (common in multi-monitor setups), the extension loses track of the workspace folder. This causes RooCode to be unable to find or access files in the workspace.
Solution
The fix adds workspace path refresh logic at key points:
Changes Made
ClineProvider.ts
to add workspace refresh calls in visibility change handlersonDidChangeWorkspaceFolders
event listenerTesting
Related Issue
Fixes #7871
Important
Fixes workspace tracking in RooCode when moved to a new VSCode window by refreshing workspace path in key scenarios.
ClineProvider.ts
to add workspace refresh logic in visibility change handlers and active editor change listener.onDidChangeWorkspaceFolders
to refresh workspace path.ClineProvider.spec.ts
andClineProvider.sticky-mode.spec.ts
to includeonDidChangeWorkspaceFolders
event listener.This description was created by
for 6b26c04. You can customize this summary. It will automatically update as commits are pushed.