mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-07 08:26:51 +00:00
Code Index (Qdrant) recreate services when change configurations (#5152)
This commit is contained in:
parent
9bf31d3ff7
commit
426518bccd
2 changed files with 62 additions and 51 deletions
|
|
@ -89,7 +89,7 @@ describe("CodeIndexManager - handleExternalSettingsChange regression", () => {
|
|||
expect(manager.isInitialized).toBe(true)
|
||||
|
||||
// Mock the methods that would be called during restart
|
||||
const stopWatcherSpy = vitest.spyOn(manager, "stopWatcher").mockImplementation(() => {})
|
||||
const recreateServicesSpy = vitest.spyOn(manager as any, "_recreateServices").mockImplementation(() => {})
|
||||
const startIndexingSpy = vitest.spyOn(manager, "startIndexing").mockResolvedValue()
|
||||
|
||||
// Mock the feature state
|
||||
|
|
@ -100,7 +100,7 @@ describe("CodeIndexManager - handleExternalSettingsChange regression", () => {
|
|||
|
||||
// Verify that the restart sequence was called
|
||||
expect(mockConfigManager.loadConfiguration).toHaveBeenCalled()
|
||||
expect(stopWatcherSpy).toHaveBeenCalled()
|
||||
expect(recreateServicesSpy).toHaveBeenCalled()
|
||||
expect(startIndexingSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -123,54 +123,7 @@ export class CodeIndexManager {
|
|||
const needsServiceRecreation = !this._serviceFactory || requiresRestart
|
||||
|
||||
if (needsServiceRecreation) {
|
||||
// Stop watcher if it exists
|
||||
if (this._orchestrator) {
|
||||
this.stopWatcher()
|
||||
}
|
||||
|
||||
// (Re)Initialize service factory
|
||||
this._serviceFactory = new CodeIndexServiceFactory(
|
||||
this._configManager,
|
||||
this.workspacePath,
|
||||
this._cacheManager,
|
||||
)
|
||||
|
||||
const ignoreInstance = ignore()
|
||||
const ignorePath = path.join(getWorkspacePath(), ".gitignore")
|
||||
try {
|
||||
const content = await fs.readFile(ignorePath, "utf8")
|
||||
ignoreInstance.add(content)
|
||||
ignoreInstance.add(".gitignore")
|
||||
} catch (error) {
|
||||
// Should never happen: reading file failed even though it exists
|
||||
console.error("Unexpected error loading .gitignore:", error)
|
||||
}
|
||||
|
||||
// (Re)Create shared service instances
|
||||
const { embedder, vectorStore, scanner, fileWatcher } = this._serviceFactory.createServices(
|
||||
this.context,
|
||||
this._cacheManager,
|
||||
ignoreInstance,
|
||||
)
|
||||
|
||||
// (Re)Initialize orchestrator
|
||||
this._orchestrator = new CodeIndexOrchestrator(
|
||||
this._configManager,
|
||||
this._stateManager,
|
||||
this.workspacePath,
|
||||
this._cacheManager,
|
||||
vectorStore,
|
||||
scanner,
|
||||
fileWatcher,
|
||||
)
|
||||
|
||||
// (Re)Initialize search service
|
||||
this._searchService = new CodeIndexSearchService(
|
||||
this._configManager,
|
||||
this._stateManager,
|
||||
embedder,
|
||||
vectorStore,
|
||||
)
|
||||
await this._recreateServices()
|
||||
}
|
||||
|
||||
// 5. Handle Indexing Start/Restart
|
||||
|
|
@ -248,6 +201,61 @@ export class CodeIndexManager {
|
|||
return this._searchService!.searchIndex(query, directoryPrefix)
|
||||
}
|
||||
|
||||
/**
|
||||
* Private helper method to recreate services with current configuration.
|
||||
* Used by both initialize() and handleExternalSettingsChange().
|
||||
*/
|
||||
private async _recreateServices(): Promise<void> {
|
||||
// Stop watcher if it exists
|
||||
if (this._orchestrator) {
|
||||
this.stopWatcher()
|
||||
}
|
||||
|
||||
// (Re)Initialize service factory
|
||||
this._serviceFactory = new CodeIndexServiceFactory(
|
||||
this._configManager!,
|
||||
this.workspacePath,
|
||||
this._cacheManager!,
|
||||
)
|
||||
|
||||
const ignoreInstance = ignore()
|
||||
const ignorePath = path.join(getWorkspacePath(), ".gitignore")
|
||||
try {
|
||||
const content = await fs.readFile(ignorePath, "utf8")
|
||||
ignoreInstance.add(content)
|
||||
ignoreInstance.add(".gitignore")
|
||||
} catch (error) {
|
||||
// Should never happen: reading file failed even though it exists
|
||||
console.error("Unexpected error loading .gitignore:", error)
|
||||
}
|
||||
|
||||
// (Re)Create shared service instances
|
||||
const { embedder, vectorStore, scanner, fileWatcher } = this._serviceFactory.createServices(
|
||||
this.context,
|
||||
this._cacheManager!,
|
||||
ignoreInstance,
|
||||
)
|
||||
|
||||
// (Re)Initialize orchestrator
|
||||
this._orchestrator = new CodeIndexOrchestrator(
|
||||
this._configManager!,
|
||||
this._stateManager,
|
||||
this.workspacePath,
|
||||
this._cacheManager!,
|
||||
vectorStore,
|
||||
scanner,
|
||||
fileWatcher,
|
||||
)
|
||||
|
||||
// (Re)Initialize search service
|
||||
this._searchService = new CodeIndexSearchService(
|
||||
this._configManager!,
|
||||
this._stateManager,
|
||||
embedder,
|
||||
vectorStore,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles external settings changes by reloading configuration.
|
||||
* This method should be called when API provider settings are updated
|
||||
|
|
@ -263,7 +271,10 @@ export class CodeIndexManager {
|
|||
|
||||
// If configuration changes require a restart and the manager is initialized, restart the service
|
||||
if (requiresRestart && isFeatureEnabled && isFeatureConfigured && this.isInitialized) {
|
||||
this.stopWatcher()
|
||||
// Recreate services with new configuration
|
||||
await this._recreateServices()
|
||||
|
||||
// Start indexing with new services
|
||||
await this.startIndexing()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue