Skip to content

Commit

Permalink
add command and status bar item
Browse files Browse the repository at this point in the history
  • Loading branch information
brianignacio5 committed Mar 29, 2024
1 parent fe3f3d7 commit 8e0597b
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 11 deletions.
1 change: 1 addition & 0 deletions i18n/en/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions i18n/es/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions i18n/ru/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions i18n/zh-CN/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 端口",
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions schema.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
27 changes: 24 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -3548,7 +3561,7 @@ function registerTreeProvidersForIDFExplorer(context: vscode.ExtensionContext) {
);
}

function createCmdsStatusBarItems() {
async function createCmdsStatusBarItems() {
const enableStatusBar = idfConf.readParameter(
"idf.enableStatusBar"
) as boolean;
Expand All @@ -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)",
Expand Down
18 changes: 10 additions & 8 deletions src/versionSwitcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
};
});
Expand All @@ -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",
Expand Down

0 comments on commit 8e0597b

Please sign in to comment.