Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VSC-1514] add idf path idf tools path to created example #1332

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion l10n/bundle.l10n.es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
2 changes: 1 addition & 1 deletion l10n/bundle.l10n.pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
2 changes: 1 addition & 1 deletion l10n/bundle.l10n.ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
2 changes: 1 addition & 1 deletion l10n/bundle.l10n.zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}",
Expand Down
42 changes: 37 additions & 5 deletions src/examples/ExamplesPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -22,14 +22,16 @@ 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;

public static createOrShow(
extensionPath: string,
targetFrameworkFolder: string,
targetDesc: string
targetDesc: string,
idfSetup: IdfSetup
) {
const column = vscode.window.activeTextEditor
? vscode.window.activeTextEditor.viewColumn
Expand All @@ -41,7 +43,8 @@ export class ExamplesPlanel {
extensionPath,
column,
targetFrameworkFolder,
targetDesc
targetDesc,
idfSetup
);
}
}
Expand All @@ -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(
Expand Down Expand Up @@ -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.`;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
});
}
}
71 changes: 45 additions & 26 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand All @@ -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
);
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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}`, {
brianignacio5 marked this conversation as resolved.
Show resolved Hide resolved
espIdfPath: idfSetup.idfPath,
}),
target: espIdfPath,
target: idfSetup.idfPath,
idfSetup,
});
}
const doesAdfPathExists = await utils.dirExistPromise(espAdfPath);
Expand All @@ -3715,6 +3729,7 @@ async function getFrameworksPickItems() {
espAdfPath,
}),
target: espAdfPath,
idfSetup: currentIdfSetup,
});
}
const doesMdfPathExists = await utils.dirExistPromise(espMdfPath);
Expand All @@ -3725,6 +3740,7 @@ async function getFrameworksPickItems() {
espMdfPath,
}),
target: espMdfPath,
idfSetup: currentIdfSetup,
});
}
const doesMatterPathExists = await utils.dirExistPromise(matterPathDir);
Expand All @@ -3735,6 +3751,7 @@ async function getFrameworksPickItems() {
matterPathDir,
}),
target: matterPathDir,
idfSetup: currentIdfSetup,
});
}
const doesEspRainmakerPathExists = await utils.dirExistPromise(
Expand All @@ -3747,6 +3764,7 @@ async function getFrameworksPickItems() {
rainmakerPathDir,
}),
target: rainmakerPathDir,
idfSetup: currentIdfSetup,
});
}
const doesEspHomeKitSdkPathExists = await utils.dirExistPromise(
Expand All @@ -3760,6 +3778,7 @@ async function getFrameworksPickItems() {
{ espHomeKitPathDir }
),
target: espHomeKitPathDir,
idfSetup: currentIdfSetup,
});
}
} catch (error) {
Expand Down
44 changes: 35 additions & 9 deletions src/newProject/newProjectInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Loading