ソースを参照

Add handling for external settings changes (#3942)

Daniel 7 ヶ月 前
コミット
20e7f118bc

+ 5 - 0
src/core/webview/ClineProvider.ts

@@ -824,6 +824,11 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
 					this.contextProxy.setProviderSettings(providerSettings),
 				])
 
+				// Notify CodeIndexManager about the settings change
+				if (this.codeIndexManager) {
+					await this.codeIndexManager.handleExternalSettingsChange()
+				}
+
 				// Change the provider for the current task.
 				// TODO: We should rename `buildApiHandler` for clarity (e.g. `getProviderClient`).
 				const task = this.getCurrentCline()

+ 10 - 3
src/services/code-index/config-manager.ts

@@ -14,7 +14,7 @@ export class CodeIndexConfigManager {
 	private modelId?: string
 	private openAiOptions?: ApiHandlerOptions
 	private ollamaOptions?: ApiHandlerOptions
-	private qdrantUrl?: string
+	private qdrantUrl?: string = "http://localhost:6333"
 	private qdrantApiKey?: string
 	private searchMinScore?: number
 
@@ -103,11 +103,18 @@ export class CodeIndexConfigManager {
 	 * Checks if the service is properly configured based on the embedder type.
 	 */
 	public isConfigured(): boolean {
+
 		if (this.embedderProvider === "openai") {
-			return !!(this.openAiOptions?.openAiNativeApiKey && this.qdrantUrl)
+			const openAiKey = this.openAiOptions?.openAiNativeApiKey
+			const qdrantUrl = this.qdrantUrl
+			const isConfigured = !!(openAiKey && qdrantUrl)
+			return isConfigured
 		} else if (this.embedderProvider === "ollama") {
 			// Ollama model ID has a default, so only base URL is strictly required for config
-			return !!(this.ollamaOptions?.ollamaBaseUrl && this.qdrantUrl)
+			const ollamaBaseUrl = this.ollamaOptions?.ollamaBaseUrl
+			const qdrantUrl = this.qdrantUrl
+			const isConfigured = !!(ollamaBaseUrl && qdrantUrl)
+			return isConfigured
 		}
 		return false // Should not happen if embedderProvider is always set correctly
 	}

+ 11 - 0
src/services/code-index/manager.ts

@@ -244,4 +244,15 @@ export class CodeIndexManager {
 		this.assertInitialized()
 		return this._searchService!.searchIndex(query, directoryPrefix)
 	}
+
+	/**
+	 * Handles external settings changes by reloading configuration.
+	 * This method should be called when API provider settings are updated
+	 * to ensure the CodeIndexConfigManager picks up the new configuration.
+	 */
+	public async handleExternalSettingsChange(): Promise<void> {
+		if (this._configManager) {
+			await this._configManager.loadConfiguration()
+		}
+	}
 }

+ 1 - 1
webview-ui/src/components/settings/CodeIndexSettings.tsx

@@ -300,7 +300,7 @@ export const CodeIndexSettings: React.FC<CodeIndexSettingsProps> = ({
 						</div>
 						<div>
 							<VSCodeTextField
-								value={codebaseIndexConfig.codebaseIndexQdrantUrl}
+								value={codebaseIndexConfig.codebaseIndexQdrantUrl || "http://localhost:6333"}
 								onInput={(e: any) =>
 									setCachedStateField("codebaseIndexConfig", {
 										...codebaseIndexConfig,