From a5ec84b70e4af56e524ec86ac2c6e9bdbdf6d186 Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Wed, 30 Oct 2024 18:55:55 +0800 Subject: [PATCH 1/2] add idf path idf tools path to created example --- src/examples/ExamplesPanel.ts | 42 +++++++++++++++--- src/extension.ts | 71 ++++++++++++++++++++----------- src/newProject/newProjectInit.ts | 44 +++++++++++++++---- src/newProject/newProjectPanel.ts | 6 +++ src/newProject/utils.ts | 8 ++-- src/test/project.test.ts | 2 + src/utils.ts | 2 +- 7 files changed, 130 insertions(+), 45 deletions(-) diff --git a/src/examples/ExamplesPanel.ts b/src/examples/ExamplesPanel.ts index 0cc97e88f..dbe4e30a2 100644 --- a/src/examples/ExamplesPanel.ts +++ b/src/examples/ExamplesPanel.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { ensureDir, readFile } from "fs-extra"; +import { ensureDir, readFile, readJSON, writeJSON } from "fs-extra"; import * as path from "path"; import * as vscode from "vscode"; import { Logger } from "../logger/logger"; @@ -22,6 +22,7 @@ import { ESP } from "../config"; import { getExamplesList, IExampleCategory } from "./Example"; import { ComponentManagerUIPanel } from "../component-manager/panel"; import { OutputChannel } from "../logger/outputChannel"; +import { IdfSetup } from "../views/setup/types"; export class ExamplesPlanel { public static currentPanel: ExamplesPlanel | undefined; @@ -29,7 +30,8 @@ export class ExamplesPlanel { public static createOrShow( extensionPath: string, targetFrameworkFolder: string, - targetDesc: string + targetDesc: string, + idfSetup: IdfSetup ) { const column = vscode.window.activeTextEditor ? vscode.window.activeTextEditor.viewColumn @@ -41,7 +43,8 @@ export class ExamplesPlanel { extensionPath, column, targetFrameworkFolder, - targetDesc + targetDesc, + idfSetup ); } } @@ -54,7 +57,8 @@ export class ExamplesPlanel { extensionPath: string, column: vscode.ViewColumn, targetFrameworkFolder: string, - targetDesc: string + targetDesc: string, + idfSetup: IdfSetup ) { const panelTitle = vscode.l10n.t("{targetDesc} Examples", { targetDesc }); this.panel = vscode.window.createWebviewPanel( @@ -111,6 +115,16 @@ export class ExamplesPlanel { vscode.Uri.file(resultFolder) ); const projectPath = vscode.Uri.file(resultFolder); + const settingsJsonPath = path.join( + resultFolder, + ".vscode", + "settings.json" + ); + await this.setCurrentSettingsInTemplate( + settingsJsonPath, + idfSetup.idfPath, + idfSetup.toolsPath + ); vscode.commands.executeCommand("vscode.openFolder", projectPath); } catch (error) { const msg = `Error copying ESP-IDF example.`; @@ -165,7 +179,11 @@ export class ExamplesPlanel { ComponentManagerUIPanel.show(extensionPath, emptyURI); } catch (error) { OutputChannel.appendLine(error.message); - Logger.errorNotify(error.message, error, "ExamplesPanel show registry"); + Logger.errorNotify( + error.message, + error, + "ExamplesPanel show registry" + ); } default: return; @@ -198,4 +216,18 @@ export class ExamplesPlanel { selected_example: selectedExample, }); } + + private async setCurrentSettingsInTemplate( + settingsJsonPath: string, + idfPathDir: string, + toolsPath: string + ) { + const settingsJson = await readJSON(settingsJsonPath); + const isWin = process.platform === "win32" ? "Win" : ""; + settingsJson["idf.espIdfPath" + isWin] = idfPathDir; + settingsJson["idf.toolsPath" + isWin] = toolsPath; + await writeJSON(settingsJsonPath, settingsJson, { + spaces: vscode.workspace.getConfiguration().get("editor.tabSize") || 2, + }); + } } diff --git a/src/extension.ts b/src/extension.ts index 9a65ebc34..32d72b230 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -130,7 +130,10 @@ import { getProjectConfigurationElements, ProjectConfigStore, } from "./project-conf"; -import { clearPreviousIdfSetups } from "./setup/existingIdfSetups"; +import { + clearPreviousIdfSetups, + getPreviousIdfSetups, +} from "./setup/existingIdfSetups"; import { getEspRainmaker } from "./rainmaker/download/espRainmakerDownload"; import { UnitTest } from "./espIdf/unitTest/adapter"; import { @@ -161,6 +164,7 @@ import { createCommandDictionary, IDFWebCommandKeys, } from "./cmdTreeView/cmdStore"; +import { IdfSetup } from "./views/setup/types"; // Global variables shared by commands let workspaceRoot: vscode.Uri; @@ -1955,19 +1959,6 @@ export async function activate(context: vscode.ExtensionContext) { }); registerIDFCommand("espIdf.examples.start", async () => { - const pickItems = await getFrameworksPickItems(); - if (!pickItems || pickItems.length == 0) { - return Logger.infoNotify(vscode.l10n.t("No ESP-IDF frameworks found")); - } - const examplesFolder = await vscode.window.showQuickPick(pickItems, { - placeHolder: vscode.l10n.t("Select framework to use"), - }); - if (!examplesFolder) { - Logger.infoNotify( - vscode.l10n.t("No framework selected to load examples.") - ); - return; - } try { const notificationMode = idfConf.readParameter( "idf.notificationMode", @@ -1988,6 +1979,24 @@ export async function activate(context: vscode.ExtensionContext) { progress: vscode.Progress<{ message: string; increment: number }> ) => { try { + const pickItems = await getFrameworksPickItems(); + if (!pickItems || pickItems.length == 0) { + return Logger.infoNotify( + vscode.l10n.t("No ESP-IDF frameworks found") + ); + } + const examplesFolder = await vscode.window.showQuickPick( + pickItems, + { + placeHolder: vscode.l10n.t("Select framework to use"), + } + ); + if (!examplesFolder) { + Logger.infoNotify( + vscode.l10n.t("No framework selected to load examples.") + ); + return; + } const doesFolderExist = await utils.dirExistPromise( examplesFolder.target ); @@ -1998,7 +2007,8 @@ export async function activate(context: vscode.ExtensionContext) { ExamplesPlanel.createOrShow( context.extensionPath, examplesFolder.target, - examplesFolder.description + examplesFolder.description, + examplesFolder.idfSetup ); } catch (error) { Logger.errorNotify( @@ -3669,10 +3679,6 @@ export async function activate(context: vscode.ExtensionContext) { } async function getFrameworksPickItems() { - const espIdfPath = idfConf.readParameter( - "idf.espIdfPath", - workspaceRoot - ) as string; const espAdfPath = idfConf.readParameter( "idf.espAdfPath", workspaceRoot @@ -3695,16 +3701,24 @@ async function getFrameworksPickItems() { workspaceRoot ) as string; - const pickItems = []; + const pickItems: { + description: string; + label: string; + target: string; + idfSetup: IdfSetup; + }[] = []; try { - const doesIdfPathExists = await utils.dirExistPromise(espIdfPath); - if (doesIdfPathExists) { + const idfSetups = await getPreviousIdfSetups(true); + const currentIdfSetup = await getCurrentIdfSetup(workspaceRoot); + const onlyValidIdfSetups = idfSetups.filter((i) => i.isValid); + for (const idfSetup of onlyValidIdfSetups) { pickItems.push({ - description: "ESP-IDF", - label: vscode.l10n.t(`Use current ESP-IDF {espIdfPath}`, { - espIdfPath, + description: `ESP-IDF v${idfSetup.version}`, + label: vscode.l10n.t(`Use ESP-IDF {espIdfPath}`, { + espIdfPath: idfSetup.idfPath, }), - target: espIdfPath, + target: idfSetup.idfPath, + idfSetup, }); } const doesAdfPathExists = await utils.dirExistPromise(espAdfPath); @@ -3715,6 +3729,7 @@ async function getFrameworksPickItems() { espAdfPath, }), target: espAdfPath, + idfSetup: currentIdfSetup, }); } const doesMdfPathExists = await utils.dirExistPromise(espMdfPath); @@ -3725,6 +3740,7 @@ async function getFrameworksPickItems() { espMdfPath, }), target: espMdfPath, + idfSetup: currentIdfSetup, }); } const doesMatterPathExists = await utils.dirExistPromise(matterPathDir); @@ -3735,6 +3751,7 @@ async function getFrameworksPickItems() { matterPathDir, }), target: matterPathDir, + idfSetup: currentIdfSetup, }); } const doesEspRainmakerPathExists = await utils.dirExistPromise( @@ -3747,6 +3764,7 @@ async function getFrameworksPickItems() { rainmakerPathDir, }), target: rainmakerPathDir, + idfSetup: currentIdfSetup, }); } const doesEspHomeKitSdkPathExists = await utils.dirExistPromise( @@ -3760,6 +3778,7 @@ async function getFrameworksPickItems() { { espHomeKitPathDir } ), target: espHomeKitPathDir, + idfSetup: currentIdfSetup, }); } } catch (error) { diff --git a/src/newProject/newProjectInit.ts b/src/newProject/newProjectInit.ts index c511ce5c1..c498503a7 100644 --- a/src/newProject/newProjectInit.ts +++ b/src/newProject/newProjectInit.ts @@ -11,7 +11,7 @@ // 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 { Progress, Uri } from "vscode"; +import { l10n, Progress, window, Uri } from "vscode"; import { getExamplesList, IExampleCategory } from "../examples/Example"; import { IComponent } from "../espIdf/idfComponent/IdfComponent"; import * as idfConf from "../idfConfiguration"; @@ -23,9 +23,12 @@ import { getOpenOcdScripts, IdfBoard, } from "../espIdf/openOcd/boardConfiguration"; +import { getPreviousIdfSetups } from "../setup/existingIdfSetups"; +import { IdfSetup } from "../views/setup/types"; export interface INewProjectArgs { espIdfPath: string; + espIdfToolsPath: string; espAdfPath: string; espMdfPath: string; espMatterPath: string; @@ -63,11 +66,33 @@ export async function getNewProjectArgs( progress.report({ increment: 10, message: "Loading ESP-IDF Boards list..." }); const openOcdScriptsPath = await getOpenOcdScripts(workspace); let espBoards = await getBoards(openOcdScriptsPath); - progress.report({ increment: 10, message: "Loading ESP-IDF Target list..." }); - const espIdfPath = idfConf.readParameter( - "idf.espIdfPath", - workspace - ) as string; + progress.report({ increment: 10, message: "Loading ESP-IDF setups list..." }); + const idfSetups = await getPreviousIdfSetups(true); + const onlyValidIdfSetups = idfSetups.filter((i) => i.isValid); + const pickItems: {description: string, label: string, target: IdfSetup}[] = []; + for (const idfSetup of onlyValidIdfSetups) { + pickItems.push({ + description: `ESP-IDF v${idfSetup.version}`, + label: l10n.t(`Use ESP-IDF {espIdfPath}`, { + espIdfPath: idfSetup.idfPath, + }), + target: idfSetup, + }); + } + progress.report({ increment: 10, message: "Select ESP-IDF to use..." }); + const espIdfPathToUse = await window.showQuickPick( + pickItems, + { + placeHolder: l10n.t("Select framework to use"), + } + ); + if (!espIdfPathToUse) { + Logger.infoNotify( + l10n.t("No framework selected to load examples.") + ); + return; + } + const idfSetup = espIdfPathToUse.target; const espAdfPath = idfConf.readParameter( "idf.espAdfPath", workspace @@ -90,9 +115,9 @@ export async function getNewProjectArgs( ) as string; let templates: { [key: string]: IExampleCategory } = {}; templates["Extension"] = getExamplesList(extensionPath, "templates"); - const idfExists = await dirExistPromise(espIdfPath); + const idfExists = await dirExistPromise(idfSetup.idfPath); if (idfExists) { - const idfTemplates = getExamplesList(espIdfPath); + const idfTemplates = getExamplesList(idfSetup.idfPath); templates["ESP-IDF"] = idfTemplates; } const adfExists = await dirExistPromise(espAdfPath); @@ -124,8 +149,9 @@ export async function getNewProjectArgs( return { boards: espBoards, components, + espIdfToolsPath: idfSetup.toolsPath, espAdfPath: adfExists ? espAdfPath : undefined, - espIdfPath: idfExists ? espIdfPath : undefined, + espIdfPath: idfExists ? idfSetup.idfPath : undefined, espMdfPath: mdfExists ? espMdfPath : undefined, espMatterPath: matterExists ? espMatterPath : undefined, espHomeKitSdkPath: homekitSdkExists ? espHomeKitSdkPath : undefined, diff --git a/src/newProject/newProjectPanel.ts b/src/newProject/newProjectPanel.ts index ef0c02ad0..316779a05 100644 --- a/src/newProject/newProjectPanel.ts +++ b/src/newProject/newProjectPanel.ts @@ -124,6 +124,8 @@ export class NewProjectPanel { message.template ) { this.createProject( + newProjectArgs.espIdfPath, + newProjectArgs.espIdfToolsPath, JSON.parse(message.components), message.port, message.containerFolder, @@ -197,6 +199,8 @@ export class NewProjectPanel { } private async createProject( + idfPath: string, + idfToolsPath: string, components: IComponent[], port: string, projectDirectory: string, @@ -283,6 +287,8 @@ export class NewProjectPanel { ); const settingsJson = await setCurrentSettingsInTemplate( settingsJsonPath, + idfPath, + idfToolsPath, port, openOcdConfigs, workspaceFolder diff --git a/src/newProject/utils.ts b/src/newProject/utils.ts index 01225c676..195a1d7a5 100644 --- a/src/newProject/utils.ts +++ b/src/newProject/utils.ts @@ -22,15 +22,15 @@ import { Uri } from "vscode"; export async function setCurrentSettingsInTemplate( settingsJsonPath: string, + idfPathDir: string, + toolsPath: string, port: string, openOcdConfigs?: string, workspace?: Uri ) { const settingsJson = await readJSON(settingsJsonPath); - const idfPathDir = readParameter("idf.espIdfPath", workspace); const adfPathDir = readParameter("idf.espAdfPath", workspace); const mdfPathDir = readParameter("idf.espMdfPath", workspace); - const toolsDir = readParameter("idf.toolsPath", workspace); const isWin = process.platform === "win32" ? "Win" : ""; if (idfPathDir) { settingsJson["idf.espIdfPath" + isWin] = idfPathDir; @@ -50,8 +50,8 @@ export async function setCurrentSettingsInTemplate( if (port.indexOf("no port") === -1) { settingsJson["idf.port" + isWin] = port; } - if (toolsDir) { - settingsJson["idf.toolsPath" + isWin] = toolsDir; + if (toolsPath) { + settingsJson["idf.toolsPath" + isWin] = toolsPath; } return settingsJson; } diff --git a/src/test/project.test.ts b/src/test/project.test.ts index aad095684..c7cb69e4c 100644 --- a/src/test/project.test.ts +++ b/src/test/project.test.ts @@ -149,6 +149,8 @@ suite("Project tests", () => { "interface/ftdi/esp32_devkitj_v1.cfg,target/esp32.cfg"; const newSettingsJson = await setCurrentSettingsInTemplate( settingsJsonPath, + process.env.IDF_PATH, + process.env.IDF_TOOLS_PATH, "no port", openOcdConfigs, Uri.file(projectPath) diff --git a/src/utils.ts b/src/utils.ts index 859f91d6f..4c86fed5b 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -403,9 +403,9 @@ export async function copyFromSrcProject( srcDirPath: string, destinationDir: vscode.Uri ) { + await copy(srcDirPath, destinationDir.fsPath); await createVscodeFolder(destinationDir); await createDevContainer(destinationDir.fsPath); - await copy(srcDirPath, destinationDir.fsPath); } export function getVariableFromCMakeLists(workspacePath: string, key: string) { From 56aa2ef7fbbcdf5ccc4a6c22c734167479e7846f Mon Sep 17 00:00:00 2001 From: Brian Ignacio Date: Fri, 8 Nov 2024 16:30:44 +0800 Subject: [PATCH 2/2] update translation --- l10n/bundle.l10n.es.json | 2 +- l10n/bundle.l10n.pt.json | 2 +- l10n/bundle.l10n.ru.json | 2 +- l10n/bundle.l10n.zh-CN.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/l10n/bundle.l10n.es.json b/l10n/bundle.l10n.es.json index 1aa0de980..0ef2db1fd 100644 --- a/l10n/bundle.l10n.es.json +++ b/l10n/bundle.l10n.es.json @@ -107,7 +107,7 @@ "ESP-IDF: Please wait mapping your rainmaker cloud account with the VS Code Extension, this could take a little while": "ESP-IDF: Espere a mapear su cuenta de nube Rainmaker con la extensión VS Code, esto podría tomar un poco de tiempo.", "Rainmaker Cloud is connected successfully (via OAuth)!": "¡Rainmaker Cloud está conectado correctamente (a través de OAuth)!", "Failed to sign-in with Rainmaker (via OAuth)": "No se pudo iniciar sesión con Rainmaker (a través de OAuth)", - "Use current ESP-IDF {espIdfPath}": "Utilice ESP-IDF actual {espIdfPath}", + "Use ESP-IDF {espIdfPath}": "Utilice ESP-IDF {espIdfPath}", "Use current ESP-ADF {espAdfPath}": "Utilice ESP-ADF actual {espAdfPath}", "Use current ESP-MDF {espMdfPath}": "Utilice ESP-MDF actual {espMdfPath}", "Use current ESP-Matter {matterPathDir}": "Utilice ESP-Matter actual {matterPathDir}", diff --git a/l10n/bundle.l10n.pt.json b/l10n/bundle.l10n.pt.json index 42fe8c041..8938f8dc6 100644 --- a/l10n/bundle.l10n.pt.json +++ b/l10n/bundle.l10n.pt.json @@ -107,7 +107,7 @@ "ESP-IDF: Please wait mapping your rainmaker cloud account with the VS Code Extension, this could take a little while": "ESP-IDF: Aguarde mapeando sua conta do Rainmaker Cloud com a extensão VS Code, isso pode demorar um pouco", "Rainmaker Cloud is connected successfully (via OAuth)!": "Rainmaker Cloud foi conectado com sucesso (via OAuth)!", "Failed to sign-in with Rainmaker (via OAuth)": "Falha ao fazer login com Rainmaker (via OAuth)", - "Use current ESP-IDF {espIdfPath}": "Usar ESP-IDF atual {espIdfPath}", + "Use ESP-IDF {espIdfPath}": "Usar ESP-IDF {espIdfPath}", "Use current ESP-ADF {espAdfPath}": "Usar ESP-ADF atual {espAdfPath}", "Use current ESP-MDF {espMdfPath}": "Use ESP-MDF atual {espMdfPath}", "Use current ESP-Matter {matterPathDir}": "Use ESP-Matter atual {matterPathDir}", diff --git a/l10n/bundle.l10n.ru.json b/l10n/bundle.l10n.ru.json index 45f54e41a..7ffaa3e0c 100644 --- a/l10n/bundle.l10n.ru.json +++ b/l10n/bundle.l10n.ru.json @@ -107,7 +107,7 @@ "ESP-IDF: Please wait mapping your rainmaker cloud account with the VS Code Extension, this could take a little while": "ESP-IDF: подождите, сопоставьте свою облачную учетную запись Rainmaker с расширением VS Code Extension, это может занять некоторое время.", "Rainmaker Cloud is connected successfully (via OAuth)!": "Rainmaker Cloud успешно подключен (через OAuth)!", "Failed to sign-in with Rainmaker (via OAuth)": "Не удалось войти в систему с помощью Rainmaker (через OAuth).", - "Use current ESP-IDF {espIdfPath}": "Использовать текущий ESP-IDF {espIdfPath}", + "Use current ESP-IDF {espIdfPath}": "Используйте ESP-IDF {espIdfPath}", "Use current ESP-ADF {espAdfPath}": "Использовать текущий ESP-ADF {espAdfPath}", "Use current ESP-MDF {espMdfPath}": "Использовать текущий ESP-MDF {espMdfPath}", "Use current ESP-Matter {matterPathDir}": "Использовать текущий ESP-Matter {matterPathDir}", diff --git a/l10n/bundle.l10n.zh-CN.json b/l10n/bundle.l10n.zh-CN.json index e27cf0ded..bb56f7d92 100644 --- a/l10n/bundle.l10n.zh-CN.json +++ b/l10n/bundle.l10n.zh-CN.json @@ -107,7 +107,7 @@ "ESP-IDF: Please wait mapping your rainmaker cloud account with the VS Code Extension, this could take a little while": "ESP-IDF:请等待使用 VS Code 扩展映射您的 Rainmaker 帐户,这可能需要一些时间", "Rainmaker Cloud is connected successfully (via OAuth)!": "Rainmaker Cloud 已成功连接(通过 OAuth)!", "Failed to sign-in with Rainmaker (via OAuth)": "无法使用 Rainmaker 登录(通过 OAuth)", - "Use current ESP-IDF {espIdfPath}": "使用当前 ESP-IDF {espIdfPath}", + "Use ESP-IDF {espIdfPath}": "使用 ESP-IDF {espIdfPath}", "Use current ESP-ADF {espAdfPath}": "使用当前 ESP-ADF {espAdfPath}", "Use current ESP-MDF {espMdfPath}": "使用当前 ESP-MDF {espMdfPath}", "Use current ESP-Matter {matterPathDir}": "使用当前 ESP-Matter {matterPathDir}",