-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -752,11 +752,16 @@ export class ClineProvider | |
// Initialize code index status subscription for the current workspace. | ||
this.updateCodeIndexStatusSubscription() | ||
|
||
// Listen for active editor changes to update code index status for the | ||
// current workspace. | ||
const activeEditorSubscription = vscode.window.onDidChangeActiveTextEditor(() => { | ||
// Listen for active editor changes to update code index status and workspace path | ||
const activeEditorSubscription = vscode.window.onDidChangeActiveTextEditor(async () => { | ||
// Update subscription when workspace might have changed. | ||
this.updateCodeIndexStatusSubscription() | ||
|
||
// Check if workspace path has changed | ||
const newWorkspacePath = getWorkspacePath() | ||
if (newWorkspacePath !== this.currentWorkspacePath) { | ||
await this.refreshWorkspace() | ||
} | ||
}) | ||
this.webviewDisposables.push(activeEditorSubscription) | ||
|
||
|
@@ -765,17 +770,21 @@ export class ClineProvider | |
if ("onDidChangeViewState" in webviewView) { | ||
// WebviewView and WebviewPanel have all the same properties except | ||
// for this visibility listener panel. | ||
const viewStateDisposable = webviewView.onDidChangeViewState(() => { | ||
const viewStateDisposable = webviewView.onDidChangeViewState(async () => { | ||
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 commentThe 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. |
||
} | ||
}) | ||
|
||
this.webviewDisposables.push(viewStateDisposable) | ||
} else if ("onDidChangeVisibility" in webviewView) { | ||
// sidebar | ||
const visibilityDisposable = webviewView.onDidChangeVisibility(() => { | ||
const visibilityDisposable = webviewView.onDidChangeVisibility(async () => { | ||
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 commentThe 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. |
||
await this.refreshWorkspace() | ||
this.postMessageToWebview({ type: "action", action: "didBecomeVisible" }) | ||
} | ||
}) | ||
|
@@ -810,6 +819,12 @@ export class ClineProvider | |
}) | ||
this.webviewDisposables.push(configDisposable) | ||
|
||
// Listen for workspace folder changes | ||
const workspaceFoldersDisposable = vscode.workspace.onDidChangeWorkspaceFolders(async () => { | ||
await this.refreshWorkspace() | ||
}) | ||
this.webviewDisposables.push(workspaceFoldersDisposable) | ||
|
||
// If the extension is starting a new session, clear previous task state. | ||
await this.removeClineFromStack() | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. |
||
}, | ||
env: { | ||
uriScheme: "vscode", | ||
|
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:
This ensures that any errors in
getWorkspacePath()
won't crash the event handler.