diff --git a/src/Backend/API.ts b/src/Backend/API.ts index a313a28b..0974719f 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 1c9457a6..cda661a5 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"; @@ -198,15 +199,10 @@ class NodeFactory { "Config nodes cannot have attributes" ); const ext = path.extname(fpath); - switch (ext) { - case ".edgetpucfg": { - node = new ConfigNode(uri, parent, "one.editor.edgetpucfg"); - break; - } - case ".cfg": - default: { - node = new ConfigNode(uri, parent); - } + if (BackendContext.isRegistered("EdgeTPU") && ext === ".edgetpucfg") { + node = new ConfigNode(uri, parent, "one.editor.edgetpucfg"); + } else { + node = new ConfigNode(uri, parent); } break; } @@ -1027,19 +1023,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" }, ]; @@ -1054,7 +1039,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) { @@ -1065,7 +1049,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; @@ -1073,11 +1073,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); } /** @@ -1093,13 +1092,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); diff --git a/src/OneExplorer/OneStorage.ts b/src/OneExplorer/OneStorage.ts index 422ade9c..100f8b87 100644 --- a/src/OneExplorer/OneStorage.ts +++ b/src/OneExplorer/OneStorage.ts @@ -24,6 +24,7 @@ import { Logger } from "../Utils/Logger"; import { ConfigObj } from "./ConfigObject"; import { Node, NodeType } from "./OneExplorer"; +import { BackendContext } from "../Backend/API"; export { BaseModelToCfgMap as _unit_test_BaseModelToCfgMap, @@ -244,7 +245,7 @@ export class OneStorage { }; try { - const extList = [".cfg", ".edgetpucfg"]; + const extList = BackendContext.isRegistered("EdgeTPU") ? [".cfg", ".edgetpucfg"] : [".cfg"]; return roots .map((root) => diff --git a/src/extension.ts b/src/extension.ts index 74dc2102..051fe47f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -88,7 +88,7 @@ export function activate(context: vscode.ExtensionContext) { MPQSelectionPanel.register(context); API.registerBackend(new OneToolchain()); - API.registerBackend(new EdgeTPUToolchain()); + //API.registerBackend(new EdgeTPUToolchain()); // returning backend registration function that will be called by backend extensions return API;