From 08ae3c9551f6dd5554f1f44c36473174779436ba Mon Sep 17 00:00:00 2001 From: Radu Date: Fri, 29 Nov 2024 09:55:30 +0200 Subject: [PATCH 1/8] Add remove settings command --- docs_espressif/en/installation.rst | 23 ++++++ package.json | 5 ++ package.nls.es.json | 1 + package.nls.json | 1 + package.nls.ru.json | 1 + package.nls.zh-CN.json | 1 + src/extension.ts | 115 +++++++++++++++++++++++++++++ 7 files changed, 147 insertions(+) diff --git a/docs_espressif/en/installation.rst b/docs_espressif/en/installation.rst index bd70cd799..0b7092f84 100644 --- a/docs_espressif/en/installation.rst +++ b/docs_espressif/en/installation.rst @@ -59,3 +59,26 @@ After installing Visual Studio Code you need to install the ESP-IDF extension fo .. warning:: Check the :ref:`Troubleshooting ` section if you have any issues during installation. + +Uninstall ESP-IDF VS Code Extension +=========================== + +To uninstall the ESP-IDF VS Code extension, follow these steps: + +1. Open Command Palette (F1) and type **ESP-IDF: Remove All ESP-IDF Settings** and select the command to remove all ESP-IDF settings. + +2. Navigate to **View** > **Extensions** or use the keyboard shortcut :kbd:`Ctrl+Shift+X` in Windows/Linux or :kbd:`Shift+⌘+X` in MacOS. + +3. Search for `ESP-IDF` and click on the **Uninstall** button. + +4. Ensure you remove the following folders: + + - Go to your `${VSCODE_EXTENSION_DIR}` and delete the ESP-IDF plugin folder. + + - `${VSCODE_EXTENSION_DIR}` is the location of the extension: + - **Windows**: `%USERPROFILE%\.vscode\extensions\espressif.esp-idf-extension-VERSION\` + - **MacOS/Linux**: `$HOME/.vscode/extensions/espressif.esp-idf-extension-VERSION/` + +.. note:: + + Make sure to replace `VERSION` with the actual version number of the ESP-IDF extension installed. \ No newline at end of file diff --git a/package.json b/package.json index ec9acf3bd..9a7095874 100644 --- a/package.json +++ b/package.json @@ -1198,6 +1198,11 @@ } ], "commands": [ + { + "command": "espIdf.removeEspIdfSettings", + "title": "espIdf.removeEspIdfSettings.title", + "category": "ESP-IDF" + }, { "command": "espIdf.openWalkthrough", "title": "ESP-IDF: Open Get Started Walkthrough" diff --git a/package.nls.es.json b/package.nls.es.json index 49d9940bb..089929038 100644 --- a/package.nls.es.json +++ b/package.nls.es.json @@ -94,6 +94,7 @@ "esp_idf.tmoScaleFactor.description": "Factor de escala para el tiempo de espera de gdb [predeterminado:1]", "esp_idf.verifyAppBinBeforeDebug.description": "Verificar binarios de la aplicación antes de depurar", "espIdf.searchError.title": "ESP-IDF: Sugerencia de error de búsqueda", + "espIdf.removeEspIdfSettings.title": "Eliminar configuración de ESP-IDF", "idf.flashType.description": "Método de flasheo del dispositivo, UART o JTag", "idf.wssPort.description": "Puerto del servidor de socket web para Core Dump o GDB Stub", "openocd.tcl.host.description": "Host para conexión tcl de Openocd", diff --git a/package.nls.json b/package.nls.json index 2f36806f4..d51df7176 100644 --- a/package.nls.json +++ b/package.nls.json @@ -98,6 +98,7 @@ "idf.wssPort.description": "WebSocket server port for Core Dump or GDB Stub", "openocd.tcl.host.description": "Host for OpenOCD TCL Connection", "openocd.tcl.port.description": "Port for OpenOCD TCL Connection", + "espIdf.removeEspIdfSettings.title": "Remove ESP-IDF Settings", "param.adapterTargetName": "Target name for ESP-IDF Debug Adapter", "param.buildPath": "Name of CMake build directory", "param.cmakeCompilerArgs": "Arguments for CMake compilation task", diff --git a/package.nls.ru.json b/package.nls.ru.json index 3d493f590..29f9177ec 100644 --- a/package.nls.ru.json +++ b/package.nls.ru.json @@ -94,6 +94,7 @@ "esp_idf.tmoScaleFactor.description": "Масштабный коэффициент для тайм-аута GDB [по умолчанию: 1]", "esp_idf.verifyAppBinBeforeDebug.description": "Проверьте двоичные файлы приложения перед отладкой", "espIdf.searchError.title": "ESP-IDF: Подсказка об ошибке поиска", + "espIdf.removeEspIdfSettings.title": "Удалить настройки ESP-IDF", "idf.flashType.description": "Метод прошивки устройства, UART или JTag", "idf.wssPort.description": "Порт веб-сокет-сервера для дампа ядра или заглушки GDB", "openocd.tcl.host.description": "Хост для подключения openocd tcl", diff --git a/package.nls.zh-CN.json b/package.nls.zh-CN.json index 8d34cd36c..fef07cdfd 100644 --- a/package.nls.zh-CN.json +++ b/package.nls.zh-CN.json @@ -99,6 +99,7 @@ "openocd.tcl.host.description": "用于 OpenOCD TCL 连接的主机", "openocd.tcl.port.description": "用于 OpenOCD TCL 连接的端口", "param.adapterTargetName": "为 ESP-IDF 调试适配器指定目标", + "espIdf.removeEspIdfSettings.title": "删除 ESP-IDF 设置", "param.buildPath": "CMake 构建目录的名称", "param.cmakeCompilerArgs": "用于 CMake 编译任务的参数", "param.coveredDarkTheme": "深色主题下 ESP-IDF 覆盖率报告中覆盖行的背景颜色", diff --git a/src/extension.ts b/src/extension.ts index 02a1d0b61..017639ec7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3728,6 +3728,121 @@ export async function activate(context: vscode.ExtensionContext) { ); checkAndNotifyMissingCompileCommands(); + + // Remove ESP-IDF settings + context.subscriptions.push( + vscode.commands.registerCommand('espIdf.removeEspIdfSettings', removeEspIdfSettings) + ); +} + +async function removeEspIdfSettings() { + const config = vscode.workspace.getConfiguration(); + const settingsToDelete: string[] = []; + + // Helper function to recursively find idf settings + function findIdfSettings(obj: any, prefix: string = '') { + if (typeof obj === 'object' && obj !== null) { + Object.keys(obj).forEach(key => { + const fullPath = prefix ? `${prefix}.${key}` : key; + if (fullPath.startsWith('idf.') || fullPath.startsWith('esp.')) { + settingsToDelete.push(fullPath); + } + findIdfSettings(obj[key], fullPath); + }); + } + } + + // Get all settings directly from configuration + const allSettings = config.inspect(''); + // Check values saved in each scope + if (allSettings?.globalValue) { + findIdfSettings(allSettings.globalValue); + } + if (allSettings?.workspaceValue) { + findIdfSettings(allSettings.workspaceValue); + } + + if (allSettings?.workspaceFolderValue) { + findIdfSettings(allSettings.workspaceFolderValue); + } + + if(settingsToDelete.length === 0) { + vscode.window.showInformationMessage("No ESP-IDF settings found to remove."); + return ; + } + + // Filter out any duplicate paths + const uniqueSettingsToDelete = [...new Set(settingsToDelete)]; + + // Ask user for confirmation + const message = 'Are you sure you want to remove all ESP-IDF settings? This will delete all idf.* configurations.'; + const result = await vscode.window.showWarningMessage( + message, + { + modal: true, + detail: `${uniqueSettingsToDelete.length} settings will be removed.` + }, + 'Yes', + 'No' + ); + + if (result !== 'Yes') { + return; + } + + try { + const message = 'Starting ESP-IDF settings cleanup...'; + OutputChannel.appendLineAndShow(message); + Logger.info(message); + + // Delete each setting + for (const setting of uniqueSettingsToDelete) { + try { + // Try to remove from each scope, but handle errors silently + // Global settings + try { + const inspection = config.inspect(setting); + if (inspection?.globalValue !== undefined) { + await config.update(setting, undefined, vscode.ConfigurationTarget.Global); + OutputChannel.appendLine(`Removed global setting: ${setting}`); + } + } catch (e) { + // Silently continue if we can't modify global settings + } + + // Workspace settings + try { + const inspection = config.inspect(setting); + if (inspection?.workspaceValue !== undefined) { + await config.update(setting, undefined, vscode.ConfigurationTarget.Workspace); + OutputChannel.appendLine(`Removed workspace setting: ${setting}`); + } + } catch (e) { + // Silently continue if we can't modify workspace settings + } + + // WorkspaceFolder settings + try { + const inspection = config.inspect(setting); + if (inspection?.workspaceFolderValue !== undefined) { + await config.update(setting, undefined, vscode.ConfigurationTarget.WorkspaceFolder); + OutputChannel.appendLine(`Removed workspace folder setting: ${setting}`); + } + } catch (e) { + // Silently continue if we can't modify workspace folder settings + } + } catch (settingError) { + OutputChannel.appendLine(`Warning: Could not fully remove setting ${setting}: ${settingError.message}`); + } + } + + OutputChannel.appendLineAndShow('ESP-IDF settings removed successfully.'); + } catch (error) { + const errorMessage = error instanceof Error ? error.message : String(error); + vscode.window.showErrorMessage(`Failed to remove settings: ${errorMessage}`); + OutputChannel.appendLineAndShow(`Error: ${errorMessage}`); + Logger.error(errorMessage, error, 'extension removeEspIdfSettings'); + } } function checkAndNotifyMissingCompileCommands() { From 7b907992ea8f83567f72603eadde03c15ba7ec18 Mon Sep 17 00:00:00 2001 From: Radu Date: Fri, 29 Nov 2024 10:35:11 +0200 Subject: [PATCH 2/8] Add translations --- l10n/bundle.l10n.es.json | 15 +++++- l10n/bundle.l10n.pt.json | 15 +++++- l10n/bundle.l10n.ru.json | 15 +++++- l10n/bundle.l10n.zh-CN.json | 15 +++++- src/extension.ts | 91 ++++++++++++++++++++++++++----------- 5 files changed, 121 insertions(+), 30 deletions(-) diff --git a/l10n/bundle.l10n.es.json b/l10n/bundle.l10n.es.json index bb3813687..18a984d50 100644 --- a/l10n/bundle.l10n.es.json +++ b/l10n/bundle.l10n.es.json @@ -196,5 +196,18 @@ "JTAG is soft-disabled ({0} is set to an odd value: {1}).": "JTAG está deshabilitado por software ({0} se ha establecido con un valor impar: {1}).", "JTAG selection may be affected by strapping configuration ({0} is set).": "La selección de JTAG puede verse afectada por la configuración de strapping (se ha establecido {0}).", "JTAG is not disabled.": "JTAG no está deshabilitado.", - "IDF Version >= 4.3.x required to have eFuse view": "Se requiere IDF Versión >= 4.3.x para tener vista de e-fuse" + "IDF Version >= 4.3.x required to have eFuse view": "Se requiere IDF Versión >= 4.3.x para tener vista de e-fuse", + "No ESP-IDF settings found to remove.": "No se encontró ninguna configuración de ESP-IDF para eliminar.", + "Are you sure you want to remove all ESP-IDF settings? This will delete all idf.* configurations.": "¿Está seguro de que desea eliminar todas las configuraciones de ESP-IDF? Esto eliminará todas las configuraciones idf.*.", + "{0} settings will be removed.": "{0} configuraciones serán eliminadas.", + "Yes": "Sí", + "No": "No", + "Starting ESP-IDF settings cleanup...": "Iniciando limpieza de configuraciones ESP-IDF...", + "Removed global setting: {0}": "Configuración global eliminada: {0}", + "Removed workspace setting: {0}": "Configuración del espacio de trabajo eliminada: {0}", + "Removed workspace folder setting: {0}": "Configuración de la carpeta del espacio de trabajo eliminada: {0}", + "Warning: Could not fully remove setting {0}: {1}": "Advertencia: No se pudo eliminar completamente la configuración {0}: {1}", + "ESP-IDF settings removed successfully.": "Configuraciones de ESP-IDF eliminadas exitosamente.", + "Failed to remove settings: {0}": "Error al eliminar las configuraciones: {0}", + "Error: {0}": "Error: {0}" } diff --git a/l10n/bundle.l10n.pt.json b/l10n/bundle.l10n.pt.json index 46c4f25b7..16bd4be5c 100644 --- a/l10n/bundle.l10n.pt.json +++ b/l10n/bundle.l10n.pt.json @@ -196,5 +196,18 @@ "JTAG is soft-disabled ({0} is set to an odd value: {1}).": "JTAG está desativado por software ({0} está definido com um valor ímpar: {1}).", "JTAG selection may be affected by strapping configuration ({0} is set).": "A seleção JTAG pode ser afetada pela configuração de strapping ({0} está definido).", "JTAG is not disabled.": "JTAG não está desativado.", - "IDF Version >= 4.3.x required to have eFuse view": "IDF Versão >= 4.3.x necessária para ter visualização de e-fuse" + "IDF Version >= 4.3.x required to have eFuse view": "IDF Versão >= 4.3.x necessária para ter visualização de e-fuse", + "No ESP-IDF settings found to remove.": "Nenhuma configuração do ESP-IDF encontrada para remover.", + "Are you sure you want to remove all ESP-IDF settings? This will delete all idf.* configurations.": "Tem certeza que deseja remover todas as configurações do ESP-IDF? Isso excluirá todas as configurações idf.*.", + "{0} settings will be removed.": "{0} configurações serão removidas.", + "Yes": "Sim", + "No": "Não", + "Starting ESP-IDF settings cleanup...": "Iniciando limpeza das configurações ESP-IDF...", + "Removed global setting: {0}": "Configuração global removida: {0}", + "Removed workspace setting: {0}": "Configuração do espaço de trabalho removida: {0}", + "Removed workspace folder setting: {0}": "Configuração da pasta do espaço de trabalho removida: {0}", + "Warning: Could not fully remove setting {0}: {1}": "Aviso: Não foi possível remover completamente a configuração {0}: {1}", + "ESP-IDF settings removed successfully.": "Configurações ESP-IDF removidas com sucesso.", + "Failed to remove settings: {0}": "Falha ao remover configurações: {0}", + "Error: {0}": "Erro: {0}" } diff --git a/l10n/bundle.l10n.ru.json b/l10n/bundle.l10n.ru.json index b29c8b76b..822528c52 100644 --- a/l10n/bundle.l10n.ru.json +++ b/l10n/bundle.l10n.ru.json @@ -196,5 +196,18 @@ "JTAG is soft-disabled ({0} is set to an odd value: {1}).": "JTAG программно отключен ({0} установлен на нечетное значение: {1}).", "JTAG selection may be affected by strapping configuration ({0} is set).": "Выбор JTAG может зависеть от конфигурации стрэппинга (установлен {0}).", "JTAG is not disabled.": "JTAG не отключен.", - "IDF Version >= 4.3.x required to have eFuse view": "Требуется IDF версии >= 4.3.x для просмотра e-fuse" + "IDF Version >= 4.3.x required to have eFuse view": "Требуется IDF версии >= 4.3.x для просмотра e-fuse", + "No ESP-IDF settings found to remove.": "Настройки ESP-IDF для удаления не найдены.", + "Are you sure you want to remove all ESP-IDF settings? This will delete all idf.* configurations.": "Вы уверены, что хотите удалить все настройки ESP-IDF? Это удалит все конфигурации idf.*.", + "{0} settings will be removed.": "{0} настроек будет удалено.", + "Yes": "Да", + "No": "Нет", + "Starting ESP-IDF settings cleanup...": "Начинается очистка настроек ESP-IDF...", + "Removed global setting: {0}": "Удалена глобальная настройка: {0}", + "Removed workspace setting: {0}": "Удалена настройка рабочего пространства: {0}", + "Removed workspace folder setting: {0}": "Удалена настройка папки рабочего пространства: {0}", + "Warning: Could not fully remove setting {0}: {1}": "Предупреждение: Не удалось полностью удалить настройку {0}: {1}", + "ESP-IDF settings removed successfully.": "Настройки ESP-IDF успешно удалены.", + "Failed to remove settings: {0}": "Не удалось удалить настройки: {0}", + "Error: {0}": "Ошибка: {0}" } diff --git a/l10n/bundle.l10n.zh-CN.json b/l10n/bundle.l10n.zh-CN.json index 16faea696..e29fcc4f3 100644 --- a/l10n/bundle.l10n.zh-CN.json +++ b/l10n/bundle.l10n.zh-CN.json @@ -196,5 +196,18 @@ "JTAG is soft-disabled ({0} is set to an odd value: {1}).": "JTAG 调试功能已被软禁用({0} 设置为奇数值:{1})。", "JTAG selection may be affected by strapping configuration ({0} is set).": "JTAG 选择可能受 strapping 配置的影响(已设置 {0})。", "JTAG is not disabled.": "JTAG 未被禁用。", - "IDF Version >= 4.3.x required to have eFuse view": "需要使用 v4.3 及以上的 IDF 版本才能查看 eFuse" + "IDF Version >= 4.3.x required to have eFuse view": "需要使用 v4.3 及以上的 IDF 版本才能查看 eFuse", + "No ESP-IDF settings found to remove.": "未找到要删除的ESP-IDF设置。", + "Are you sure you want to remove all ESP-IDF settings? This will delete all idf.* configurations.": "您确定要删除所有ESP-IDF设置吗?这将删除所有idf.*配置。", + "{0} settings will be removed.": "{0}个设置将被删除。", + "Yes": "是", + "No": "否", + "Starting ESP-IDF settings cleanup...": "正在开始清理ESP-IDF设置...", + "Removed global setting: {0}": "已删除全局设置:{0}", + "Removed workspace setting: {0}": "已删除工作区设置:{0}", + "Removed workspace folder setting: {0}": "已删除工作区文件夹设置:{0}", + "Warning: Could not fully remove setting {0}: {1}": "警告:无法完全删除设置 {0}:{1}", + "ESP-IDF settings removed successfully.": "ESP-IDF设置已成功删除。", + "Failed to remove settings: {0}": "删除设置失败:{0}", + "Error: {0}": "错误:{0}" } diff --git a/src/extension.ts b/src/extension.ts index 017639ec7..9bbc86e4f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3731,7 +3731,10 @@ export async function activate(context: vscode.ExtensionContext) { // Remove ESP-IDF settings context.subscriptions.push( - vscode.commands.registerCommand('espIdf.removeEspIdfSettings', removeEspIdfSettings) + vscode.commands.registerCommand( + "espIdf.removeEspIdfSettings", + removeEspIdfSettings + ) ); } @@ -3740,11 +3743,11 @@ async function removeEspIdfSettings() { const settingsToDelete: string[] = []; // Helper function to recursively find idf settings - function findIdfSettings(obj: any, prefix: string = '') { - if (typeof obj === 'object' && obj !== null) { - Object.keys(obj).forEach(key => { + function findIdfSettings(obj: any, prefix: string = "") { + if (typeof obj === "object" && obj !== null) { + Object.keys(obj).forEach((key) => { const fullPath = prefix ? `${prefix}.${key}` : key; - if (fullPath.startsWith('idf.') || fullPath.startsWith('esp.')) { + if (fullPath.startsWith("idf.") || fullPath.startsWith("esp.")) { settingsToDelete.push(fullPath); } findIdfSettings(obj[key], fullPath); @@ -3753,7 +3756,7 @@ async function removeEspIdfSettings() { } // Get all settings directly from configuration - const allSettings = config.inspect(''); + const allSettings = config.inspect(""); // Check values saved in each scope if (allSettings?.globalValue) { findIdfSettings(allSettings.globalValue); @@ -3766,32 +3769,39 @@ async function removeEspIdfSettings() { findIdfSettings(allSettings.workspaceFolderValue); } - if(settingsToDelete.length === 0) { - vscode.window.showInformationMessage("No ESP-IDF settings found to remove."); - return ; + if (settingsToDelete.length === 0) { + vscode.window.showInformationMessage( + vscode.l10n.t("No ESP-IDF settings found to remove.") + ); + return; } // Filter out any duplicate paths const uniqueSettingsToDelete = [...new Set(settingsToDelete)]; // Ask user for confirmation - const message = 'Are you sure you want to remove all ESP-IDF settings? This will delete all idf.* configurations.'; + const message = vscode.l10n.t( + "Are you sure you want to remove all ESP-IDF settings? This will delete all idf.* configurations." + ); const result = await vscode.window.showWarningMessage( message, { modal: true, - detail: `${uniqueSettingsToDelete.length} settings will be removed.` + detail: vscode.l10n.t( + "{0} settings will be removed.", + uniqueSettingsToDelete.length + ), }, - 'Yes', - 'No' + vscode.l10n.t("Yes"), + vscode.l10n.t("No") ); - if (result !== 'Yes') { + if (result !== vscode.l10n.t("Yes")) { return; } try { - const message = 'Starting ESP-IDF settings cleanup...'; + const message = vscode.l10n.t("Starting ESP-IDF settings cleanup..."); OutputChannel.appendLineAndShow(message); Logger.info(message); @@ -3803,8 +3813,14 @@ async function removeEspIdfSettings() { try { const inspection = config.inspect(setting); if (inspection?.globalValue !== undefined) { - await config.update(setting, undefined, vscode.ConfigurationTarget.Global); - OutputChannel.appendLine(`Removed global setting: ${setting}`); + await config.update( + setting, + undefined, + vscode.ConfigurationTarget.Global + ); + OutputChannel.appendLine( + vscode.l10n.t("Removed global setting: {0}", setting) + ); } } catch (e) { // Silently continue if we can't modify global settings @@ -3814,8 +3830,14 @@ async function removeEspIdfSettings() { try { const inspection = config.inspect(setting); if (inspection?.workspaceValue !== undefined) { - await config.update(setting, undefined, vscode.ConfigurationTarget.Workspace); - OutputChannel.appendLine(`Removed workspace setting: ${setting}`); + await config.update( + setting, + undefined, + vscode.ConfigurationTarget.Workspace + ); + OutputChannel.appendLine( + vscode.l10n.t("Removed workspace setting: {0}", setting) + ); } } catch (e) { // Silently continue if we can't modify workspace settings @@ -3825,23 +3847,40 @@ async function removeEspIdfSettings() { try { const inspection = config.inspect(setting); if (inspection?.workspaceFolderValue !== undefined) { - await config.update(setting, undefined, vscode.ConfigurationTarget.WorkspaceFolder); - OutputChannel.appendLine(`Removed workspace folder setting: ${setting}`); + await config.update( + setting, + undefined, + vscode.ConfigurationTarget.WorkspaceFolder + ); + OutputChannel.appendLine( + vscode.l10n.t("Removed workspace folder setting: {0}", setting) + ); } } catch (e) { // Silently continue if we can't modify workspace folder settings } } catch (settingError) { - OutputChannel.appendLine(`Warning: Could not fully remove setting ${setting}: ${settingError.message}`); + OutputChannel.appendLine( + vscode.l10n.t( + "Warning: Could not fully remove setting {0}: {1}", + setting, + settingError.message + ) + ); } } - OutputChannel.appendLineAndShow('ESP-IDF settings removed successfully.'); + OutputChannel.appendLineAndShow( + vscode.l10n.t("ESP-IDF settings removed successfully.") + ); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); - vscode.window.showErrorMessage(`Failed to remove settings: ${errorMessage}`); - OutputChannel.appendLineAndShow(`Error: ${errorMessage}`); - Logger.error(errorMessage, error, 'extension removeEspIdfSettings'); + vscode.window.showErrorMessage( + vscode.l10n.t("Failed to remove settings: {0}"), + errorMessage + ); + OutputChannel.appendLineAndShow(vscode.l10n.t("Error: {0}"), errorMessage); + Logger.error(errorMessage, error, "extension removeEspIdfSettings"); } } From 17f8a1a4214c7a98b629c10197dee09a0ab91c3a Mon Sep 17 00:00:00 2001 From: Radu Date: Fri, 29 Nov 2024 11:14:37 +0200 Subject: [PATCH 3/8] Fix translation title --- package.json | 2 +- package.nls.pt.json | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 9a7095874..5f7cb6ff1 100644 --- a/package.json +++ b/package.json @@ -1200,7 +1200,7 @@ "commands": [ { "command": "espIdf.removeEspIdfSettings", - "title": "espIdf.removeEspIdfSettings.title", + "title": "%espIdf.removeEspIdfSettings.title%", "category": "ESP-IDF" }, { diff --git a/package.nls.pt.json b/package.nls.pt.json index 40ed77072..afe87f9fc 100644 --- a/package.nls.pt.json +++ b/package.nls.pt.json @@ -93,6 +93,8 @@ "esp_idf.initGdbCommands.description": "Um ou mais comandos GDB a serem executados para configurar o depurador subjacente. ", "esp_idf.tmoScaleFactor.description": "Fator de escala para tempo limite do gdb [padrão: 1]", "esp_idf.verifyAppBinBeforeDebug.description": "Verifique os binários do aplicativo antes da depuração", + "espIdf.searchError.title": "ESP-IDF: Buscar Dica de Erro", + "espIdf.removeEspIdfSettings.title": "Remover Configurações ESP-IDF", "idf.flashType.description": "Método flash do dispositivo, UART ou JTag", "idf.wssPort.description": "Porta do servidor Web Socket para Core Dump ou GDB Stub", "openocd.tcl.host.description": "Host para conexão OpenOCD tcl", From 2ea665e9a596d11a1c6dfcb20e0d04a1051d94c4 Mon Sep 17 00:00:00 2001 From: Radu Date: Fri, 29 Nov 2024 11:53:08 +0200 Subject: [PATCH 4/8] Fix documentation sub-header --- docs_espressif/en/installation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs_espressif/en/installation.rst b/docs_espressif/en/installation.rst index 0b7092f84..9ff27efbc 100644 --- a/docs_espressif/en/installation.rst +++ b/docs_espressif/en/installation.rst @@ -61,7 +61,7 @@ After installing Visual Studio Code you need to install the ESP-IDF extension fo Check the :ref:`Troubleshooting ` section if you have any issues during installation. Uninstall ESP-IDF VS Code Extension -=========================== +-------------------------------- To uninstall the ESP-IDF VS Code extension, follow these steps: From 75304b7a523b70168876e44f58e31c6d1aab27f2 Mon Sep 17 00:00:00 2001 From: Radu Date: Mon, 2 Dec 2024 11:45:48 +0200 Subject: [PATCH 5/8] fix format documentation --- docs_espressif/en/installation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs_espressif/en/installation.rst b/docs_espressif/en/installation.rst index 9ff27efbc..af4e85db6 100644 --- a/docs_espressif/en/installation.rst +++ b/docs_espressif/en/installation.rst @@ -61,7 +61,7 @@ After installing Visual Studio Code you need to install the ESP-IDF extension fo Check the :ref:`Troubleshooting ` section if you have any issues during installation. Uninstall ESP-IDF VS Code Extension --------------------------------- +------------------------------------- To uninstall the ESP-IDF VS Code extension, follow these steps: From b87b294de64ce04b2de4d91989bc4985b28888c0 Mon Sep 17 00:00:00 2001 From: Radu Date: Thu, 16 Jan 2025 09:51:12 +0200 Subject: [PATCH 6/8] Restructure code as requested --- src/extension.ts | 115 +++++++++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 58 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 9bbc86e4f..c4fad0909 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3757,16 +3757,18 @@ async function removeEspIdfSettings() { // Get all settings directly from configuration const allSettings = config.inspect(""); - // Check values saved in each scope - if (allSettings?.globalValue) { - findIdfSettings(allSettings.globalValue); - } - if (allSettings?.workspaceValue) { - findIdfSettings(allSettings.workspaceValue); - } - if (allSettings?.workspaceFolderValue) { - findIdfSettings(allSettings.workspaceFolderValue); + // Check values saved in each scope using a simple loop + const scopeValues = [ + allSettings?.globalValue, + allSettings?.workspaceValue, + allSettings?.workspaceFolderValue, + ]; + + for (const value of scopeValues) { + if (value) { + findIdfSettings(value); + } } if (settingsToDelete.length === 0) { @@ -3800,64 +3802,61 @@ async function removeEspIdfSettings() { return; } + // Helper function to remove setting from a specific scope + async function removeSettingFromScope( + setting: string, + target: vscode.ConfigurationTarget, + inspectionValue: any, + scopeDescription: string + ) { + try { + if (inspectionValue !== undefined) { + await config.update(setting, undefined, target); + OutputChannel.appendLine( + vscode.l10n.t(`Removed ${scopeDescription} setting: {0}`, setting) + ); + } + } catch (e) { + // Silently continue if we can't modify settings for this scope + } + } + try { const message = vscode.l10n.t("Starting ESP-IDF settings cleanup..."); OutputChannel.appendLineAndShow(message); Logger.info(message); + const scopeConfigs = [ + { + target: vscode.ConfigurationTarget.Global, + property: "globalValue", + description: "global", + }, + { + target: vscode.ConfigurationTarget.Workspace, + property: "workspaceValue", + description: "workspace", + }, + { + target: vscode.ConfigurationTarget.WorkspaceFolder, + property: "workspaceFolderValue", + description: "workspace folder", + }, + ]; + // Delete each setting for (const setting of uniqueSettingsToDelete) { try { - // Try to remove from each scope, but handle errors silently - // Global settings - try { - const inspection = config.inspect(setting); - if (inspection?.globalValue !== undefined) { - await config.update( - setting, - undefined, - vscode.ConfigurationTarget.Global - ); - OutputChannel.appendLine( - vscode.l10n.t("Removed global setting: {0}", setting) - ); - } - } catch (e) { - // Silently continue if we can't modify global settings - } + const inspection = config.inspect(setting); - // Workspace settings - try { - const inspection = config.inspect(setting); - if (inspection?.workspaceValue !== undefined) { - await config.update( - setting, - undefined, - vscode.ConfigurationTarget.Workspace - ); - OutputChannel.appendLine( - vscode.l10n.t("Removed workspace setting: {0}", setting) - ); - } - } catch (e) { - // Silently continue if we can't modify workspace settings - } - - // WorkspaceFolder settings - try { - const inspection = config.inspect(setting); - if (inspection?.workspaceFolderValue !== undefined) { - await config.update( - setting, - undefined, - vscode.ConfigurationTarget.WorkspaceFolder - ); - OutputChannel.appendLine( - vscode.l10n.t("Removed workspace folder setting: {0}", setting) - ); - } - } catch (e) { - // Silently continue if we can't modify workspace folder settings + // Try to remove from each scope + for (const { target, property, description } of scopeConfigs) { + await removeSettingFromScope( + setting, + target, + inspection?.[property], + description + ); } } catch (settingError) { OutputChannel.appendLine( From 7570f35fac10edee5f8aba8ae3d0db46485eab2c Mon Sep 17 00:00:00 2001 From: Radu Date: Thu, 16 Jan 2025 10:00:15 +0200 Subject: [PATCH 7/8] Move code out of extension.ts --- src/extension.ts | 146 +--------------------------------------------- src/uninstall.ts | 148 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 145 deletions(-) create mode 100644 src/uninstall.ts diff --git a/src/extension.ts b/src/extension.ts index c4fad0909..3088d7683 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -173,6 +173,7 @@ import { IDFWebCommandKeys, } from "./cmdTreeView/cmdStore"; import { IdfSetup } from "./views/setup/types"; +import { removeEspIdfSettings } from "./uninstall"; // Global variables shared by commands let workspaceRoot: vscode.Uri; @@ -3738,151 +3739,6 @@ export async function activate(context: vscode.ExtensionContext) { ); } -async function removeEspIdfSettings() { - const config = vscode.workspace.getConfiguration(); - const settingsToDelete: string[] = []; - - // Helper function to recursively find idf settings - function findIdfSettings(obj: any, prefix: string = "") { - if (typeof obj === "object" && obj !== null) { - Object.keys(obj).forEach((key) => { - const fullPath = prefix ? `${prefix}.${key}` : key; - if (fullPath.startsWith("idf.") || fullPath.startsWith("esp.")) { - settingsToDelete.push(fullPath); - } - findIdfSettings(obj[key], fullPath); - }); - } - } - - // Get all settings directly from configuration - const allSettings = config.inspect(""); - - // Check values saved in each scope using a simple loop - const scopeValues = [ - allSettings?.globalValue, - allSettings?.workspaceValue, - allSettings?.workspaceFolderValue, - ]; - - for (const value of scopeValues) { - if (value) { - findIdfSettings(value); - } - } - - if (settingsToDelete.length === 0) { - vscode.window.showInformationMessage( - vscode.l10n.t("No ESP-IDF settings found to remove.") - ); - return; - } - - // Filter out any duplicate paths - const uniqueSettingsToDelete = [...new Set(settingsToDelete)]; - - // Ask user for confirmation - const message = vscode.l10n.t( - "Are you sure you want to remove all ESP-IDF settings? This will delete all idf.* configurations." - ); - const result = await vscode.window.showWarningMessage( - message, - { - modal: true, - detail: vscode.l10n.t( - "{0} settings will be removed.", - uniqueSettingsToDelete.length - ), - }, - vscode.l10n.t("Yes"), - vscode.l10n.t("No") - ); - - if (result !== vscode.l10n.t("Yes")) { - return; - } - - // Helper function to remove setting from a specific scope - async function removeSettingFromScope( - setting: string, - target: vscode.ConfigurationTarget, - inspectionValue: any, - scopeDescription: string - ) { - try { - if (inspectionValue !== undefined) { - await config.update(setting, undefined, target); - OutputChannel.appendLine( - vscode.l10n.t(`Removed ${scopeDescription} setting: {0}`, setting) - ); - } - } catch (e) { - // Silently continue if we can't modify settings for this scope - } - } - - try { - const message = vscode.l10n.t("Starting ESP-IDF settings cleanup..."); - OutputChannel.appendLineAndShow(message); - Logger.info(message); - - const scopeConfigs = [ - { - target: vscode.ConfigurationTarget.Global, - property: "globalValue", - description: "global", - }, - { - target: vscode.ConfigurationTarget.Workspace, - property: "workspaceValue", - description: "workspace", - }, - { - target: vscode.ConfigurationTarget.WorkspaceFolder, - property: "workspaceFolderValue", - description: "workspace folder", - }, - ]; - - // Delete each setting - for (const setting of uniqueSettingsToDelete) { - try { - const inspection = config.inspect(setting); - - // Try to remove from each scope - for (const { target, property, description } of scopeConfigs) { - await removeSettingFromScope( - setting, - target, - inspection?.[property], - description - ); - } - } catch (settingError) { - OutputChannel.appendLine( - vscode.l10n.t( - "Warning: Could not fully remove setting {0}: {1}", - setting, - settingError.message - ) - ); - } - } - - OutputChannel.appendLineAndShow( - vscode.l10n.t("ESP-IDF settings removed successfully.") - ); - } catch (error) { - const errorMessage = error instanceof Error ? error.message : String(error); - vscode.window.showErrorMessage( - vscode.l10n.t("Failed to remove settings: {0}"), - errorMessage - ); - OutputChannel.appendLineAndShow(vscode.l10n.t("Error: {0}"), errorMessage); - Logger.error(errorMessage, error, "extension removeEspIdfSettings"); - } -} - function checkAndNotifyMissingCompileCommands() { if (vscode.workspace.workspaceFolders) { vscode.workspace.workspaceFolders.forEach(async (folder) => { diff --git a/src/uninstall.ts b/src/uninstall.ts new file mode 100644 index 000000000..317b87976 --- /dev/null +++ b/src/uninstall.ts @@ -0,0 +1,148 @@ +import * as vscode from "vscode"; +import { Logger } from "./logger/logger"; +import { OutputChannel } from "./logger/outputChannel"; + +export async function removeEspIdfSettings() { + const config = vscode.workspace.getConfiguration(); + const settingsToDelete: string[] = []; + + // Helper function to recursively find idf settings + function findIdfSettings(obj: any, prefix: string = "") { + if (typeof obj === "object" && obj !== null) { + Object.keys(obj).forEach((key) => { + const fullPath = prefix ? `${prefix}.${key}` : key; + if (fullPath.startsWith("idf.") || fullPath.startsWith("esp.")) { + settingsToDelete.push(fullPath); + } + findIdfSettings(obj[key], fullPath); + }); + } + } + + // Get all settings directly from configuration + const allSettings = config.inspect(""); + + // Check values saved in each scope using a simple loop + const scopeValues = [ + allSettings?.globalValue, + allSettings?.workspaceValue, + allSettings?.workspaceFolderValue, + ]; + + for (const value of scopeValues) { + if (value) { + findIdfSettings(value); + } + } + + if (settingsToDelete.length === 0) { + vscode.window.showInformationMessage( + vscode.l10n.t("No ESP-IDF settings found to remove.") + ); + return; + } + + // Filter out any duplicate paths + const uniqueSettingsToDelete = [...new Set(settingsToDelete)]; + + // Ask user for confirmation + const message = vscode.l10n.t( + "Are you sure you want to remove all ESP-IDF settings? This will delete all idf.* configurations." + ); + const result = await vscode.window.showWarningMessage( + message, + { + modal: true, + detail: vscode.l10n.t( + "{0} settings will be removed.", + uniqueSettingsToDelete.length + ), + }, + vscode.l10n.t("Yes"), + vscode.l10n.t("No") + ); + + if (result !== vscode.l10n.t("Yes")) { + return; + } + + // Helper function to remove setting from a specific scope + async function removeSettingFromScope( + setting: string, + target: vscode.ConfigurationTarget, + inspectionValue: any, + scopeDescription: string + ) { + try { + if (inspectionValue !== undefined) { + await config.update(setting, undefined, target); + OutputChannel.appendLine( + vscode.l10n.t(`Removed ${scopeDescription} setting: {0}`, setting) + ); + } + } catch (e) { + // Silently continue if we can't modify settings for this scope + } + } + + try { + const message = vscode.l10n.t("Starting ESP-IDF settings cleanup..."); + OutputChannel.appendLineAndShow(message); + Logger.info(message); + + const scopeConfigs = [ + { + target: vscode.ConfigurationTarget.Global, + property: "globalValue", + description: "global", + }, + { + target: vscode.ConfigurationTarget.Workspace, + property: "workspaceValue", + description: "workspace", + }, + { + target: vscode.ConfigurationTarget.WorkspaceFolder, + property: "workspaceFolderValue", + description: "workspace folder", + }, + ]; + + // Delete each setting + for (const setting of uniqueSettingsToDelete) { + try { + const inspection = config.inspect(setting); + + // Try to remove from each scope + for (const { target, property, description } of scopeConfigs) { + await removeSettingFromScope( + setting, + target, + inspection?.[property], + description + ); + } + } catch (settingError) { + OutputChannel.appendLine( + vscode.l10n.t( + "Warning: Could not fully remove setting {0}: {1}", + setting, + settingError.message + ) + ); + } + } + + OutputChannel.appendLineAndShow( + vscode.l10n.t("ESP-IDF settings removed successfully.") + ); + } catch (error) { + const errorMessage = error instanceof Error ? error.message : String(error); + vscode.window.showErrorMessage( + vscode.l10n.t("Failed to remove settings: {0}"), + errorMessage + ); + OutputChannel.appendLineAndShow(vscode.l10n.t("Error: {0}"), errorMessage); + Logger.error(errorMessage, error, "extension removeEspIdfSettings"); + } +} From 87753b6be5f68a264a5bb6dfaa2f8e4e2dccd309 Mon Sep 17 00:00:00 2001 From: Radu Date: Thu, 16 Jan 2025 10:57:41 +0200 Subject: [PATCH 8/8] Make use of registerIDFCommand - Renaming the function to clearly indicate it's async --- src/extension.ts | 9 ++------- src/uninstall.ts | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 3088d7683..1b0e6d177 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -173,7 +173,7 @@ import { IDFWebCommandKeys, } from "./cmdTreeView/cmdStore"; import { IdfSetup } from "./views/setup/types"; -import { removeEspIdfSettings } from "./uninstall"; +import { asyncRemoveEspIdfSettings } from "./uninstall"; // Global variables shared by commands let workspaceRoot: vscode.Uri; @@ -3731,12 +3731,7 @@ export async function activate(context: vscode.ExtensionContext) { checkAndNotifyMissingCompileCommands(); // Remove ESP-IDF settings - context.subscriptions.push( - vscode.commands.registerCommand( - "espIdf.removeEspIdfSettings", - removeEspIdfSettings - ) - ); + registerIDFCommand("espIdf.removeEspIdfSettings", asyncRemoveEspIdfSettings); } function checkAndNotifyMissingCompileCommands() { diff --git a/src/uninstall.ts b/src/uninstall.ts index 317b87976..303d6caab 100644 --- a/src/uninstall.ts +++ b/src/uninstall.ts @@ -2,7 +2,7 @@ import * as vscode from "vscode"; import { Logger } from "./logger/logger"; import { OutputChannel } from "./logger/outputChannel"; -export async function removeEspIdfSettings() { +export async function asyncRemoveEspIdfSettings() { const config = vscode.workspace.getConfiguration(); const settingsToDelete: string[] = [];