fix: handle undefined codeIndexManager when no workspace is open (#5356)

This commit is contained in:
hannesrudolph 2025-07-04 13:44:53 -06:00
parent a92993504f
commit 030ad26532
19 changed files with 114 additions and 12 deletions

View file

@ -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) {

View file

@ -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}}",

View file

@ -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}}",

View file

@ -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}}",

View file

@ -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}}",

View file

@ -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}}",

View file

@ -1,5 +1,8 @@
{
"unknownError": "अज्ञात त्रुटि",
"code_indexing_requires_workspace": "कोड इंडेक्सिंग के लिए एक खुला कार्यक्षेत्र आवश्यक है",
"indexing_started": "कोड इंडेक्सिंग शुरू हुई",
"indexing_failed": "इंडेक्सिंग शुरू करने में विफल: {{error}}",
"authenticationFailed": "एम्बेडिंग बनाने में विफल: प्रमाणीकरण विफल। कृपया अपनी एपीआई कुंजी जांचें।",
"failedWithStatus": "{{attempts}} प्रयासों के बाद एम्बेडिंग बनाने में विफल: HTTP {{statusCode}} - {{errorMessage}}",
"failedWithError": "{{attempts}} प्रयासों के बाद एम्बेडिंग बनाने में विफल: {{errorMessage}}",

View file

@ -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}}",

View file

@ -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}}",

View file

@ -1,5 +1,8 @@
{
"unknownError": "不明なエラー",
"code_indexing_requires_workspace": "コードのインデックスを作成するには、開いているワークスペースが必要です",
"indexing_started": "コードのインデックス作成が開始されました",
"indexing_failed": "インデックス作成の開始に失敗しました: {{error}}",
"authenticationFailed": "埋め込みの作成に失敗しました認証に失敗しました。APIキーを確認してください。",
"failedWithStatus": "{{attempts}}回試行しましたが、埋め込みの作成に失敗しましたHTTP {{statusCode}} - {{errorMessage}}",
"failedWithError": "{{attempts}}回試行しましたが、埋め込みの作成に失敗しました:{{errorMessage}}",

View file

@ -1,5 +1,8 @@
{
"unknownError": "알 수 없는 오류",
"code_indexing_requires_workspace": "코드 인덱싱을 위해서는 열려 있는 작업 공간이 필요합니다",
"indexing_started": "코드 인덱싱이 시작되었습니다",
"indexing_failed": "인덱싱 시작 실패: {{error}}",
"authenticationFailed": "임베딩 생성 실패: 인증에 실패했습니다. API 키를 확인하세요.",
"failedWithStatus": "{{attempts}}번 시도 후 임베딩 생성 실패: HTTP {{statusCode}} - {{errorMessage}}",
"failedWithError": "{{attempts}}번 시도 후 임베딩 생성 실패: {{errorMessage}}",

View file

@ -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}}",

View file

@ -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}}",

View file

@ -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}}",

View file

@ -1,5 +1,8 @@
{
"unknownError": "Неизвестная ошибка",
"code_indexing_requires_workspace": "Для индексирования кода требуется открытое рабочее пространство",
"indexing_started": "Индексирование кода началось",
"indexing_failed": "Не удалось начать индексирование: {{error}}",
"authenticationFailed": "Не удалось создать вложения: Ошибка аутентификации. Проверьте свой ключ API.",
"failedWithStatus": "Не удалось создать вложения после {{attempts}} попыток: HTTP {{statusCode}} - {{errorMessage}}",
"failedWithError": "Не удалось создать вложения после {{attempts}} попыток: {{errorMessage}}",

View file

@ -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}}",

View file

@ -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}}",

View file

@ -1,5 +1,8 @@
{
"unknownError": "未知错误",
"code_indexing_requires_workspace": "代码索引需要一个打开的工作区",
"indexing_started": "代码索引已开始",
"indexing_failed": "启动索引失败:{{error}}",
"authenticationFailed": "创建嵌入失败:身份验证失败。请检查您的 API 密钥。",
"failedWithStatus": "尝试 {{attempts}} 次后创建嵌入失败HTTP {{statusCode}} - {{errorMessage}}",
"failedWithError": "尝试 {{attempts}} 次后创建嵌入失败:{{errorMessage}}",

View file

@ -1,5 +1,8 @@
{
"unknownError": "未知錯誤",
"code_indexing_requires_workspace": "程式碼索引需要一個開啟的工作區",
"indexing_started": "程式碼索引已開始",
"indexing_failed": "啟動索引失敗:{{error}}",
"authenticationFailed": "建立內嵌失敗:驗證失敗。請檢查您的 API 金鑰。",
"failedWithStatus": "嘗試 {{attempts}} 次後建立內嵌失敗HTTP {{statusCode}} - {{errorMessage}}",
"failedWithError": "嘗試 {{attempts}} 次後建立內嵌失敗:{{errorMessage}}",