Skip to content

Commit 271a59c

Browse files
committed
fix small issue
1 parent a931227 commit 271a59c

File tree

3 files changed

+53
-37
lines changed

3 files changed

+53
-37
lines changed

src/services/code-index/config-manager.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ export class CodeIndexConfigManager {
269269
const prevGeminiApiKey = prev?.geminiApiKey ?? ""
270270
const prevMistralApiKey = prev?.mistralApiKey ?? ""
271271
const prevQdrantUrl = prev?.qdrantUrl ?? ""
272+
const prevValkeyUrl = prev?.valkeyUrl ?? ""
273+
const prevSearchProvider = prev?.searchProvider ?? ""
272274
const prevQdrantApiKey = prev?.qdrantApiKey ?? ""
273275

274276
// 1. Transition from disabled/unconfigured to enabled/configured
@@ -306,6 +308,8 @@ export class CodeIndexConfigManager {
306308
const currentGeminiApiKey = this.geminiOptions?.apiKey ?? ""
307309
const currentMistralApiKey = this.mistralOptions?.apiKey ?? ""
308310
const currentQdrantUrl = this.qdrantUrl ?? ""
311+
const currentValkeyUrl = this.valkeyUrl ?? ""
312+
const currentSearchProvider = this.searchProvider ?? ""
309313
const currentQdrantApiKey = this.qdrantApiKey ?? ""
310314

311315
if (prevOpenAiKey !== currentOpenAiKey) {
@@ -340,6 +344,14 @@ export class CodeIndexConfigManager {
340344
return true
341345
}
342346

347+
if (prevValkeyUrl !== currentValkeyUrl) {
348+
return true
349+
}
350+
351+
if (currentSearchProvider != this.searchProvider) {
352+
return true
353+
}
354+
343355
// Vector dimension changes (still important for compatibility)
344356
if (this._hasVectorDimensionChanged(prevProvider, prev?.modelId)) {
345357
return true

src/services/code-index/vector-store/valkey-search-client.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,39 +35,38 @@ export class ValkeySearchVectorStore implements IVectorStore {
3535

3636
this.isInitializing = true
3737

38-
try {
39-
if (this.client && this.client.disconnect) {
40-
this.client.disconnect()
41-
}
38+
return new Promise<void>((resolve, reject) => {
39+
try {
40+
const { hostname, port, password, username } = this.parseConnectionOptions()
41+
this.client = new Valkey({
42+
host: hostname,
43+
port,
44+
password,
45+
username,
46+
})
4247

43-
const { hostname, port, password } = this.parseConnectionOptions()
44-
this.client = new Valkey({
45-
host: hostname,
46-
port,
47-
password,
48-
retryStrategy: (times) => Math.min(times * 100, 5000),
49-
})
48+
this.client.on("error", (err: Error) => {
49+
this.destroy()
50+
this.isInitializing = false
51+
reject(new Error("Valkey connection error", err))
52+
})
5053

51-
this.client.on("error", (err: Error) => {
52-
console.error("[ValkeySearch] Connection error:", err)
53-
})
54+
this.client.on("ready", () => {
55+
this.isInitializing = false
56+
resolve()
57+
})
5458

55-
this.client.on("ready", () => {
56-
console.log("[ValkeySearch] Connection established")
57-
this.isInitializing = false
58-
})
59+
this.client.on("end", () => {
60+
this.destroy()
61+
reject(new Error("Valkey connection closed"))
62+
})
5963

60-
this.client.on("end", () => {
61-
console.log("[ValkeySearch] Connection closed")
64+
this.client.connect().catch(reject)
65+
} catch (error) {
6266
this.isInitializing = false
63-
})
64-
65-
await this.client.connect()
66-
} catch (error) {
67-
console.error("[ValkeySearch] Failed to initialize client:", error)
68-
this.isInitializing = false
69-
setTimeout(async () => await this.initializeClient(), 5000)
70-
}
67+
reject(new Error("Valkey initialization failed", error))
68+
}
69+
})
7170
}
7271

7372
private parseConnectionOptions() {
@@ -76,6 +75,7 @@ export class ValkeySearchVectorStore implements IVectorStore {
7675
hostname: url.hostname,
7776
port: Number(url.port) || 6379,
7877
password: url.password || undefined,
78+
username: url.username || undefined,
7979
}
8080
}
8181

webview-ui/src/components/chat/CodeIndexPopover.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,6 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
193193
// Current settings state - tracks user changes
194194
const [currentSettings, setCurrentSettings] = useState<LocalCodeIndexSettings>(getDefaultSettings())
195195

196-
// Search provider selection
197-
const [searchProvider, setSearchProvider] = useState<SearchProvider>((currentSettings.searchProvider = ""))
198-
199196
// Update indexing status from parent
200197
useEffect(() => {
201198
setIndexingStatus(externalIndexingStatus)
@@ -345,6 +342,10 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
345342
// Use a Set to ensure unique keys
346343
const uniqueKeys = Array.from(new Set(allKeys))
347344

345+
if (currentSettings.searchProvider !== initialSettings.searchProvider) {
346+
return true
347+
}
348+
348349
for (const key of uniqueKeys) {
349350
const currentValue = currentSettings[key]
350351
const initialValue = initialSettings[key]
@@ -461,7 +462,6 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
461462
setSaveError(null)
462463

463464
// Prepare settings to save
464-
currentSettings.searchProvider = searchProvider
465465
const settingsToSave: any = {
466466
codebaseIndexEnabled: currentSettings.codebaseIndexEnabled,
467467
}
@@ -542,7 +542,9 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
542542
<div className="flex items-center gap-2">
543543
<VSCodeCheckbox
544544
checked={currentSettings.codebaseIndexEnabled}
545-
onChange={(e: any) => updateSetting("codebaseIndexEnabled", e.target.checked)}>
545+
onChange={(e: any) => {
546+
updateSetting("codebaseIndexEnabled", e.target.checked)
547+
}}>
546548
<span className="font-medium">{t("settings:codeIndex.enableLabel")}</span>
547549
</VSCodeCheckbox>
548550
<StandardTooltip content={t("settings:codeIndex.enableDescription")}>
@@ -1027,8 +1029,10 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
10271029
{t("settings:codeIndex.searchProviderLabel")}
10281030
</label>
10291031
<Select
1030-
value={searchProvider}
1031-
onValueChange={(value: SearchProvider) => setSearchProvider(value)}>
1032+
value={currentSettings.searchProvider}
1033+
onValueChange={(value: SearchProvider) => {
1034+
updateSetting("searchProvider", value)
1035+
}}>
10321036
<SelectTrigger className="w-full">
10331037
<SelectValue />
10341038
</SelectTrigger>
@@ -1043,7 +1047,7 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
10431047
</Select>
10441048
</div>
10451049

1046-
{searchProvider === "qdrant" && (
1050+
{currentSettings.searchProvider === "qdrant" && (
10471051
<>
10481052
<div className="space-y-2">
10491053
<label className="text-sm font-medium">
@@ -1096,7 +1100,7 @@ export const CodeIndexPopover: React.FC<CodeIndexPopoverProps> = ({
10961100
</>
10971101
)}
10981102

1099-
{searchProvider === "valkey" && (
1103+
{currentSettings.searchProvider === "valkey" && (
11001104
<>
11011105
<div className="space-y-2">
11021106
<label className="text-sm font-medium">

0 commit comments

Comments
 (0)