From d1582d4a0b76cf8eeac503d7b9c499c673da2e92 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Mon, 21 Aug 2023 20:01:25 +0800 Subject: [PATCH 1/6] add setup cmd install and reuse --- package.json | 10 ++ src/extension.ts | 9 ++ src/setup/cmd.ts | 250 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 269 insertions(+) create mode 100644 src/setup/cmd.ts diff --git a/package.json b/package.json index 0e9033a34..2cce31ee0 100644 --- a/package.json +++ b/package.json @@ -1378,6 +1378,16 @@ "command": "espIdf.createSbom", "title": "%espIdf.createSbom.title%", "category": "ESP-IDF" + }, + { + "command": "espIdf.installEspIdf", + "title": "Install ESP-IDF command", + "category": "ESP-IDF" + }, + { + "command": "espIdf.useEspIdfJsonSetup", + "title": "Use ESP-IDF setup", + "category": "ESP-IDF" } ], "breakpoints": [ diff --git a/src/extension.ts b/src/extension.ts index 5a7fc5ed3..7c5f825fe 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 { downloadEspIdf, useExistingEspIdfJsonSetup } from "./setup/cmd"; // Global variables shared by commands let workspaceRoot: vscode.Uri; @@ -2286,6 +2287,14 @@ export async function activate(context: vscode.ExtensionContext) { }); }); + registerIDFCommand("espIdf.installEspIdf", async () => { + await downloadEspIdf(context.extensionUri); + }); + + registerIDFCommand("espIdf.useEspIdfJsonSetup", async () => { + await useExistingEspIdfJsonSetup(); + }); + registerIDFCommand("espIdf.importProject", async () => { const srcFolder = await vscode.window.showOpenDialog({ canSelectFolders: true, diff --git a/src/setup/cmd.ts b/src/setup/cmd.ts new file mode 100644 index 000000000..9ae7be1d1 --- /dev/null +++ b/src/setup/cmd.ts @@ -0,0 +1,250 @@ +/* + * Project: ESP-IDF VSCode Extension + * File Created: Monday, 21st August 2023 3:30:23 pm + * Copyright 2023 Espressif Systems (Shanghai) CO LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + CancellationToken, + ConfigurationTarget, + Progress, + ProgressLocation, + Uri, + window, +} from "vscode"; +import { getEspIdfVersions } from "./espIdfVersionList"; +import { Logger } from "../logger/logger"; +import { ESP } from "../config"; +import { downloadInstallIdfVersion } from "./espIdfDownload"; +import { IdfToolsManager } from "../idfToolsManager"; +import { join } from "path"; +import { saveSettings } from "./setupInit"; +import { getUnixPythonList, installExtensionPyReqs, installPythonEnvFromIdfTools } from "../pythonManager"; +import { loadIdfSetupsFromEspIdfJson } from "./existingIdfSetups"; +import { OutputChannel } from "../logger/outputChannel"; +import { downloadEspIdfTools } from "./toolInstall"; +import { isBinInPath } from "../utils"; + +export async function useExistingEspIdfJsonSetup() { + const containerPath = + process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME; + const toolsPath = join(containerPath, ".espressif"); + const idfSetups = await loadIdfSetupsFromEspIdfJson(toolsPath); + let quickPickItems = idfSetups.map((idfSetup) => { + return { + description: idfSetup.idfPath, + label: idfSetup.version, + target: idfSetup.id, + ...idfSetup, + }; + }); + const espIdfVersion = await window.showQuickPick(quickPickItems, { + placeHolder: "Select ESP-IDF version", + }); + if (!espIdfVersion) { + Logger.infoNotify("No ESP-IDF version selected."); + return; + } + const idfToolsManager = await IdfToolsManager.createIdfToolsManager( + espIdfVersion.idfPath + ); + const exportedToolsPaths = await idfToolsManager.exportPathsInString( + join(toolsPath, "tools"), + ["cmake", "ninja"] + ); + const exportedVars = await idfToolsManager.exportVars( + join(toolsPath, "tools") + ); + await saveSettings( + espIdfVersion.idfPath, + espIdfVersion.python, + exportedToolsPaths, + exportedVars, + toolsPath, + espIdfVersion.gitPath, + ConfigurationTarget.Global + ); +} + +export async function downloadEspIdf(extensionPath: Uri) { + const espIdfVersions = await getEspIdfVersions(extensionPath.fsPath); + + let quickPickItems = espIdfVersions.map((k) => { + return { + description: k.filename, + label: k.name, + target: k.filename, + ...k, + }; + }); + const espIdfVersion = await window.showQuickPick(quickPickItems, { + placeHolder: "Select ESP-IDF version", + }); + if (!espIdfVersion) { + Logger.infoNotify("No ESP-IDF version selected."); + return; + } + + const mirror = await window.showQuickPick( + [ + { + description: "Mirror", + label: "Espressif", + target: ESP.IdfMirror.Espressif, + }, + { + description: "Mirror", + label: "Github", + target: ESP.IdfMirror.Github, + }, + ], + { placeHolder: "Select download mirror" } + ); + + if (!mirror) { + Logger.infoNotify("No mirror selected."); + return; + } + const containerPath = + process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME; + + const destPath = join(containerPath, "esp"); + const toolsPath = join(containerPath, ".espressif"); + let idfGitPath = "git"; + let idfPythonPath = ""; + + window.withProgress( + { + cancellable: true, + location: ProgressLocation.Notification, + title: "Installing ESP-IDF", + }, + async ( + progress: Progress<{ + message: string; + increment: number; + }>, + cancelToken: CancellationToken + ) => { + let onReqPkgs = []; + if (process.platform === "win32") { + const embedPaths = await this.installEmbedPyGit( + toolsPath, + progress, + cancelToken + ); + idfGitPath = embedPaths.idfGitPath; + idfPythonPath = embedPaths.idfPythonPath; + const canAccessCMake = await isBinInPath( + "cmake", + extensionPath.fsPath, + process.env + ); + + if (canAccessCMake === "") { + onReqPkgs = onReqPkgs + ? [...onReqPkgs, "cmake"] + : ["cmake"]; + } + + const canAccessNinja = await isBinInPath( + "ninja", + extensionPath.fsPath, + process.env + ); + + if (canAccessNinja === "") { + onReqPkgs = onReqPkgs + ? [...onReqPkgs, "ninja"] + : ["ninja"]; + } + } else { + const pythonList = await getUnixPythonList(toolsPath); + let pythonItems = pythonList.map((pyVer) => { + return { + description: "", + label: pyVer, + target: pyVer, + }; + }); + const selectPyVersion = await window.showQuickPick(pythonItems, { + placeHolder: "Select ESP-IDF version", + }); + + if (!selectPyVersion) { + return; + } + idfPythonPath = selectPyVersion.target; + } + + const espIdfPath = await downloadInstallIdfVersion( + espIdfVersion, + destPath, + mirror.target, + idfGitPath, + progress, + cancelToken + ); + const idfToolsManager = await IdfToolsManager.createIdfToolsManager( + espIdfPath + ); + const exportedToolsPaths = await idfToolsManager.exportPathsInString( + join(toolsPath, "tools"), + ["cmake", "ninja"] + ); + const exportedVars = await idfToolsManager.exportVars( + join(toolsPath, "tools") + ); + + await downloadEspIdfTools( + toolsPath, + idfToolsManager, + mirror.target, + progress, + idfPythonPath, + cancelToken, + onReqPkgs + ); + + const virtualEnvPath = await installPythonEnvFromIdfTools( + espIdfPath, + toolsPath, + undefined, + idfPythonPath, + idfGitPath, + OutputChannel.init(), + cancelToken + ); + + await installExtensionPyReqs( + virtualEnvPath, + espIdfPath, + toolsPath, + undefined, + OutputChannel.init() + ); + + await saveSettings( + espIdfPath, + virtualEnvPath, + exportedToolsPaths, + exportedVars, + toolsPath, + idfGitPath, + ConfigurationTarget.Global + ); + } + ); +} From cd5209aad1ad4adc5f5b9756367fe8ba0c86b047 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Tue, 22 Aug 2023 18:22:29 +0800 Subject: [PATCH 2/6] add cmds i18n --- README.md | 2 + i18n/en/package.i18n.json | 2 + i18n/es/package.i18n.json | 2 + i18n/ru/package.i18n.json | 2 + i18n/zh-CN/package.i18n.json | 2 + package.json | 4 +- package.nls.json | 2 + schema.i18n.json | 2 + src/setup/cmd.ts | 122 ++++++++++++++++++++++++--------- src/setup/existingIdfSetups.ts | 2 + 10 files changed, 107 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 34b7efa69..aa347c115 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,7 @@ Click F1 to show Visual studio code actions, then type **ESP-IDF** to | Get HTML Coverage Report for project | | | | Import ESP-IDF Project | | | | Install ESP-ADF | | | +| Install ESP-IDF | | | | Install ESP-IDF Python Packages | | | | Install ESP-MDF | | | | Install ESP-Matter | | | @@ -161,6 +162,7 @@ Click F1 to show Visual studio code actions, then type **ESP-IDF** to | Unit Test: Install ESP-IDF PyTest requirements | | | | Remove Editor coverage | | | | Run ESP-IDF-SBOM vulnerability check | | | +| Use ESP-IDF setup from IDF Installer | | | # About commands diff --git a/i18n/en/package.i18n.json b/i18n/en/package.i18n.json index 033d2965a..66ce7c5b8 100644 --- a/i18n/en/package.i18n.json +++ b/i18n/en/package.i18n.json @@ -66,6 +66,8 @@ "espIdf.unitTest.installPyTest.title": "Unit Test: Install ESP-IDF PyTest requirements", "espIdf.saveDefSdkconfig.title": "ESP-IDF: Save Default SDKCONFIG file (save-defconfig)", "espIdf.createSbom.title": "Run ESP-IDF-SBOM vulnerability check", + "espIdf.installEspIdf.title": "Install ESP-IDF", + "espIdf.useEspIdfJsonSetup.title": "Use ESP-IDF setup from IDF Installer", "esp.component-manager.ui.show.title": "Show Component Registry", "esp.component-manager.cli.addDependencyError": "Error encountered while adding dependency to the component", "debug.initConfig.name": "ESP-IDF Debug: Launch", diff --git a/i18n/es/package.i18n.json b/i18n/es/package.i18n.json index c8ab8c4e2..a797c3273 100644 --- a/i18n/es/package.i18n.json +++ b/i18n/es/package.i18n.json @@ -68,6 +68,8 @@ "espIdf.clearSavedIdfSetups.title": "Limpiar configuraciones de IDF guardadas", "espIdf.unitTest.buildFlashUnitTestApp.title": "Unit Test: Construir y programar la app unit test app para pruebas", "espIdf.unitTest.installPyTest.title": "Unit Test: Instalar requerimientos ESP-IDF PyTest", + "espIdf.installEspIdf.title": "Instalar ESP-IDF", + "espIdf.useEspIdfJsonSetup.title": "Usar la configuracion ESP-IDF del Instalador IDF", "debug.initConfig.name": "Lanzar Depuracion ESP-IDF:", "debug.initConfig.description": "Nueva configuración para proyectos ESP-IDF", "param.adapterTargetName": "Target para el ESP-IDF Debug Adapter", diff --git a/i18n/ru/package.i18n.json b/i18n/ru/package.i18n.json index 632b33221..25d1304bc 100644 --- a/i18n/ru/package.i18n.json +++ b/i18n/ru/package.i18n.json @@ -66,6 +66,8 @@ "espIdf.unitTest.buildFlashUnitTestApp.title": "Модульный тест: сборка и запуск приложения модульного тестирования для тестирования.", "espIdf.unitTest.installPyTest.title": "Модульный тест: установите требования ESP-IDF PyTest", "espIdf.createSbom.title": "Запустите проверку уязвимостей ESP-IDF-SBOM.", + "espIdf.installEspIdf.title": "Установите ESP-IDF", + "espIdf.useEspIdfJsonSetup.title": "Используйте настройку ESP-IDF из установщика IDF.", "esp.component-manager.ui.show.title": "Показать реестр компонентов", "esp.component-manager.cli.addDependencyError": "Ошибка при добавлении зависимости к компоненту", "debug.initConfig.name": "Отладка запуск", diff --git a/i18n/zh-CN/package.i18n.json b/i18n/zh-CN/package.i18n.json index 2ddde3829..7067bbd31 100644 --- a/i18n/zh-CN/package.i18n.json +++ b/i18n/zh-CN/package.i18n.json @@ -66,6 +66,8 @@ "espIdf.unitTest.buildFlashUnitTestApp.title": "单元测试:构建并闪存用于测试的单元测试应用程序", "espIdf.unitTest.installPyTest.title": "单元测试:安装ESP-IDF PyTest要求", "espIdf.createSbom.title": "运行ESP-IDF-SBOM漏洞检查", + "espIdf.installEspIdf.title": "安装ESP-IDF", + "espIdf.useEspIdfJsonSetup.title": "使用IDF安装程序中的ESP-IDF设置", "esp.component-manager.ui.show.title": "显示组件注册表", "esp.component-manager.cli.addDependencyError": "向组件添加依赖项时遇到错误", "debug.initConfig.name": "ESP-IDF调试 启动", diff --git a/package.json b/package.json index 2cce31ee0..7de55d279 100644 --- a/package.json +++ b/package.json @@ -1381,12 +1381,12 @@ }, { "command": "espIdf.installEspIdf", - "title": "Install ESP-IDF command", + "title": "%espIdf.installEspIdf.title%", "category": "ESP-IDF" }, { "command": "espIdf.useEspIdfJsonSetup", - "title": "Use ESP-IDF setup", + "title": "%espIdf.useEspIdfJsonSetup.title%", "category": "ESP-IDF" } ], diff --git a/package.nls.json b/package.nls.json index 6331723d0..1aa9cba43 100644 --- a/package.nls.json +++ b/package.nls.json @@ -66,6 +66,8 @@ "espIdf.projectConf.title": "Select project configuration", "espIdf.saveDefSdkconfig.title": "ESP-IDF: Save Default SDKCONFIG file (save-defconfig)", "espIdf.createSbom.title": "Run ESP-IDF-SBOM vulnerability check", + "espIdf.installEspIdf.title": "Install ESP-IDF", + "espIdf.useEspIdfJsonSetup.title": "Use ESP-IDF setup from IDF Installer", "esp.component-manager.ui.show.title": "Show Component Registry", "esp.component-manager.cli.addDependencyError": "Error encountered while adding dependency to the component", "debug.initConfig.name": "ESP-IDF Debug: Launch", diff --git a/schema.i18n.json b/schema.i18n.json index 16db54db0..7829a61f6 100644 --- a/schema.i18n.json +++ b/schema.i18n.json @@ -144,6 +144,8 @@ "espIdf.unitTest.buildFlashUnitTestApp.title", "espIdf.unitTest.installPyTest.title", "espIdf.createSbom.title", + "espIdf.installEspIdf.title", + "espIdf.useEspIdfJsonSetup.title", "debug.initConfig.name", "debug.initConfig.description", "param.adapterTargetName", diff --git a/src/setup/cmd.ts b/src/setup/cmd.ts index 9ae7be1d1..953bd26ca 100644 --- a/src/setup/cmd.ts +++ b/src/setup/cmd.ts @@ -31,17 +31,39 @@ import { downloadInstallIdfVersion } from "./espIdfDownload"; import { IdfToolsManager } from "../idfToolsManager"; import { join } from "path"; import { saveSettings } from "./setupInit"; -import { getUnixPythonList, installExtensionPyReqs, installPythonEnvFromIdfTools } from "../pythonManager"; +import { + getUnixPythonList, + installExtensionPyReqs, + installPythonEnvFromIdfTools, +} from "../pythonManager"; import { loadIdfSetupsFromEspIdfJson } from "./existingIdfSetups"; import { OutputChannel } from "../logger/outputChannel"; import { downloadEspIdfTools } from "./toolInstall"; import { isBinInPath } from "../utils"; +import { pathExists } from "fs-extra"; export async function useExistingEspIdfJsonSetup() { const containerPath = process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME; - const toolsPath = join(containerPath, ".espressif"); + let toolsPath = join(containerPath, ".espressif"); + const actualToolsPath = await openFolder( + "Where to save ESP-IDF Tools? (IDF_TOOLS_PATH)" + ); + if (actualToolsPath) { + toolsPath = actualToolsPath; + } + const espIdfJsonPath = join(toolsPath, "esp_idf.json"); + const espIdfJsonExists = await pathExists(espIdfJsonPath); + if (!espIdfJsonExists) { + Logger.infoNotify(`${espIdfJsonPath} doesn't exists.`); + OutputChannel.appendLineAndShow(`${espIdfJsonPath} doesn't exists.`); + return; + } const idfSetups = await loadIdfSetupsFromEspIdfJson(toolsPath); + if (!idfSetups) { + OutputChannel.appendLineAndShow("No IDF Setups found"); + return; + } let quickPickItems = idfSetups.map((idfSetup) => { return { description: idfSetup.idfPath, @@ -55,6 +77,7 @@ export async function useExistingEspIdfJsonSetup() { }); if (!espIdfVersion) { Logger.infoNotify("No ESP-IDF version selected."); + OutputChannel.appendLineAndShow("No ESP-IDF version selected."); return; } const idfToolsManager = await IdfToolsManager.createIdfToolsManager( @@ -78,6 +101,20 @@ export async function useExistingEspIdfJsonSetup() { ); } +export async function openFolder(openLabel: string) { + const selectedFolder = await window.showOpenDialog({ + canSelectFolders: true, + canSelectFiles: false, + canSelectMany: false, + openLabel, + }); + if (selectedFolder && selectedFolder.length > 0) { + return selectedFolder[0].fsPath; + } else { + window.showInformationMessage("No folder selected"); + } +} + export async function downloadEspIdf(extensionPath: Uri) { const espIdfVersions = await getEspIdfVersions(extensionPath.fsPath); @@ -93,9 +130,31 @@ export async function downloadEspIdf(extensionPath: Uri) { placeHolder: "Select ESP-IDF version", }); if (!espIdfVersion) { - Logger.infoNotify("No ESP-IDF version selected."); + window.showInformationMessage("No ESP-IDF version selected."); return; } + const containerPath = + process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME; + + let destPath = join(containerPath, "esp"); + let toolsPath = join(containerPath, ".espressif"); + let espIdfPath = ""; + + if (espIdfVersion.filename === "manual") { + espIdfPath = await openFolder("Select ESP-IDF (IDF_PATH)"); + } else { + const actualDestPath = await openFolder("Where to save ESP-IDF?"); + if (actualDestPath) { + destPath = actualDestPath; + } + } + + const actualToolsPath = await openFolder( + "Choose ESP-IDF Tools (IDF_TOOLS_PATH)" + ); + if (actualToolsPath) { + toolsPath = actualToolsPath; + } const mirror = await window.showQuickPick( [ @@ -114,14 +173,10 @@ export async function downloadEspIdf(extensionPath: Uri) { ); if (!mirror) { - Logger.infoNotify("No mirror selected."); + window.showInformationMessage("No mirror selected."); return; } - const containerPath = - process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME; - const destPath = join(containerPath, "esp"); - const toolsPath = join(containerPath, ".espressif"); let idfGitPath = "git"; let idfPythonPath = ""; @@ -152,26 +207,22 @@ export async function downloadEspIdf(extensionPath: Uri) { extensionPath.fsPath, process.env ); - + if (canAccessCMake === "") { - onReqPkgs = onReqPkgs - ? [...onReqPkgs, "cmake"] - : ["cmake"]; + onReqPkgs = onReqPkgs ? [...onReqPkgs, "cmake"] : ["cmake"]; } - + const canAccessNinja = await isBinInPath( "ninja", extensionPath.fsPath, process.env ); - + if (canAccessNinja === "") { - onReqPkgs = onReqPkgs - ? [...onReqPkgs, "ninja"] - : ["ninja"]; + onReqPkgs = onReqPkgs ? [...onReqPkgs, "ninja"] : ["ninja"]; } } else { - const pythonList = await getUnixPythonList(toolsPath); + const pythonList = await getUnixPythonList(extensionPath.fsPath); let pythonItems = pythonList.map((pyVer) => { return { description: "", @@ -184,29 +235,25 @@ export async function downloadEspIdf(extensionPath: Uri) { }); if (!selectPyVersion) { + window.showInformationMessage("No python selected"); return; } idfPythonPath = selectPyVersion.target; } - const espIdfPath = await downloadInstallIdfVersion( - espIdfVersion, - destPath, - mirror.target, - idfGitPath, - progress, - cancelToken - ); + if (espIdfVersion.filename !== "manual") { + espIdfPath = await downloadInstallIdfVersion( + espIdfVersion, + destPath, + mirror.target, + idfGitPath, + progress, + cancelToken + ); + } const idfToolsManager = await IdfToolsManager.createIdfToolsManager( espIdfPath ); - const exportedToolsPaths = await idfToolsManager.exportPathsInString( - join(toolsPath, "tools"), - ["cmake", "ninja"] - ); - const exportedVars = await idfToolsManager.exportVars( - join(toolsPath, "tools") - ); await downloadEspIdfTools( toolsPath, @@ -236,6 +283,15 @@ export async function downloadEspIdf(extensionPath: Uri) { OutputChannel.init() ); + const exportedToolsPaths = await idfToolsManager.exportPathsInString( + join(toolsPath, "tools"), + onReqPkgs + ); + const exportedVars = await idfToolsManager.exportVars( + join(toolsPath, "tools"), + onReqPkgs + ); + await saveSettings( espIdfPath, virtualEnvPath, diff --git a/src/setup/existingIdfSetups.ts b/src/setup/existingIdfSetups.ts index a5d899b2a..f05e3d982 100644 --- a/src/setup/existingIdfSetups.ts +++ b/src/setup/existingIdfSetups.ts @@ -116,5 +116,7 @@ export async function loadIdfSetupsFromEspIdfJson(toolsPath: string) { idfSetups.push(setupConf); } return idfSetups; + } else { + return []; } } From a637d4fbd87ddff3c85f3220db6b7a7ba62afe73 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Tue, 22 Aug 2023 18:22:54 +0800 Subject: [PATCH 3/6] fix open folder dir msg --- src/setup/cmd.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/setup/cmd.ts b/src/setup/cmd.ts index 953bd26ca..7f4c6ee0f 100644 --- a/src/setup/cmd.ts +++ b/src/setup/cmd.ts @@ -47,7 +47,7 @@ export async function useExistingEspIdfJsonSetup() { process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME; let toolsPath = join(containerPath, ".espressif"); const actualToolsPath = await openFolder( - "Where to save ESP-IDF Tools? (IDF_TOOLS_PATH)" + "Choose ESP-IDF Tools (.espressif directory)" ); if (actualToolsPath) { toolsPath = actualToolsPath; @@ -62,7 +62,7 @@ export async function useExistingEspIdfJsonSetup() { const idfSetups = await loadIdfSetupsFromEspIdfJson(toolsPath); if (!idfSetups) { OutputChannel.appendLineAndShow("No IDF Setups found"); - return; + return; } let quickPickItems = idfSetups.map((idfSetup) => { return { From 979ec736d2f3892556de947e80286875ac71fbad Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Wed, 3 Apr 2024 19:38:07 +0800 Subject: [PATCH 4/6] fix cmd context --- src/setup/cmd.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/setup/cmd.ts b/src/setup/cmd.ts index 7f4c6ee0f..fe732d9c7 100644 --- a/src/setup/cmd.ts +++ b/src/setup/cmd.ts @@ -19,9 +19,9 @@ import { CancellationToken, ConfigurationTarget, + ExtensionContext, Progress, ProgressLocation, - Uri, window, } from "vscode"; import { getEspIdfVersions } from "./espIdfVersionList"; @@ -115,8 +115,8 @@ export async function openFolder(openLabel: string) { } } -export async function downloadEspIdf(extensionPath: Uri) { - const espIdfVersions = await getEspIdfVersions(extensionPath.fsPath); +export async function downloadEspIdf(context: ExtensionContext) { + const espIdfVersions = await getEspIdfVersions(context.extensionPath); let quickPickItems = espIdfVersions.map((k) => { return { @@ -204,7 +204,7 @@ export async function downloadEspIdf(extensionPath: Uri) { idfPythonPath = embedPaths.idfPythonPath; const canAccessCMake = await isBinInPath( "cmake", - extensionPath.fsPath, + context.extensionPath, process.env ); @@ -214,7 +214,7 @@ export async function downloadEspIdf(extensionPath: Uri) { const canAccessNinja = await isBinInPath( "ninja", - extensionPath.fsPath, + context.extensionPath, process.env ); @@ -222,7 +222,7 @@ export async function downloadEspIdf(extensionPath: Uri) { onReqPkgs = onReqPkgs ? [...onReqPkgs, "ninja"] : ["ninja"]; } } else { - const pythonList = await getUnixPythonList(extensionPath.fsPath); + const pythonList = await getUnixPythonList(context.extensionPath); let pythonItems = pythonList.map((pyVer) => { return { description: "", @@ -271,6 +271,7 @@ export async function downloadEspIdf(extensionPath: Uri) { undefined, idfPythonPath, idfGitPath, + context, OutputChannel.init(), cancelToken ); From e8f7772e8d50e5756f22f6ebc4ce653cc0de40f8 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Mon, 8 Apr 2024 18:14:54 +0800 Subject: [PATCH 5/6] fix downloadEspIdf method call --- src/extension.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 7c5f825fe..a0355489b 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2288,7 +2288,7 @@ export async function activate(context: vscode.ExtensionContext) { }); registerIDFCommand("espIdf.installEspIdf", async () => { - await downloadEspIdf(context.extensionUri); + await downloadEspIdf(context); }); registerIDFCommand("espIdf.useEspIdfJsonSetup", async () => { From 2ab2d92b791ca384baf8448b894ac86e616e1829 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Wed, 10 Apr 2024 18:01:25 +0800 Subject: [PATCH 6/6] save settings on workspace folder --- src/extension.ts | 4 ++-- src/setup/cmd.ts | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index a0355489b..78a471d17 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2288,11 +2288,11 @@ export async function activate(context: vscode.ExtensionContext) { }); registerIDFCommand("espIdf.installEspIdf", async () => { - await downloadEspIdf(context); + await downloadEspIdf(context, workspaceRoot); }); registerIDFCommand("espIdf.useEspIdfJsonSetup", async () => { - await useExistingEspIdfJsonSetup(); + await useExistingEspIdfJsonSetup(workspaceRoot); }); registerIDFCommand("espIdf.importProject", async () => { diff --git a/src/setup/cmd.ts b/src/setup/cmd.ts index fe732d9c7..cbd959523 100644 --- a/src/setup/cmd.ts +++ b/src/setup/cmd.ts @@ -22,6 +22,7 @@ import { ExtensionContext, Progress, ProgressLocation, + Uri, window, } from "vscode"; import { getEspIdfVersions } from "./espIdfVersionList"; @@ -42,7 +43,7 @@ import { downloadEspIdfTools } from "./toolInstall"; import { isBinInPath } from "../utils"; import { pathExists } from "fs-extra"; -export async function useExistingEspIdfJsonSetup() { +export async function useExistingEspIdfJsonSetup(workspaceFolder: Uri) { const containerPath = process.platform === "win32" ? process.env.USERPROFILE : process.env.HOME; let toolsPath = join(containerPath, ".espressif"); @@ -97,7 +98,8 @@ export async function useExistingEspIdfJsonSetup() { exportedVars, toolsPath, espIdfVersion.gitPath, - ConfigurationTarget.Global + ConfigurationTarget.WorkspaceFolder, + workspaceFolder ); } @@ -115,7 +117,10 @@ export async function openFolder(openLabel: string) { } } -export async function downloadEspIdf(context: ExtensionContext) { +export async function downloadEspIdf( + context: ExtensionContext, + workspaceFolder: Uri +) { const espIdfVersions = await getEspIdfVersions(context.extensionPath); let quickPickItems = espIdfVersions.map((k) => { @@ -300,7 +305,8 @@ export async function downloadEspIdf(context: ExtensionContext) { exportedVars, toolsPath, idfGitPath, - ConfigurationTarget.Global + ConfigurationTarget.WorkspaceFolder, + workspaceFolder ); } );