mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
fix: detect newly added folders in workspace dynamically
- Added workspace folder change listener in extension.ts - Convert codeIndexManagers from array to Map for better tracking - Implement logic to create CodeIndexManager for added folders - Implement logic to dispose CodeIndexManager for removed folders - Add handleWorkspaceFoldersChanged method to ClineProvider - Fixes #8886
This commit is contained in:
parent
a3101aa92b
commit
eb36d954be
2 changed files with 65 additions and 15 deletions
|
|
@ -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 })
|
||||
|
|
|
|||
|
|
@ -101,28 +101,69 @@ 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()
|
||||
|
||||
if (vscode.workspace.workspaceFolders) {
|
||||
for (const folder of vscode.workspace.workspaceFolders) {
|
||||
const manager = CodeIndexManager.getInstance(context, folder.uri.fsPath)
|
||||
// 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.push(manager)
|
||||
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)
|
||||
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) {
|
||||
await initializeCodeIndexManagerForFolder(folder)
|
||||
}
|
||||
}
|
||||
|
||||
// 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] 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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()
|
||||
}),
|
||||
)
|
||||
|
||||
// Initialize the provider *before* the Roo Code Cloud service.
|
||||
const provider = new ClineProvider(context, outputChannel, "sidebar", contextProxy, mdmService)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue