Skip to content

Commit

Permalink
temp 5
Browse files Browse the repository at this point in the history
ONE-vscode-DCO-1.0-Signed-off-by: Dayoung Lee <[email protected]>
  • Loading branch information
dayo09 committed Oct 24, 2023
1 parent 3234fd6 commit f63119b
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 422 deletions.
77 changes: 8 additions & 69 deletions src/OneExplorer/ArtifactLocator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,7 @@

import * as assert from "assert";
import * as path from "path";
import * as vscode from "vscode";

/**
* 'Artifact'
* The collective term is and inclusive, it includes two types of files:
* (1) Pre-existing files to run ONE config, a.k.a. base models (.tflite, .onnx, ...)
* (2) Result files after running ONE config, a.k.a. products (.circle, .log, ...)
*/
export interface Artifact {
/**
* An artifact's attribute
*/
attr: ArtifactAttr;

/**
* A full path in file system
*/
path: string;
}

export interface ArtifactAttr {
/**
* ABOUT EXTENDED EXTENSION (WITH MULTIPLE PERIODS, *.extended.ext)
*
* Generally, file name extensions are defined from the last period.
* Let's define 'extended file extension' with multiple periods.
*
* EXAMPLE
*
* (File name) model.opt.circle.log
* (Extension) .log
* (Extended Extension) .circle.log OR opt.circle.log (selective)
*/
ext: string;

/**
* An icon for the artifact
*
* If not set, it is set by OneExplorer Node.
*/
icon?: vscode.ThemeIcon;

/**
* A openViewType for the artifact
*
* It is used as an argument for 'vscode.openWith' command
* to open the file with specified editor.
*
* If not set, it is set by OneExplorer Node.
* If 'default'(string), open with text editor
*
* @reference vscode.openWith
*/
openViewType?: string;

/**
* Hidden from the default view.
* The status can be unhide by command
*/
canHide?: boolean;
}
import {ArtifactType} from "./Artifact";

