Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 41 additions & 18 deletions src/OneExplorer/OneExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ class NodeFactory {

OneStorage.insert(node);

OneStorage.insert(node);

return node;
}
}
Expand Down Expand Up @@ -237,7 +239,7 @@ class DirectoryNode extends Node {
} else if (
fstat.isFile() &&
(fname.endsWith('.pb') || fname.endsWith('.tflite') || fname.endsWith('.onnx'))) {
const baseModelNode = NodeFactory.create(NodeType.baseModel, fpath, this);
const baseModelNode = OneStorage.getNode(fpath) ?? NodeFactory.create(NodeType.baseModel, fpath, this);

if (baseModelNode) {
this._childNodes!.push(baseModelNode);
Expand Down Expand Up @@ -292,7 +294,7 @@ class BaseModelNode extends Node {
return;
}
configPaths.forEach(configPath => {
const configNode = NodeFactory.create(NodeType.config, configPath, this);
const configNode = OneStorage.getNode(configPath) ?? NodeFactory.create(NodeType.config, configPath, this);

if (configNode) {
this._childNodes!.push(configNode);
Expand Down Expand Up @@ -349,7 +351,7 @@ class ConfigNode extends Node {
const products = cfgObj.getProductsExists;

products.forEach(product => {
const productNode = NodeFactory.create(NodeType.product, product.path, this, product.attr);
const productNode = OneStorage.getNode(product.path) ?? NodeFactory.create(NodeType.product, product.path, this, product.attr);

if (productNode) {
this._childNodes!.push(productNode);
Expand Down Expand Up @@ -445,21 +447,27 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
{treeDataProvider: provider, showCollapseAll: true, canSelectMany: true});

let registrations = [
provider.fileWatcher.onDidCreate((_uri: vscode.Uri) => {
provider.refresh();
}),
provider.fileWatcher.onDidChange((_uri: vscode.Uri) => {
// TODO Handle by each node types
provider.refresh();
vscode.workspace.onDidRenameFiles(e => {
e.files.forEach(file => {
console.log(`onDidRenameFile: ${file.oldUri}=>${file.newUri}`);
const node = OneStorage.getNode(file.oldUri.fsPath);
if (!node) {
return;
}
node.uri = file.newUri;
});
}),
provider.fileWatcher.onDidDelete((uri: vscode.Uri) => {
const node = OneStorage.getNode(uri.fsPath);
if (!node) {
return;
}
vscode.workspace.onDidDeleteFiles(e => {
e.files.forEach(file => {
console.log(`onDidDeleteFiles: ${file.fsPath}`);
const node = OneStorage.getNode(file.fsPath);
if (!node) {
return;
}

OneStorage.delete(node, true);
provider.refresh(node.parent);
OneStorage.delete(node, true);
provider.refresh(node.parent);
});
}),
vscode.workspace.onDidChangeWorkspaceFolders(() => {
provider._workspaceRoots = obtainWorkspaceRoots().map(root => vscode.Uri.file(root));
Expand Down Expand Up @@ -819,8 +827,23 @@ input_path=${modelName}.${extName}
vscode.workspace.applyEdit(edit).then(isSuccess => {
if (isSuccess) {
vscode.workspace.openTextDocument(uri).then(document => {
document.save();
vscode.commands.executeCommand('vscode.openWith', uri, CfgEditorPanel.viewType);
document.save().then((isOk)=>{
if(!isOk){
return;
}
//New CFG File
OneStorage.addConfig(uri.fsPath);
const cfgObj = OneStorage.getCfgObj(uri.fsPath);
if (cfgObj) {
cfgObj.getBaseModels.forEach(model => {
const basemodelNode = OneStorage.getNode(model.path);
if (basemodelNode) {
basemodelNode.resetChildren();
this.refresh(node);
}
});
}
}).then(()=>vscode.commands.executeCommand('vscode.openWith', uri, CfgEditorPanel.viewType));
});
} else {
Logger.error('OneExplorer', 'CreateCfg', `Failed to create the file ${uri}`);
Expand Down
39 changes: 39 additions & 0 deletions src/OneExplorer/OneStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@ export class OneStorage {
}
}

private static _replace(node: Node, newPath: string) {
OneStorage.get()._nodeMap.delete(node.path);
OneStorage.get()._nodeMap.set(newPath, node);

switch (node.type) {
case NodeType.baseModel:
OneStorage.resetBaseModel(node.path);
break;
case NodeType.config:
OneStorage.resetConfig(node.path);
break;
default:
break;
}
}

private constructor() {
const cfgList = this._initCfgList();
this._cfgToCfgObjMap = this._initCfgToCfgObjMap(cfgList);
Expand Down Expand Up @@ -224,11 +240,34 @@ export class OneStorage {
OneStorage._obj = undefined;
}

public static addBaseModel(path: string): void {
// TODO

Logger.debug('OneStorage', `Config Path(${path}) is removed.`);
}

public static resetBaseModel(path: string): void {
delete OneStorage.get()._baseModelToCfgsMap[path];
Logger.debug('OneStorage', `Base Mode Path(${path}) is removed.`);
}

public static addConfig(path: string): void {
const cfgobj = ConfigObj.createConfigObj(vscode.Uri.file(path));
OneStorage.get()._cfgToCfgObjMap[path] = cfgobj;

if(!cfgobj){
return;
}

cfgobj?.getBaseModelsExists.map(v=>
v.path
).forEach(model=>{
OneStorage.get()._baseModelToCfgsMap[model].push(path);
});

Logger.debug('OneStorage', `Config Path(${path}) is added.`);
}

public static resetConfig(path: string): void {
delete OneStorage.get()._cfgToCfgObjMap[path];
Object.entries(OneStorage.get()._baseModelToCfgsMap).forEach(([modelpath]) => {
Expand Down