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..2f2d7425 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,8 @@ 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, - extName: string - ): Promise { - //Options must be added according to extension + 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" }, ]; @@ -1165,7 +1155,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) { @@ -1176,7 +1165,23 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider { selectedLabel = selectedOption?.label; } - switch (selectedLabel) { + return 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 +1189,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 +1208,17 @@ 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);