From 26f7b4cf40ed0ac96509883dc6d07e8cf3fde648 Mon Sep 17 00:00:00 2001 From: "Brian A. Ignacio" Date: Fri, 28 Apr 2023 17:00:39 +0800 Subject: [PATCH] add idf enableStatusBar setting to show status bar (#953) --- docs/SETTINGS.md | 1 + i18n/en/package.i18n.json | 1 + i18n/es/package.i18n.json | 1 + i18n/ru/package.i18n.json | 1 + i18n/zh-CN/package.i18n.json | 1 + package.json | 6 ++++ package.nls.json | 1 + schema.i18n.json | 3 +- src/extension.ts | 61 +++++++++++++++++++++++++++--------- src/workspaceConfig.ts | 12 ++++--- 10 files changed, 69 insertions(+), 19 deletions(-) diff --git a/docs/SETTINGS.md b/docs/SETTINGS.md index 2aee1fb77..ee11d5c32 100644 --- a/docs/SETTINGS.md +++ b/docs/SETTINGS.md @@ -106,6 +106,7 @@ These settings are used to configure the [Code coverage](./COVERAGE.md) colors. | `idf.deleteComponentsOnFullClean` | Delete `managed_components` on full clean project command (default `false`) | User, Remote or Workspace | | `idf.monitorNoReset` | Enable no-reset flag to IDF Monitor (default `false`) | User, Remote or Workspace | | `idf.monitorStartDelayBeforeDebug` | Delay to start debug session after IDF monitor execution | User, Remote or Workspace | +| `idf.enableStatusBar` | Show or hide the extension status bar items | User, Remote or Workspace | ## Custom tasks for build and flash tasks diff --git a/i18n/en/package.i18n.json b/i18n/en/package.i18n.json index 6a4d939a7..e7d4f43fc 100644 --- a/i18n/en/package.i18n.json +++ b/i18n/en/package.i18n.json @@ -101,6 +101,7 @@ "param.svdFile": "SVD file to resolve ESP-IDF Peripheral view in Debug view", "param.deleteComponentsOnFullClean": "Delete managed_components on full clean project command", "param.sdkconfigDefaults": "List of sdkconfig default values for initial build configuration", + "param.enableStatusBar.title": "Enable ESP-IDF extension status bar items", "view.components.name": "Project Components", "configuration.title": "ESP-IDF", "espIdf.apptrace.archive.refresh.title": "Refresh Trace Archive List", diff --git a/i18n/es/package.i18n.json b/i18n/es/package.i18n.json index 8079b6239..a69dd5409 100644 --- a/i18n/es/package.i18n.json +++ b/i18n/es/package.i18n.json @@ -106,6 +106,7 @@ "param.deleteComponentsOnFullClean": "Borrar managed_components en el comando limpiar proyecto", "param.monitorStartDelayBeforeDebug": "Retraso para iniciar la sesión de depuración luego de IDF Monitor (ms)", "param.monitorNoReset": "Habilitar no-reset en el IDF Monitor", + "param.enableStatusBar.title": "Habilitar elementos de la barra de estatus de la extension ESP-IDF", "view.components.name": "Componentes de proyecto", "configuration.title": "ESP-IDF", "espIdf.apptrace.archive.refresh.title": "Refresh Trace Archive List", diff --git a/i18n/ru/package.i18n.json b/i18n/ru/package.i18n.json index aa4aa0715..0f8743f24 100644 --- a/i18n/ru/package.i18n.json +++ b/i18n/ru/package.i18n.json @@ -106,6 +106,7 @@ "param.deleteComponentsOnFullClean": "Удалить manage_components при полной очистке проекта.", "param.monitorStartDelayBeforeDebug": "Задержка запуска сеанса отладки после выполнения монитора IDF (мс)", "param.monitorNoReset": "Включить флаг отсутствия сброса для монитора IDF", + "param.enableStatusBar.title": "Включить элементы строки состояния расширения ESP-IDF", "view.components.name": "Компоненты проекта", "configuration.title": "ESP-IDF", "espIdf.apptrace.archive.refresh.title": "Обновить список архива трассировки", diff --git a/i18n/zh-CN/package.i18n.json b/i18n/zh-CN/package.i18n.json index e04780e1e..b48d70ca0 100644 --- a/i18n/zh-CN/package.i18n.json +++ b/i18n/zh-CN/package.i18n.json @@ -106,6 +106,7 @@ "param.deleteComponentsOnFullClean": "完全清除项目命令时删除managed_components", "param.monitorStartDelayBeforeDebug": "IDF监视器执行后延迟启动调试会话 (ms)", "param.monitorNoReset": "对IDF监视器启用无重置标志", + "param.enableStatusBar.title": "启用ESP-IDF扩展状态栏项目", "view.components.name": "项目组件", "configuration.title": "ESP-IDF", "espIdf.apptrace.archive.refresh.title": "刷新跟踪归档列表", diff --git a/package.json b/package.json index d0b52576f..bfa1573f4 100644 --- a/package.json +++ b/package.json @@ -846,6 +846,12 @@ "default": false, "scope": "resource", "description": "%param.monitorNoReset%" + }, + "idf.enableStatusBar": { + "type": "boolean", + "description": "%param.enableStatusBar.title%", + "scope": "resource", + "default": true } } } diff --git a/package.nls.json b/package.nls.json index 63a2648b3..90a64950e 100644 --- a/package.nls.json +++ b/package.nls.json @@ -103,6 +103,7 @@ "param.sdkconfigDefaults": "List of sdkconfig default values for initial build configuration", "param.monitorStartDelayBeforeDebug": "Delay to start debug session after IDF monitor execution (ms)", "param.monitorNoReset": "Enable no-reset flag to IDF Monitor", + "param.enableStatusBar.title": "Enable ESP-IDF extension status bar items", "view.components.name": "Project Components", "configuration.title": "ESP-IDF", "espIdf.apptrace.archive.refresh.title": "Refresh Trace Archive List", diff --git a/schema.i18n.json b/schema.i18n.json index 653fad14a..2d4a5f1d8 100644 --- a/schema.i18n.json +++ b/schema.i18n.json @@ -221,6 +221,7 @@ "param.preFlashTask", "param.postFlashTask", "param.svdFile", - "param.deleteComponentsOnFullClean" + "param.deleteComponentsOnFullClean", + "param.enableStatusBar.title" ] } diff --git a/src/extension.ts b/src/extension.ts index ddab00815..39d8b7b46 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -257,7 +257,7 @@ export async function activate(context: vscode.ExtensionContext) { // Create a status bar item with current workspace // Status Bar Item with common commands - statusBarItems = creatCmdsStatusBarItems(); + statusBarItems = createCmdsStatusBarItems(); // Create Kconfig Language Server Client KconfigLangClient.startKconfigLangServer(context); @@ -298,8 +298,10 @@ export async function activate(context: vscode.ExtensionContext) { if (PreCheck.isWorkspaceFolderOpen()) { workspaceRoot = initSelectedWorkspace(statusBarItems["workspace"]); await getIdfTargetFromSdkconfig(workspaceRoot, statusBarItems["target"]); - statusBarItems["port"].text = - "$(plug) " + idfConf.readParameter("idf.port", workspaceRoot); + if (statusBarItems && statusBarItems["port"]) { + statusBarItems["port"].text = + "$(plug) " + idfConf.readParameter("idf.port", workspaceRoot); + } const coverageOptions = getCoverageOptions(workspaceRoot); covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions); } @@ -353,8 +355,10 @@ export async function activate(context: vscode.ExtensionContext) { workspaceRoot, statusBarItems["target"] ); - statusBarItems["port"].text = - "$(plug) " + idfConf.readParameter("idf.port", workspaceRoot); + if (statusBarItems && statusBarItems["port"]) { + statusBarItems["port"].text = + "$(plug) " + idfConf.readParameter("idf.port", workspaceRoot); + } const coverageOptions = getCoverageOptions(workspaceRoot); covRenderer = new CoverageRenderer(workspaceRoot, coverageOptions); break; @@ -773,8 +777,10 @@ export async function activate(context: vscode.ExtensionContext) { workspaceRoot, statusBarItems["target"] ); - statusBarItems["port"].text = - "$(plug) " + idfConf.readParameter("idf.port", workspaceRoot); + if (statusBarItems && statusBarItems["port"]) { + statusBarItems["port"].text = + "$(plug) " + idfConf.readParameter("idf.port", workspaceRoot); + } updateIdfComponentsTree(workspaceRoot); const workspaceFolderInfo = { clickCommand: "espIdf.pickAWorkspaceFolder", @@ -1085,7 +1091,20 @@ export async function activate(context: vscode.ExtensionContext) { vscode.workspace.onDidChangeConfiguration(async (e) => { const winFlag = process.platform === "win32" ? "Win" : ""; - if (e.affectsConfiguration("idf.openOcdConfigs")) { + if (e.affectsConfiguration("idf.enableStatusBar")) { + const enableStatusBar = idfConf.readParameter( + "idf.enableStatusBar", + workspaceRoot + ) as boolean; + if (enableStatusBar) { + statusBarItems = createCmdsStatusBarItems(); + } else if (!enableStatusBar) { + for (let statusItem in statusBarItems) { + statusBarItems[statusItem].dispose(); + statusBarItems[statusItem] = undefined; + } + } + } else if (e.affectsConfiguration("idf.openOcdConfigs")) { const openOcdConfigFilesList = idfConf.readParameter( "idf.openOcdConfigs", workspaceRoot @@ -1109,7 +1128,9 @@ export async function activate(context: vscode.ExtensionContext) { target: idfTarget, } as IDebugAdapterConfig; debugAdapterManager.configureAdapter(debugAdapterConfig); - statusBarItems["target"].text = "$(circuit-board) " + idfTarget; + if (statusBarItems && statusBarItems["target"]) { + statusBarItems["target"].text = "$(circuit-board) " + idfTarget; + } } else if (e.affectsConfiguration("idf.espIdfPath" + winFlag)) { ESP.URL.Docs.IDF_INDEX = undefined; } else if (e.affectsConfiguration("idf.qemuTcpPort")) { @@ -1117,8 +1138,10 @@ export async function activate(context: vscode.ExtensionContext) { tcpPort: idfConf.readParameter("idf.qemuTcpPort", workspaceRoot), } as IQemuOptions); } else if (e.affectsConfiguration("idf.port" + winFlag)) { - statusBarItems["port"].text = - "$(plug) " + idfConf.readParameter("idf.port", workspaceRoot); + if (statusBarItems && statusBarItems["port"]) { + statusBarItems["port"].text = + "$(plug) " + idfConf.readParameter("idf.port", workspaceRoot); + } } else if (e.affectsConfiguration("idf.customAdapterTargetName")) { let idfTarget = idfConf.readParameter( "idf.adapterTargetName", @@ -1133,7 +1156,9 @@ export async function activate(context: vscode.ExtensionContext) { target: idfTarget, } as IDebugAdapterConfig; debugAdapterManager.configureAdapter(debugAdapterConfig); - statusBarItems["target"].text = "$(circuit-board) " + idfTarget; + if (statusBarItems && statusBarItems["target"]) { + statusBarItems["target"].text = "$(circuit-board) " + idfTarget; + } } } else if (e.affectsConfiguration("openocd.tcl.host")) { const tclHost = idfConf.readParameter( @@ -1158,7 +1183,9 @@ export async function activate(context: vscode.ExtensionContext) { "idf.flashType", workspaceRoot ) as string; - statusBarItems["flashType"].text = `$(star-empty) ${flashType}`; + if (statusBarItems && statusBarItems["flashType"]) { + statusBarItems["flashType"].text = `$(star-empty) ${flashType}`; + } } else if (e.affectsConfiguration("idf.buildPath")) { updateIdfComponentsTree(workspaceRoot); } @@ -2985,7 +3012,13 @@ function registerTreeProvidersForIDFExplorer(context: vscode.ExtensionContext) { ); } -function creatCmdsStatusBarItems() { +function createCmdsStatusBarItems() { + const enableStatusBar = idfConf.readParameter( + "idf.enableStatusBar" + ) as boolean; + if (!enableStatusBar) { + return {}; + } const port = idfConf.readParameter("idf.port", workspaceRoot) as string; let idfTarget = idfConf.readParameter("idf.adapterTargetName", workspaceRoot); let flashType = idfConf.readParameter( diff --git a/src/workspaceConfig.ts b/src/workspaceConfig.ts index 9f756f445..02b5c512f 100644 --- a/src/workspaceConfig.ts +++ b/src/workspaceConfig.ts @@ -22,7 +22,7 @@ import { Logger } from "./logger/logger"; import * as utils from "./utils"; import { getSDKConfigFilePath } from "./utils"; -export function initSelectedWorkspace(status: vscode.StatusBarItem) { +export function initSelectedWorkspace(status?: vscode.StatusBarItem) { const workspaceRoot = vscode.workspace.workspaceFolders[0].uri; updateIdfComponentsTree(workspaceRoot); const workspaceFolderInfo = { @@ -31,7 +31,9 @@ export function initSelectedWorkspace(status: vscode.StatusBarItem) { tooltip: vscode.workspace.workspaceFolders[0].uri.fsPath, text: "${file-directory}", }; - utils.updateStatus(status, workspaceFolderInfo); + if (status) { + utils.updateStatus(status, workspaceFolderInfo); + } return workspaceRoot; } @@ -79,7 +81,7 @@ export function getProjectName(buildDir: string): Promise { export async function getIdfTargetFromSdkconfig( workspacePath: vscode.Uri, - statusItem: vscode.StatusBarItem + statusItem?: vscode.StatusBarItem ) { let sdkConfigPath = getSDKConfigFilePath(workspacePath); const doesSdkconfigExists = await pathExists(sdkConfigPath); @@ -98,5 +100,7 @@ export async function getIdfTargetFromSdkconfig( vscode.ConfigurationTarget.WorkspaceFolder, workspacePath ); - statusItem.text = "$(circuit-board) " + idfTarget; + if (statusItem) { + statusItem.text = "$(circuit-board) " + idfTarget; + } }