Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,15 @@ export class ClineProvider
await this.postStateToWebview()
}

async handleWorkspaceFoldersChanged() {
// Update the current workspace path when folders change
this.currentWorkspacePath = getWorkspacePath()
// Notify the webview about the state change
await this.postStateToWebview()
// Log the workspace change for debugging
this.log("Workspace folders changed - updated workspace path and notified webview")
}

async postStateToWebview() {
const state = await this.getStateToPostToWebview()
this.postMessageToWebview({ type: "state", state })
Expand Down
65 changes: 53 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,68 @@ export async function activate(context: vscode.ExtensionContext) {
const contextProxy = await ContextProxy.getInstance(context)

// Initialize code index managers for all workspace folders.
const codeIndexManagers: CodeIndexManager[] = []
const codeIndexManagers: Map<string, CodeIndexManager> = new Map()

// Helper function to initialize a CodeIndexManager for a folder
async function initializeCodeIndexManagerForFolder(folder: vscode.WorkspaceFolder): Promise<void> {
const manager = CodeIndexManager.getInstance(context, folder.uri.fsPath)

if (manager) {
codeIndexManagers.set(folder.uri.fsPath, manager)

try {
await manager.initialize(contextProxy)
} catch (error) {
outputChannel.appendLine(
`[CodeIndexManager] Error during background CodeIndexManager configuration/indexing for ${folder.uri.fsPath}: ${error.message || error}`,
)
}

context.subscriptions.push(manager)
}
}

// Initialize managers for existing workspace folders
if (vscode.workspace.workspaceFolders) {
for (const folder of vscode.workspace.workspaceFolders) {
const manager = CodeIndexManager.getInstance(context, folder.uri.fsPath)

if (manager) {
codeIndexManagers.push(manager)
await initializeCodeIndexManagerForFolder(folder)
}
}

try {
await manager.initialize(contextProxy)
} catch (error) {
// Listen for workspace folder changes
context.subscriptions.push(
vscode.workspace.onDidChangeWorkspaceFolders(async (event) => {
// Handle removed folders
for (const removedFolder of event.removed) {
const manager = codeIndexManagers.get(removedFolder.uri.fsPath)
if (manager) {
outputChannel.appendLine(
`[CodeIndexManager] Error during background CodeIndexManager configuration/indexing for ${folder.uri.fsPath}: ${error.message || error}`,
`[CodeIndexManager] Removing CodeIndexManager for removed folder: ${removedFolder.uri.fsPath}`,
)
// Dispose the manager
manager.dispose()
// Remove from our map
codeIndexManagers.delete(removedFolder.uri.fsPath)
// Remove from context subscriptions
const index = context.subscriptions.indexOf(manager)
if (index > -1) {
context.subscriptions.splice(index, 1)
}
}
}

context.subscriptions.push(manager)
// Handle added folders
for (const addedFolder of event.added) {
outputChannel.appendLine(
`[CodeIndexManager] Adding CodeIndexManager for new folder: ${addedFolder.uri.fsPath}`,
)
await initializeCodeIndexManagerForFolder(addedFolder)
}
}
}

// Notify the provider about workspace changes
provider.handleWorkspaceFoldersChanged()
}),
)
Comment on lines +133 to +165
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provider variable is referenced before it's initialized. The workspace folder change listener (lines 133-165) calls provider.handleWorkspaceFoldersChanged() on line 163, but provider is not created until line 168. This will cause a ReferenceError when workspace folders are added or removed. The listener registration should be moved to after the provider initialization, or the provider reference should be captured differently.


// Initialize the provider *before* the Roo Code Cloud service.
const provider = new ClineProvider(context, outputChannel, "sidebar", contextProxy, mdmService)
Expand Down