Skip to content

Commit

Permalink
Support Optional Update on Change Event
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 4, 2023
1 parent 4aed26f commit 02b8134
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 15 deletions.
2 changes: 1 addition & 1 deletion res/modelDir/truediv/model.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ one-pack=False
one-codegen=True

[one-import-tflite]
input_path=./model.tflite
input_path=./model2.tflite
output_path=./model.circle

[one-quantize]
Expand Down
34 changes: 34 additions & 0 deletions src/OneExplorer/ConfigObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,40 @@ export class ConfigObj {
};
}

static diffBaseModels(newCfgObj?: ConfigObj, oldCfgObj?: ConfigObj):[addedBaseModels: string[], removedBaseModels:string[]]{
const newBaseModels = newCfgObj?.getBaseModelsExists.map(artifact=>artifact.path) ?? [];
const oldBaseModels = oldCfgObj?.getBaseModelsExists.map(artifact=>artifact.path) ?? [];

const addedBaseModels = newBaseModels.filter(path=>
!oldBaseModels.includes(path)
) ?? [];

const removedBaseModels = oldBaseModels.filter(path=>
!newBaseModels.includes(path)
) ?? [];

return [addedBaseModels, removedBaseModels];
}

static diffProducts(newCfgObj?: ConfigObj, oldCfgObj?: ConfigObj):[addedProducts: string[], removedProducts:string[]]{
const newProducts = newCfgObj?.getProductsExists.map(artifact=>artifact.path);
const oldProducts = oldCfgObj?.getProductsExists.map(artifact=>artifact.path);

const addedProducts = newProducts?.filter(artifact=>{
!oldProducts?.some(a=>
a === artifact
);
}) ?? [];

const removedProducts = oldProducts?.filter(artifact=>{
!newProducts?.some(a=>
a === artifact
);
}) ?? [];

return [addedProducts, removedProducts];
}

public updateBaseModelField(
oldpath: string,
newpath: string
Expand Down
57 changes: 43 additions & 14 deletions src/OneExplorer/OneExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { CfgEditorPanel } from "../CfgEditor/CfgEditorPanel";
import { obtainWorkspaceRoots } from "../Utils/Helpers";
import { Logger } from "../Utils/Logger";

import { ConfigObj } from "./ConfigObject";
import { ArtifactAttr } from "./ArtifactLocator";
import { OneStorage } from "./OneStorage";

Expand Down Expand Up @@ -516,6 +517,15 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
readonly onDidChangeTreeData: vscode.Event<Node | undefined | void> =
this._onDidChangeTreeData.event;

private _onDidDeleteNode: vscode.EventEmitter<Node> =
new vscode.EventEmitter<Node>();
readonly onDidDeleteNode: vscode.Event<Node> = this._onDidDeleteNode.event;

private _onDidChangeConfigNode: vscode.EventEmitter<Node> =
new vscode.EventEmitter<Node>();
readonly onDidChangeConfigNode: vscode.Event<Node> =
this._onDidChangeConfigNode.event;

private fileWatcher = vscode.workspace.createFileSystemWatcher(`**/*`);

private _tree: Node[] | undefined;
Expand Down Expand Up @@ -543,20 +553,36 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
provider.refresh();
}),
provider.fileWatcher.onDidChange((uri: vscode.Uri) => {
if (
[
...BaseModelNode.extList,
...ConfigNode.extList,
...ProductNode.extList,
].includes(path.parse(uri.path).ext)
) {
Logger.info(
"OneExploer",
`Refresh explorer view on a file change in '${uri.path}'`
);
// TODO Handle by each node types
provider.refresh();
const node = OneStorage.getNode(uri.fsPath);
if (!node) {
return;
}

Logger.info(
"OneExplorer",
`Refresh explorer view on a file change in '${uri.path}'`
);

if (ConfigNode.extList.includes(path.parse(uri.path).ext)) {
provider._onDidChangeConfigNode.fire(node);
}
}),
provider.onDidChangeConfigNode((node: Node) => {
const [addedBaseModels, removedBaseModels] = ConfigObj.diffBaseModels(
ConfigObj.createConfigObj(node.uri) ?? undefined,
OneStorage.getCfgObj(node.path)
);

const nodesForUpdate = [...addedBaseModels, ...removedBaseModels]
.map((path) => OneStorage.getNode(path))
.concat([node]);

nodesForUpdate.forEach((_node) => {
if (_node) {
OneStorage.delete(_node);
provider._onDidChangeTreeData.fire(_node.parent);
}
});
}),
provider.fileWatcher.onDidDelete((uri: vscode.Uri) => {
const node = OneStorage.getNode(uri.fsPath);
Expand All @@ -565,7 +591,10 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
}

OneStorage.delete(node, true);
provider.refresh(node.parent);
provider._onDidDeleteNode.fire(node);
}),
provider.onDidDeleteNode((node) => {
provider._onDidChangeTreeData.fire(node.parent);
}),
vscode.workspace.onDidChangeWorkspaceFolders(() => {
provider._workspaceRoots = obtainWorkspaceRoots().map((root) =>
Expand Down
3 changes: 3 additions & 0 deletions src/OneExplorer/OneStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ export class OneStorage {
* (3) the path is a lonely base model file
*/
public static getCfgs(baseModelPath: string): string[] | undefined {
OneStorage.get()._getCfgList().forEach(cfg=>{

})
return OneStorage.get()._baseModelToCfgsMap.get(baseModelPath);
}

Expand Down

0 comments on commit 02b8134

Please sign in to comment.