From 030ad265326d7f65e0f2d9155d6355cbdba89ac8 Mon Sep 17 00:00:00 2001 From: hannesrudolph Date: Fri, 4 Jul 2025 13:44:53 -0600 Subject: [PATCH] fix: handle undefined codeIndexManager when no workspace is open (#5356) --- src/core/webview/webviewMessageHandler.ts | 72 +++++++++++++++++++---- src/i18n/locales/ca/embeddings.json | 3 + src/i18n/locales/de/embeddings.json | 3 + src/i18n/locales/en/embeddings.json | 3 + src/i18n/locales/es/embeddings.json | 3 + src/i18n/locales/fr/embeddings.json | 3 + src/i18n/locales/hi/embeddings.json | 3 + src/i18n/locales/id/embeddings.json | 3 + src/i18n/locales/it/embeddings.json | 3 + src/i18n/locales/ja/embeddings.json | 3 + src/i18n/locales/ko/embeddings.json | 3 + src/i18n/locales/nl/embeddings.json | 3 + src/i18n/locales/pl/embeddings.json | 3 + src/i18n/locales/pt-BR/embeddings.json | 3 + src/i18n/locales/ru/embeddings.json | 3 + src/i18n/locales/tr/embeddings.json | 3 + src/i18n/locales/vi/embeddings.json | 3 + src/i18n/locales/zh-CN/embeddings.json | 3 + src/i18n/locales/zh-TW/embeddings.json | 3 + 19 files changed, 114 insertions(+), 12 deletions(-) diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index 1828e8ab5b..69d2247bc3 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -1126,6 +1126,9 @@ export const webviewMessageHandler = async ( // Notify the code index manager about the change if (provider.codeIndexManager) { await provider.codeIndexManager.handleSettingsChange() + } else { + // Send error response when no workspace is open + vscode.window.showErrorMessage(t("embeddings:code_indexing_requires_workspace")) } await provider.postStateToWebview() @@ -1827,6 +1830,17 @@ export const webviewMessageHandler = async ( break } + // Check if codeIndexManager exists first + if (!provider.codeIndexManager) { + // Send error response when no workspace is open + await provider.postMessageToWebview({ + type: "codeIndexSettingsSaved", + success: false, + error: t("embeddings:code_indexing_requires_workspace"), + }) + break + } + const settings = message.codeIndexSettings try { @@ -1869,16 +1883,14 @@ export const webviewMessageHandler = async ( const storedOpenAiKey = provider.contextProxy.getSecret("codeIndexOpenAiKey") // Notify code index manager of changes - if (provider.codeIndexManager) { - await provider.codeIndexManager.handleSettingsChange() + await provider.codeIndexManager.handleSettingsChange() - // Auto-start indexing if now enabled and configured - if (provider.codeIndexManager.isFeatureEnabled && provider.codeIndexManager.isFeatureConfigured) { - if (!provider.codeIndexManager.isInitialized) { - await provider.codeIndexManager.initialize(provider.contextProxy) - } - provider.codeIndexManager.startIndexing() + // Auto-start indexing if now enabled and configured + if (provider.codeIndexManager.isFeatureEnabled && provider.codeIndexManager.isFeatureConfigured) { + if (!provider.codeIndexManager.isInitialized) { + await provider.codeIndexManager.initialize(provider.contextProxy) } + provider.codeIndexManager.startIndexing() } // Send success response @@ -1902,7 +1914,21 @@ export const webviewMessageHandler = async ( } case "requestIndexingStatus": { - const status = provider.codeIndexManager!.getCurrentStatus() + if (!provider.codeIndexManager) { + // Send a default status indicating indexing is unavailable + provider.postMessageToWebview({ + type: "indexingStatusUpdate", + values: { + systemStatus: "Unavailable", + message: t("embeddings:code_indexing_requires_workspace"), + processedItems: 0, + totalItems: 0, + currentItemUnit: "files", + }, + }) + break + } + const status = provider.codeIndexManager.getCurrentStatus() provider.postMessageToWebview({ type: "indexingStatusUpdate", values: status, @@ -1930,23 +1956,45 @@ export const webviewMessageHandler = async ( break } case "startIndexing": { + if (!provider.codeIndexManager) { + provider.log("Cannot start indexing: No workspace is open") + // Show error message to user + vscode.window.showErrorMessage(t("embeddings:code_indexing_requires_workspace")) + break + } try { - const manager = provider.codeIndexManager! + const manager = provider.codeIndexManager if (manager.isFeatureEnabled && manager.isFeatureConfigured) { if (!manager.isInitialized) { await manager.initialize(provider.contextProxy) } - manager.startIndexing() + // Show success message + vscode.window.showInformationMessage(t("embeddings:indexing_started")) } } catch (error) { provider.log(`Error starting indexing: ${error instanceof Error ? error.message : String(error)}`) + // Show error message + vscode.window.showErrorMessage( + t("embeddings:indexing_failed", { error: error instanceof Error ? error.message : String(error) }), + ) } break } case "clearIndexData": { + if (!provider.codeIndexManager) { + provider.log("Cannot clear index data: No workspace is open") + provider.postMessageToWebview({ + type: "indexCleared", + values: { + success: false, + error: t("embeddings:code_indexing_requires_workspace"), + }, + }) + break + } try { - const manager = provider.codeIndexManager! + const manager = provider.codeIndexManager await manager.clearIndexData() provider.postMessageToWebview({ type: "indexCleared", values: { success: true } }) } catch (error) { diff --git a/src/i18n/locales/ca/embeddings.json b/src/i18n/locales/ca/embeddings.json index 3302ff7acd..375c0364d0 100644 --- a/src/i18n/locales/ca/embeddings.json +++ b/src/i18n/locales/ca/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Error desconegut", + "code_indexing_requires_workspace": "La indexació de codi requereix un espai de treball obert", + "indexing_started": "Indexació de codi iniciada", + "indexing_failed": "No s'ha pogut iniciar la indexació: {{error}}", "authenticationFailed": "No s'han pogut crear les incrustacions: ha fallat l'autenticació. Comproveu la vostra clau d'API.", "failedWithStatus": "No s'han pogut crear les incrustacions després de {{attempts}} intents: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "No s'han pogut crear les incrustacions després de {{attempts}} intents: {{errorMessage}}", diff --git a/src/i18n/locales/de/embeddings.json b/src/i18n/locales/de/embeddings.json index 300899fd1b..0b4d47e6f9 100644 --- a/src/i18n/locales/de/embeddings.json +++ b/src/i18n/locales/de/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Unbekannter Fehler", + "code_indexing_requires_workspace": "Die Code-Indizierung erfordert einen geöffneten Arbeitsbereich", + "indexing_started": "Code-Indizierung gestartet", + "indexing_failed": "Indizierung konnte nicht gestartet werden: {{error}}", "authenticationFailed": "Erstellung von Einbettungen fehlgeschlagen: Authentifizierung fehlgeschlagen. Bitte überprüfe deinen API-Schlüssel.", "failedWithStatus": "Erstellung von Einbettungen nach {{attempts}} Versuchen fehlgeschlagen: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "Erstellung von Einbettungen nach {{attempts}} Versuchen fehlgeschlagen: {{errorMessage}}", diff --git a/src/i18n/locales/en/embeddings.json b/src/i18n/locales/en/embeddings.json index e57f3de0e8..60afd7aec0 100644 --- a/src/i18n/locales/en/embeddings.json +++ b/src/i18n/locales/en/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Unknown error", + "code_indexing_requires_workspace": "Code indexing requires an open workspace", + "indexing_started": "Code indexing started", + "indexing_failed": "Failed to start indexing: {{error}}", "authenticationFailed": "Failed to create embeddings: Authentication failed. Please check your API key.", "failedWithStatus": "Failed to create embeddings after {{attempts}} attempts: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "Failed to create embeddings after {{attempts}} attempts: {{errorMessage}}", diff --git a/src/i18n/locales/es/embeddings.json b/src/i18n/locales/es/embeddings.json index c2d7795362..54037567c1 100644 --- a/src/i18n/locales/es/embeddings.json +++ b/src/i18n/locales/es/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Error desconocido", + "code_indexing_requires_workspace": "La indexación de código requiere un espacio de trabajo abierto", + "indexing_started": "Indexación de código iniciada", + "indexing_failed": "No se pudo iniciar la indexación: {{error}}", "authenticationFailed": "No se pudieron crear las incrustaciones: Error de autenticación. Comprueba tu clave de API.", "failedWithStatus": "No se pudieron crear las incrustaciones después de {{attempts}} intentos: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "No se pudieron crear las incrustaciones después de {{attempts}} intentos: {{errorMessage}}", diff --git a/src/i18n/locales/fr/embeddings.json b/src/i18n/locales/fr/embeddings.json index 4dbbe6218b..4b73961825 100644 --- a/src/i18n/locales/fr/embeddings.json +++ b/src/i18n/locales/fr/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Erreur inconnue", + "code_indexing_requires_workspace": "L'indexation du code nécessite un espace de travail ouvert", + "indexing_started": "Indexation du code démarrée", + "indexing_failed": "Échec du démarrage de l'indexation : {{error}}", "authenticationFailed": "Échec de la création des embeddings : Échec de l'authentification. Veuillez vérifier votre clé API.", "failedWithStatus": "Échec de la création des embeddings après {{attempts}} tentatives : HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "Échec de la création des embeddings après {{attempts}} tentatives : {{errorMessage}}", diff --git a/src/i18n/locales/hi/embeddings.json b/src/i18n/locales/hi/embeddings.json index 312d42e69c..31e72facd4 100644 --- a/src/i18n/locales/hi/embeddings.json +++ b/src/i18n/locales/hi/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "अज्ञात त्रुटि", + "code_indexing_requires_workspace": "कोड इंडेक्सिंग के लिए एक खुला कार्यक्षेत्र आवश्यक है", + "indexing_started": "कोड इंडेक्सिंग शुरू हुई", + "indexing_failed": "इंडेक्सिंग शुरू करने में विफल: {{error}}", "authenticationFailed": "एम्बेडिंग बनाने में विफल: प्रमाणीकरण विफल। कृपया अपनी एपीआई कुंजी जांचें।", "failedWithStatus": "{{attempts}} प्रयासों के बाद एम्बेडिंग बनाने में विफल: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "{{attempts}} प्रयासों के बाद एम्बेडिंग बनाने में विफल: {{errorMessage}}", diff --git a/src/i18n/locales/id/embeddings.json b/src/i18n/locales/id/embeddings.json index abfa9cb354..ad6f81d6c7 100644 --- a/src/i18n/locales/id/embeddings.json +++ b/src/i18n/locales/id/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Error tidak dikenal", + "code_indexing_requires_workspace": "Pengindeksan kode memerlukan ruang kerja yang terbuka", + "indexing_started": "Pengindeksan kode dimulai", + "indexing_failed": "Gagal memulai pengindeksan: {{error}}", "authenticationFailed": "Gagal membuat embeddings: Autentikasi gagal. Silakan periksa API key Anda.", "failedWithStatus": "Gagal membuat embeddings setelah {{attempts}} percobaan: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "Gagal membuat embeddings setelah {{attempts}} percobaan: {{errorMessage}}", diff --git a/src/i18n/locales/it/embeddings.json b/src/i18n/locales/it/embeddings.json index 5bd7164886..cf7a6e332d 100644 --- a/src/i18n/locales/it/embeddings.json +++ b/src/i18n/locales/it/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Errore sconosciuto", + "code_indexing_requires_workspace": "L'indicizzazione del codice richiede un'area di lavoro aperta", + "indexing_started": "Indicizzazione del codice avviata", + "indexing_failed": "Avvio dell'indicizzazione non riuscito: {{error}}", "authenticationFailed": "Creazione degli embedding non riuscita: Autenticazione fallita. Controlla la tua chiave API.", "failedWithStatus": "Creazione degli embedding non riuscita dopo {{attempts}} tentativi: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "Creazione degli embedding non riuscita dopo {{attempts}} tentativi: {{errorMessage}}", diff --git a/src/i18n/locales/ja/embeddings.json b/src/i18n/locales/ja/embeddings.json index 862270a364..5adceb3759 100644 --- a/src/i18n/locales/ja/embeddings.json +++ b/src/i18n/locales/ja/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "不明なエラー", + "code_indexing_requires_workspace": "コードのインデックスを作成するには、開いているワークスペースが必要です", + "indexing_started": "コードのインデックス作成が開始されました", + "indexing_failed": "インデックス作成の開始に失敗しました: {{error}}", "authenticationFailed": "埋め込みの作成に失敗しました:認証に失敗しました。APIキーを確認してください。", "failedWithStatus": "{{attempts}}回試行しましたが、埋め込みの作成に失敗しました:HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "{{attempts}}回試行しましたが、埋め込みの作成に失敗しました:{{errorMessage}}", diff --git a/src/i18n/locales/ko/embeddings.json b/src/i18n/locales/ko/embeddings.json index 37877bfa97..26688e1aa9 100644 --- a/src/i18n/locales/ko/embeddings.json +++ b/src/i18n/locales/ko/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "알 수 없는 오류", + "code_indexing_requires_workspace": "코드 인덱싱을 위해서는 열려 있는 작업 공간이 필요합니다", + "indexing_started": "코드 인덱싱이 시작되었습니다", + "indexing_failed": "인덱싱 시작 실패: {{error}}", "authenticationFailed": "임베딩 생성 실패: 인증에 실패했습니다. API 키를 확인하세요.", "failedWithStatus": "{{attempts}}번 시도 후 임베딩 생성 실패: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "{{attempts}}번 시도 후 임베딩 생성 실패: {{errorMessage}}", diff --git a/src/i18n/locales/nl/embeddings.json b/src/i18n/locales/nl/embeddings.json index 7256b0973b..ba7a486e61 100644 --- a/src/i18n/locales/nl/embeddings.json +++ b/src/i18n/locales/nl/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Onbekende fout", + "code_indexing_requires_workspace": "Code-indexering vereist een open werkruimte", + "indexing_started": "Code-indexering gestart", + "indexing_failed": "Starten van indexering mislukt: {{error}}", "authenticationFailed": "Insluitingen maken mislukt: Authenticatie mislukt. Controleer je API-sleutel.", "failedWithStatus": "Insluitingen maken mislukt na {{attempts}} pogingen: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "Insluitingen maken mislukt na {{attempts}} pogingen: {{errorMessage}}", diff --git a/src/i18n/locales/pl/embeddings.json b/src/i18n/locales/pl/embeddings.json index c3e160869b..6cc4cadd1a 100644 --- a/src/i18n/locales/pl/embeddings.json +++ b/src/i18n/locales/pl/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Nieznany błąd", + "code_indexing_requires_workspace": "Indeksowanie kodu wymaga otwartego obszaru roboczego", + "indexing_started": "Rozpoczęto indeksowanie kodu", + "indexing_failed": "Nie udało się rozpocząć indeksowania: {{error}}", "authenticationFailed": "Nie udało się utworzyć osadzeń: Uwierzytelnianie nie powiodło się. Sprawdź swój klucz API.", "failedWithStatus": "Nie udało się utworzyć osadzeń po {{attempts}} próbach: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "Nie udało się utworzyć osadzeń po {{attempts}} próbach: {{errorMessage}}", diff --git a/src/i18n/locales/pt-BR/embeddings.json b/src/i18n/locales/pt-BR/embeddings.json index 6b97475265..9f371283b7 100644 --- a/src/i18n/locales/pt-BR/embeddings.json +++ b/src/i18n/locales/pt-BR/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Erro desconhecido", + "code_indexing_requires_workspace": "A indexação de código requer um espaço de trabalho aberto", + "indexing_started": "Indexação de código iniciada", + "indexing_failed": "Falha ao iniciar a indexação: {{error}}", "authenticationFailed": "Falha ao criar embeddings: Falha na autenticação. Verifique sua chave de API.", "failedWithStatus": "Falha ao criar embeddings após {{attempts}} tentativas: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "Falha ao criar embeddings após {{attempts}} tentativas: {{errorMessage}}", diff --git a/src/i18n/locales/ru/embeddings.json b/src/i18n/locales/ru/embeddings.json index c6143816e8..cfe50b6062 100644 --- a/src/i18n/locales/ru/embeddings.json +++ b/src/i18n/locales/ru/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Неизвестная ошибка", + "code_indexing_requires_workspace": "Для индексирования кода требуется открытое рабочее пространство", + "indexing_started": "Индексирование кода началось", + "indexing_failed": "Не удалось начать индексирование: {{error}}", "authenticationFailed": "Не удалось создать вложения: Ошибка аутентификации. Проверьте свой ключ API.", "failedWithStatus": "Не удалось создать вложения после {{attempts}} попыток: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "Не удалось создать вложения после {{attempts}} попыток: {{errorMessage}}", diff --git a/src/i18n/locales/tr/embeddings.json b/src/i18n/locales/tr/embeddings.json index 10ad965f0f..4e0e4852b1 100644 --- a/src/i18n/locales/tr/embeddings.json +++ b/src/i18n/locales/tr/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Bilinmeyen hata", + "code_indexing_requires_workspace": "Kod indeksleme için açık bir çalışma alanı gerekir", + "indexing_started": "Kod indeksleme başlatıldı", + "indexing_failed": "İndeksleme başlatılamadı: {{error}}", "authenticationFailed": "Gömülmeler oluşturulamadı: Kimlik doğrulama başarısız oldu. Lütfen API anahtarınızı kontrol edin.", "failedWithStatus": "{{attempts}} denemeden sonra gömülmeler oluşturulamadı: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "{{attempts}} denemeden sonra gömülmeler oluşturulamadı: {{errorMessage}}", diff --git a/src/i18n/locales/vi/embeddings.json b/src/i18n/locales/vi/embeddings.json index a533aaac07..b96862d8ab 100644 --- a/src/i18n/locales/vi/embeddings.json +++ b/src/i18n/locales/vi/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "Lỗi không xác định", + "code_indexing_requires_workspace": "Lập chỉ mục mã yêu cầu một không gian làm việc đang mở", + "indexing_started": "Đã bắt đầu lập chỉ mục mã", + "indexing_failed": "Không thể bắt đầu lập chỉ mục: {{error}}", "authenticationFailed": "Không thể tạo nhúng: Xác thực không thành công. Vui lòng kiểm tra khóa API của bạn.", "failedWithStatus": "Không thể tạo nhúng sau {{attempts}} lần thử: HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "Không thể tạo nhúng sau {{attempts}} lần thử: {{errorMessage}}", diff --git a/src/i18n/locales/zh-CN/embeddings.json b/src/i18n/locales/zh-CN/embeddings.json index dba5282844..f5d08d2e8a 100644 --- a/src/i18n/locales/zh-CN/embeddings.json +++ b/src/i18n/locales/zh-CN/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "未知错误", + "code_indexing_requires_workspace": "代码索引需要一个打开的工作区", + "indexing_started": "代码索引已开始", + "indexing_failed": "启动索引失败:{{error}}", "authenticationFailed": "创建嵌入失败:身份验证失败。请检查您的 API 密钥。", "failedWithStatus": "尝试 {{attempts}} 次后创建嵌入失败:HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "尝试 {{attempts}} 次后创建嵌入失败:{{errorMessage}}", diff --git a/src/i18n/locales/zh-TW/embeddings.json b/src/i18n/locales/zh-TW/embeddings.json index 71a5a482f2..8a213e8720 100644 --- a/src/i18n/locales/zh-TW/embeddings.json +++ b/src/i18n/locales/zh-TW/embeddings.json @@ -1,5 +1,8 @@ { "unknownError": "未知錯誤", + "code_indexing_requires_workspace": "程式碼索引需要一個開啟的工作區", + "indexing_started": "程式碼索引已開始", + "indexing_failed": "啟動索引失敗:{{error}}", "authenticationFailed": "建立內嵌失敗:驗證失敗。請檢查您的 API 金鑰。", "failedWithStatus": "嘗試 {{attempts}} 次後建立內嵌失敗:HTTP {{statusCode}} - {{errorMessage}}", "failedWithError": "嘗試 {{attempts}} 次後建立內嵌失敗:{{errorMessage}}",