From 286acbc6c7038ec683b9149f933c2fc8049a6d41 Mon Sep 17 00:00:00 2001 From: Dayoung Lee Date: Wed, 1 Nov 2023 17:42:35 +0900 Subject: [PATCH 1/2] [EdgeTPU] Bind CFG creation to backend This commit binds edgetpu creation feature to EdgeTPU Backend functionally. ONE-vscode-DCO-1.0-Signed-off-by: Dayoung Lee --- src/Backend/API.ts | 1 + src/OneExplorer/OneExplorer.ts | 48 ++++++++++++++++++++-------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/Backend/API.ts b/src/Backend/API.ts index 5b351290..1e2de200 100644 --- a/src/Backend/API.ts +++ b/src/Backend/API.ts @@ -67,6 +67,7 @@ const registerBackend = (backend: Backend) => { // TODO: Consider better way to refresh toolchainView after backend's registration. vscode.commands.executeCommand("one.toolchain.refresh"); vscode.commands.executeCommand("one.device.refresh"); + vscode.commands.executeCommand("one.explorer.refresh"); }; export const API = { diff --git a/src/OneExplorer/OneExplorer.ts b/src/OneExplorer/OneExplorer.ts index 082ee109..8cd14118 100644 --- a/src/OneExplorer/OneExplorer.ts +++ b/src/OneExplorer/OneExplorer.ts @@ -19,6 +19,7 @@ import * as fs from "fs"; import * as path from "path"; import * as vscode from "vscode"; +import { BackendContext } from "../Backend/API"; import { obtainWorkspaceRoots } from "../Utils/Helpers"; import { Logger } from "../Utils/Logger"; @@ -1138,19 +1139,10 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { }); } - /** - * Select the option for the configuration you want to create - * Return information about the selected option - * - * @param modelName A base model's name - * @param extName A base model's extension name - * - */ - private async generateCfgInfo( - modelName: string, + private async askCfgExt( extName: string - ): Promise { - //Options must be added according to extension + ): Promise { + // Options must be added according to extension const options: vscode.QuickPickItem[] = [ { label: ".cfg", description: "configuration file of onecc compiler" }, ]; @@ -1165,7 +1157,6 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { const placeHolder = options.map((option) => option.label).join(" / "); let selectedLabel: string | undefined = ".cfg"; - let cfgData: ICfgData | undefined = undefined; //If options array only has the `.cfg` option, skip selecting it. if (options.length !== 1) { @@ -1175,8 +1166,24 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { }); selectedLabel = selectedOption?.label; } + + return selectedLabel; + } - switch (selectedLabel) { + /** + * Select the option for the configuration you want to create + * Return information about the selected option + * + * @param modelName A base model's name + * @param extName A base model's extension name + */ + private async generateCfgInfo( + modelName: string, + extName: string, + cfgExt: string + ): Promise { + let cfgData : ICfgData | undefined = undefined; + switch (cfgExt) { case ".cfg": cfgData = new CfgData(); break; @@ -1184,11 +1191,10 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { cfgData = new EdgeTPUCfgData(); break; default: - cfgData = undefined; - break; + throw Error("OneExplorer: Cannot reach here"); } - return cfgData?.generateCfgInfo(modelName, extName); + return cfgData!.generateCfgInfo(modelName, extName); } /** @@ -1204,13 +1210,15 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { const modelName = path.parse(node.path).name; const extName = path.parse(node.path).ext.slice(1); - const cfgInfo = await this.generateCfgInfo(modelName, extName); + const cfgExt = BackendContext.isRegistered("EdgeTPU") ? await this.askCfgExt(extName) : ".cfg"; - //When the user presses the ESC button, it is cancelled - if (cfgInfo === undefined) { + if (cfgExt === undefined) { + // When the user presses the ESC button, it is cancelled return; } + const cfgInfo = await this.generateCfgInfo(modelName, extName, cfgExt); + // TODO(dayo) Auto-configure more fields const validateInputPath = (cfgName: string): string | undefined => { const cfgPath: string = path.join(dirPath, cfgName); From 392a4a155f4c997e419a64d82b11e41a2d26f438 Mon Sep 17 00:00:00 2001 From: Dayoung Lee Date: Fri, 3 Nov 2023 13:45:12 +0900 Subject: [PATCH 2/2] Format ONE-vscode-DCO-1.0-Signed-off-by: Dayoung Lee --- src/OneExplorer/OneExplorer.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/OneExplorer/OneExplorer.ts b/src/OneExplorer/OneExplorer.ts index 8cd14118..2f2d7425 100644 --- a/src/OneExplorer/OneExplorer.ts +++ b/src/OneExplorer/OneExplorer.ts @@ -1139,9 +1139,7 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { }); } - private async askCfgExt( - extName: string - ): Promise { + private async askCfgExt(extName: string): Promise { // Options must be added according to extension const options: vscode.QuickPickItem[] = [ { label: ".cfg", description: "configuration file of onecc compiler" }, @@ -1166,7 +1164,7 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { }); selectedLabel = selectedOption?.label; } - + return selectedLabel; } @@ -1182,7 +1180,7 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { extName: string, cfgExt: string ): Promise { - let cfgData : ICfgData | undefined = undefined; + let cfgData: ICfgData | undefined = undefined; switch (cfgExt) { case ".cfg": cfgData = new CfgData(); @@ -1210,7 +1208,9 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { const modelName = path.parse(node.path).name; const extName = path.parse(node.path).ext.slice(1); - const cfgExt = BackendContext.isRegistered("EdgeTPU") ? await this.askCfgExt(extName) : ".cfg"; + const cfgExt = BackendContext.isRegistered("EdgeTPU") + ? await this.askCfgExt(extName) + : ".cfg"; if (cfgExt === undefined) { // When the user presses the ESC button, it is cancelled