From 8e0597b049d2a534fb2fbad19a8876a7cb66b6ef Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Fri, 29 Mar 2024 19:08:44 +0800 Subject: [PATCH] add command and status bar item --- 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 | 5 +++++ package.nls.json | 1 + schema.i18n.json | 1 + src/extension.ts | 27 ++++++++++++++++++++++++--- src/versionSwitcher/index.ts | 18 ++++++++++-------- 9 files changed, 45 insertions(+), 11 deletions(-) diff --git a/i18n/en/package.i18n.json b/i18n/en/package.i18n.json index b602a266d..a9bd8e70f 100644 --- a/i18n/en/package.i18n.json +++ b/i18n/en/package.i18n.json @@ -150,6 +150,7 @@ "espIdf.efuse.clearResults.title": "Clear eFuse Summary", "espIdf.jtag_flash.title": "Flash (with JTag)", "espIdf.selectFlashMethodAndFlash.title": "Select Flash Method", + "espIdf.selectCurrentIdfVersion.title": "Select Current ESP-IDF Version", "idf.flashType.description": "Device flash method, UART or JTag", "openocd.tcl.host.description": "Host for openocd tcl connection", "openocd.tcl.port.description": "Port for openocd tcl connection", diff --git a/i18n/es/package.i18n.json b/i18n/es/package.i18n.json index c468d236e..3ede0e90c 100644 --- a/i18n/es/package.i18n.json +++ b/i18n/es/package.i18n.json @@ -150,6 +150,7 @@ "espIdf.efuse.clearResults.title": "Limpiar el resumen de eFuse", "espIdf.jtag_flash.title": "Flash (con JTag)", "espIdf.selectFlashMethodAndFlash.title": "Seleccione el método de programar", + "espIdf.selectCurrentIdfVersion.title": "Seleccione la versión ESP-IDF a usar", "idf.flashType.description": "Método de flash del dispositivo, UART o JTag", "openocd.tcl.host.description": "Anfitrión para conexión tcl openocd", "openocd.tcl.port.description": "Puerto para conexión tcl openocd", diff --git a/i18n/ru/package.i18n.json b/i18n/ru/package.i18n.json index 251f51f9d..99b23b94c 100644 --- a/i18n/ru/package.i18n.json +++ b/i18n/ru/package.i18n.json @@ -150,6 +150,7 @@ "espIdf.efuse.clearResults.title": "Очистить сводку eFuse", "espIdf.jtag_flash.title": "Прошить (через JTag)", "espIdf.selectFlashMethodAndFlash.title": "Выбрать метод прошивки", + "espIdf.selectCurrentIdfVersion.title": "Выберите текущую версию ESP-IDF", "idf.flashType.description": "Метод прошивки устройства, UART или JTag", "openocd.tcl.host.description": "Хост для подключения openocd tcl", "openocd.tcl.port.description": "Порт для подключения openocd tcl", diff --git a/i18n/zh-CN/package.i18n.json b/i18n/zh-CN/package.i18n.json index 08f015d12..6a83dfddb 100644 --- a/i18n/zh-CN/package.i18n.json +++ b/i18n/zh-CN/package.i18n.json @@ -150,6 +150,7 @@ "espIdf.efuse.clearResults.title": "清除 eFuse 摘要", "espIdf.jtag_flash.title": "JTag 烧录", "espIdf.selectFlashMethodAndFlash.title": "选择烧录方式烧录", + "espIdf.selectCurrentIdfVersion.title": "选择当前ESP-IDF版本", "idf.flashType.description": "设备烧录方式,UART 或 JTag", "openocd.tcl.host.description": "OpenOCD TCL 主机", "openocd.tcl.port.description": "OpenOCD TCL 端口", diff --git a/package.json b/package.json index fab8cc49c..3a740d935 100644 --- a/package.json +++ b/package.json @@ -1379,6 +1379,11 @@ "command": "espIdf.createSbom", "title": "%espIdf.createSbom.title%", "category": "ESP-IDF" + }, + { + "command": "espIdf.selectCurrentIdfVersion", + "title": "%espIdf.selectCurrentIdfVersion.title%", + "category": "ESP-IDF" } ], "breakpoints": [ diff --git a/package.nls.json b/package.nls.json index 76c2cbc11..02d0acd83 100644 --- a/package.nls.json +++ b/package.nls.json @@ -150,6 +150,7 @@ "espIdf.efuse.clearResults.title": "Clear eFuse Summary", "espIdf.jtag_flash.title": "Flash (with JTag)", "espIdf.selectFlashMethodAndFlash.title": "Select Flash Method", + "espIdf.selectCurrentIdfVersion.title": "Select Current ESP-IDF Version", "idf.flashType.description": "Device flash method, UART or JTag", "openocd.tcl.host.description": "Host for openocd tcl connection", "openocd.tcl.port.description": "Port for openocd tcl connection", diff --git a/schema.i18n.json b/schema.i18n.json index 16db54db0..e10e7571e 100644 --- a/schema.i18n.json +++ b/schema.i18n.json @@ -207,6 +207,7 @@ "espIdf.efuse.clearResults.title", "espIdf.jtag_flash.title", "espIdf.selectFlashMethodAndFlash.title", + "espIdf.selectCurrentIdfVersion.title", "idf.flashType.description", "openocd.tcl.host.description", "openocd.tcl.port.description", diff --git a/src/extension.ts b/src/extension.ts index 9fd3335e5..8922c03c3 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -145,6 +145,7 @@ import { getFileList, getTestComponents } from "./espIdf/unitTest/utils"; import { saveDefSdkconfig } from "./espIdf/menuconfig/saveDefConfig"; import { createSBOM, installEspSBOM } from "./espBom"; import { getEspHomeKitSdk } from "./espHomekit/espHomekitDownload"; +import { getCurrentIdfSetup, selectIdfSetup } from "./versionSwitcher"; // Global variables shared by commands let workspaceRoot: vscode.Uri; @@ -276,7 +277,7 @@ export async function activate(context: vscode.ExtensionContext) { // Create a status bar item with current workspace // Status Bar Item with common commands - statusBarItems = createCmdsStatusBarItems(); + statusBarItems = await createCmdsStatusBarItems(); // Create Kconfig Language Server Client KconfigLangClient.startKconfigLangServer(context); @@ -804,6 +805,15 @@ export async function activate(context: vscode.ExtensionContext) { ); }); + registerIDFCommand("espIdf.selectCurrentIdfVersion", () => { + PreCheck.perform([webIdeCheck, openFolderCheck], async () => { + const curWorkspaceFolder = vscode.workspace.workspaceFolders.find( + (w) => w.uri === workspaceRoot + ); + await selectIdfSetup(curWorkspaceFolder); + }); + }); + registerIDFCommand("espIdf.customTask", async () => { try { const customTask = new CustomTask(workspaceRoot); @@ -1222,7 +1232,7 @@ export async function activate(context: vscode.ExtensionContext) { workspaceRoot ) as boolean; if (enableStatusBar) { - statusBarItems = createCmdsStatusBarItems(); + statusBarItems = await createCmdsStatusBarItems(); } else if (!enableStatusBar) { for (let statusItem in statusBarItems) { statusBarItems[statusItem].dispose(); @@ -1258,6 +1268,9 @@ export async function activate(context: vscode.ExtensionContext) { } } else if (e.affectsConfiguration("idf.espIdfPath" + winFlag)) { ESP.URL.Docs.IDF_INDEX = undefined; + let currentIdfVersion = await getCurrentIdfSetup(workspaceRoot); + statusBarItems["currentIdfVersion"].text = + "$(octoface) ESP-IDF v" + currentIdfVersion.version; } else if (e.affectsConfiguration("idf.qemuTcpPort")) { qemuManager.configure({ tcpPort: idfConf.readParameter("idf.qemuTcpPort", workspaceRoot), @@ -3548,7 +3561,7 @@ function registerTreeProvidersForIDFExplorer(context: vscode.ExtensionContext) { ); } -function createCmdsStatusBarItems() { +async function createCmdsStatusBarItems() { const enableStatusBar = idfConf.readParameter( "idf.enableStatusBar" ) as boolean; @@ -3570,8 +3583,16 @@ function createCmdsStatusBarItems() { workspaceRoot ); } + let currentIdfVersion = await getCurrentIdfSetup(workspaceRoot); const statusBarItems: { [key: string]: vscode.StatusBarItem } = {}; + statusBarItems["currentIdfVersion"] = createStatusBarItem( + "$(octoface) ESP-IDF v" + currentIdfVersion.version, + "ESP-IDF: Select current ESP-IDF version", + "espIdf.selectCurrentIdfVersion", + 102 + ); + statusBarItems["port"] = createStatusBarItem( "$(plug)" + port, "ESP-IDF: Select Port to Use (COM, tty, usbserial)", diff --git a/src/versionSwitcher/index.ts b/src/versionSwitcher/index.ts index 86276655d..531fa5e95 100644 --- a/src/versionSwitcher/index.ts +++ b/src/versionSwitcher/index.ts @@ -16,9 +16,12 @@ * limitations under the License. */ -import { ConfigurationTarget, window, WorkspaceFolder } from "vscode"; +import { ConfigurationTarget, Uri, window, WorkspaceFolder } from "vscode"; import { getPreviousIdfSetups } from "../setup/existingIdfSetups"; -import { checkIdfSetup, useIdfSetupSettings } from "../setup/setupValidation/espIdfSetup"; +import { + checkIdfSetup, + useIdfSetupSettings, +} from "../setup/setupValidation/espIdfSetup"; import { readParameter } from "../idfConfiguration"; import { getIdfMd5sum } from "../setup/espIdfJson"; import { getEspIdfFromCMake } from "../utils"; @@ -32,7 +35,9 @@ export async function selectIdfSetup(workspaceFolder: WorkspaceFolder) { } const idfSetupOptions = idfSetups.map((idfSetup) => { return { - label: `Version: ${idfSetup.version} IDF_PATH: ${idfSetup.idfPath} IDF_TOOLS_PATH: ${idfSetup.toolsPath}`, + label: `Version: v${idfSetup.version}`, + description: `IDF_PATH: ${idfSetup.idfPath}`, + detail: `IDF_TOOLS_PATH: ${idfSetup.toolsPath}`, target: idfSetup, }; }); @@ -48,12 +53,9 @@ export async function selectIdfSetup(workspaceFolder: WorkspaceFolder) { ); } -export async function getCurrentIdfSetup(workspaceFolder: WorkspaceFolder){ +export async function getCurrentIdfSetup(workspaceFolder: Uri) { let idfPath = readParameter("idf.espIdfPath", workspaceFolder); - const toolsPath = readParameter( - "idf.toolsPath", - workspaceFolder - ) as string; + const toolsPath = readParameter("idf.toolsPath", workspaceFolder) as string; const gitPath = readParameter("idf.gitPath", workspaceFolder); const pythonPath = readParameter( "idf.pythonBinPath",