/**
* 'Locator' is to grep matching paths inside Ini Object
Expand Down Expand Up @@ -210,7 +150,7 @@ export class Locator {

// TODO Move to backend side with some modification
export class LocatorRunner {
private artifactLocators: { artifactAttr: ArtifactAttr; locator: Locator }[] =
private artifactLocators: { type: ArtifactType, locator: Locator }[] =
[];

/**
Expand Down Expand Up @@ -266,7 +206,7 @@ export class LocatorRunner {
};

public register(artifactLocator: {
artifactAttr: ArtifactAttr;
type: ArtifactType;
locator: Locator;
}) {
this.artifactLocators.push(artifactLocator);
Expand All @@ -275,22 +215,21 @@ export class LocatorRunner {
/**
* @brief Run registered locators
*
* @returns Artifact[] with paths
* @returns {ArtifactType: type, path: string}[] with paths
*/
public run(iniObj: object, dir: string): Artifact[] {
public run(iniObj: object, dir: string): {type:ArtifactType, path:string}[] {
assert.strictEqual(
path.isAbsolute(dir),
true,
"FIX CALLER: dir argument must be an absolute path"
);

let artifacts: Artifact[] = [];
let artifacts: {type:ArtifactType, path:string}[] = [];

// Get Artifacts with {type, ext, path}
this.artifactLocators.forEach(({ artifactAttr, locator }) => {
this.artifactLocators.forEach(({ type, locator }) => {
let filePaths: string[] = locator.locate(iniObj, dir);
filePaths.forEach((filePath) => {
let artifact: Artifact = { attr: artifactAttr, path: filePath };
let artifact = { type: type, path: filePath };
artifacts.push(artifact);
});
});
Expand Down
101 changes: 21 additions & 80 deletions src/OneExplorer/ConfigObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import * as vscode from "vscode";
import { RealPath } from "../Utils/Helpers";
import { Logger } from "../Utils/Logger";

import { Artifact, Locator, LocatorRunner } from "./ArtifactLocator";
import { Locator, LocatorRunner } from "./ArtifactLocator";
import { Artifact, ArtifactType} from "./Artifact";

type Cfg = {
"one-import-tflite": CfgOneImportTflite;
Expand Down Expand Up @@ -64,7 +65,7 @@ export class ConfigObj {
/**
* a parsed config object
*/
obj: { baseModels: Artifact[]; products: Artifact[] };
obj: { baseModels: {type: ArtifactType, path: string}[]; products: {type: ArtifactType, path: string}[] };

get getBaseModels() {
return this.obj.baseModels;
Expand All @@ -77,7 +78,7 @@ export class ConfigObj {
/**
* @brief Returns only the baseModels which exists in file system
*/
get getBaseModelsExists() {
get getBaseModelsExists() : {type: ArtifactType, path: string}[]{
return this.obj.baseModels.filter((artifact) =>
RealPath.exists(artifact.path)
);
Expand All @@ -86,7 +87,7 @@ export class ConfigObj {
/**
* @brief Returns only the products which exists in file system
*/
get getProductsExists() {
get getProductsExists() : {type: ArtifactType, path: string}[]{
return this.obj.products.filter((artifact) =>
RealPath.exists(artifact.path)
);
Expand Down Expand Up @@ -211,42 +212,33 @@ export class ConfigObj {
private static parseBaseModels = (
filePath: string,
iniObj: object
): Artifact[] => {
): {type: ArtifactType, path: string}[] => {
const dir = path.dirname(filePath);

let locatorRunner = new LocatorRunner();

locatorRunner.register({
artifactAttr: {
ext: ".tflite",
icon: new vscode.ThemeIcon("symbol-variable"),
},
type: "BASEMODEL_TFLITE",
locator: new Locator((value: string) =>
LocatorRunner.searchWithExt(".tflite", value)
),
});

locatorRunner.register({
artifactAttr: {
ext: ".pb",
icon: new vscode.ThemeIcon("symbol-variable"),
},
type: "BASEMODEL_PB",
locator: new Locator((value: string) =>
LocatorRunner.searchWithExt(".pb", value)
),
});

locatorRunner.register({
artifactAttr: {
ext: ".onnx",
icon: new vscode.ThemeIcon("symbol-variable"),
},
type: "BASEMODEL_ONNX",
locator: new Locator((value: string) =>
LocatorRunner.searchWithExt(".onnx", value)
),
});

let artifacts: Artifact[] = locatorRunner.run(iniObj, dir);
let artifacts: {type: ArtifactType, path: string}[] = locatorRunner.run(iniObj, dir);

if (artifacts.length > 1) {
// TODO Notify the error with a better UX
Expand Down Expand Up @@ -279,7 +271,7 @@ export class ConfigObj {
private static parseProducts = (
filePath: string,
iniObj: object
): Artifact[] => {
): {path: string, type: ArtifactType} [] => {
const dir = path.dirname(filePath);

let locatorRunner = new LocatorRunner();
Expand All @@ -291,34 +283,21 @@ export class ConfigObj {
*/

locatorRunner.register({
artifactAttr: {
ext: ".circle",
icon: new vscode.ThemeIcon("symbol-variable"),
openViewType: "one.viewer.circle",
},
type: "PRODUCT_CIRCLE",
locator: new Locator((value: string) =>
LocatorRunner.searchWithExt(".circle", value)
),
});

locatorRunner.register({
artifactAttr: {
ext: ".tvn",
icon: new vscode.ThemeIcon("symbol-variable"),
openViewType: "default",
},
type: "PRODUCT_TVN",
locator: new Locator((value: string) =>
LocatorRunner.searchWithExt(".tvn", value)
),
});

locatorRunner.register({
artifactAttr: {
ext: ".tracealloc.json",
icon: new vscode.ThemeIcon("graph"),
openViewType: "one.viewer.mondrian",
canHide: true,
},
type: "PRODUCT_MONDRIAN",
locator: new Locator((value: string) => {
return LocatorRunner.searchWithExt(".tvn", value).map((filepath) =>
filepath.replace(".tvn", ".tracealloc.json")
Expand All @@ -331,12 +310,7 @@ export class ConfigObj {
// REQUIRES: <model>.tvn be written in the config file.
// This rule is added to show a trace.json file generated by `one.toolchain.profileModel` command.
locatorRunner.register({
artifactAttr: {
ext: ".trace.json",
icon: new vscode.ThemeIcon("graph"),
openViewType: "default",
canHide: true,
},
type: "PRODUCT_CHROME_TRACE",
locator: new Locator((value: string) => {
return LocatorRunner.searchWithExt(".tvn", value).map((filepath) =>
filepath.replace(".tvn", ".trace.json")
Expand All @@ -345,12 +319,7 @@ export class ConfigObj {
});

locatorRunner.register({
artifactAttr: {
ext: ".json",
icon: new vscode.ThemeIcon("graph"),
openViewType: "default",
canHide: true,
},
type: "PRODUCT_CHROME_TRACE",
locator: new Locator(
(value: string) => {
return LocatorRunner.searchWithCommandOption(
Expand All @@ -365,12 +334,7 @@ export class ConfigObj {
});

locatorRunner.register({
artifactAttr: {
ext: ".tv2m",
icon: new vscode.ThemeIcon("symbol-method"),
openViewType: "default",
canHide: true,
},
type: "PRODUCT_TV2M",
locator: new Locator((value: string) => {
return LocatorRunner.searchWithExt(".tvn", value).map((filepath) =>
filepath.replace(".tvn", ".tv2m")
Expand All @@ -379,12 +343,7 @@ export class ConfigObj {
});

locatorRunner.register({
artifactAttr: {
ext: ".tv2o",
icon: new vscode.ThemeIcon("symbol-method"),
openViewType: "default",
canHide: true,
},
type: "PRODUCT_TV2O",
locator: new Locator((value: string) => {
return LocatorRunner.searchWithExt(".tvn", value).map((filepath) =>
filepath.replace(".tvn", ".tv2o")
Expand All @@ -393,12 +352,7 @@ export class ConfigObj {
});

locatorRunner.register({
artifactAttr: {
ext: ".tv2w",
icon: new vscode.ThemeIcon("symbol-method"),
openViewType: "default",
canHide: true,
},
type: "PRODUCT_TV2W",
locator: new Locator((value: string) => {
return LocatorRunner.searchWithExt(".tvn", value).map((filepath) =>
filepath.replace(".tvn", ".tv2w")
Expand All @@ -407,28 +361,15 @@ export class ConfigObj {
});

locatorRunner.register({
// 'default' view type is 'text editor' (vscode.openWith)
artifactAttr: {
ext: ".circle.log",
openViewType: "default",
icon: vscode.ThemeIcon.File,
canHide: true,
},
type: "PRODUCT_CIRCLE_LOG",
locator: new Locator((value: string) => {
return LocatorRunner.searchWithExt(".circle", value).map((filepath) =>
filepath.replace(".circle", ".circle.log")
);
}),
});

/**
* When you add a new product type, please append the ext type to
* OneTreeDataProvider.fileWatcher too, to prevent a bug.
*
* TODO Provide better structure to remove this extra work
*/

let artifacts: Artifact[] = locatorRunner.run(iniObj, dir);
let artifacts: {path: string, type: ArtifactType} [] = locatorRunner.run(iniObj, dir);

return artifacts;
};
Expand Down
Loading

0 comments on commit f63119b

Please sign in to comment.