Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OneExplorer] Update label instantly #1465

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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
102 changes: 78 additions & 24 deletions src/OneExplorer/OneExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ export abstract class Node {
this._childNodes = undefined;
}

updateUri(uri: vscode.Uri): void {
this.uri = uri;
}

addChild(node: Node) {
if (this._childNodes) {
this._childNodes.push(node);
}
}

get path(): string {
return this.uri.fsPath;
}
Expand Down Expand Up @@ -474,8 +484,6 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
readonly onDidChangeTreeData: vscode.Event<Node | undefined | void> =
this._onDidChangeTreeData.event;

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

private _tree: Node[] | undefined;
private _treeView: vscode.TreeView<Node> | undefined;
private _workspaceRoots: vscode.Uri[] = [];
Expand All @@ -492,22 +500,6 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
});

let registrations = [
provider.fileWatcher.onDidCreate((_uri: vscode.Uri) => {
provider.refresh();
}),
provider.fileWatcher.onDidChange((_uri: vscode.Uri) => {
// TODO Handle by each node types
provider.refresh();
}),
provider.fileWatcher.onDidDelete((uri: vscode.Uri) => {
const node = OneStorage.getNode(uri.fsPath);
if (!node) {
return;
}

OneStorage.delete(node, true);
provider.refresh(node.parent);
}),
vscode.workspace.onDidChangeWorkspaceFolders(() => {
provider._workspaceRoots = obtainWorkspaceRoots().map((root) =>
vscode.Uri.file(root)
Expand Down Expand Up @@ -544,8 +536,19 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
vscode.commands.executeCommand("revealInExplorer", node.uri);
}
),
vscode.commands.registerCommand("one.explorer.refresh", () =>
provider.refresh()
vscode.commands.registerCommand("one.explorer.refresh", (node?: Node) =>
provider.refresh(node)
),
vscode.commands.registerCommand("one.explorer.rebuild", (cfg: string) =>{
const node = OneStorage.getNode(cfg);
if(!node || node.type !== NodeType.config){
return;
}

node.resetChildren();
node.getChildren();
provider.refresh(node);
}
),
vscode.commands.registerCommand("one.explorer.hideExtra", () =>
provider.hideExtra()
Expand Down Expand Up @@ -757,7 +760,14 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {

const edit = new vscode.WorkspaceEdit();
edit.renameFile(node.uri, vscode.Uri.file(newpath));
vscode.workspace.applyEdit(edit);
vscode.workspace.applyEdit(edit).then((onfulfilled) => {
if (onfulfilled) {
node.updateUri(vscode.Uri.file(newpath));
this.refresh(node);
} else {
Logger.error("OneExplorer", "Failed to rename a cfg file");
}
});
}
});
}
Expand Down Expand Up @@ -785,7 +795,17 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
if (children.length === 0) {
const edit = new vscode.WorkspaceEdit();
edit.renameFile(node.uri, vscode.Uri.file(newpath));
vscode.workspace.applyEdit(edit);
vscode.workspace.applyEdit(edit).then((onfulfilled) => {
if (onfulfilled) {
node.updateUri(vscode.Uri.file(newpath));
this.refresh(node);
} else {
Logger.error(
"OneExplorer",
`Failed to rename a file ${node.uri.fsPath}`
);
}
});
return;
}

Expand Down Expand Up @@ -828,7 +848,17 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
refactorCfgs().then(() => {
const edit = new vscode.WorkspaceEdit();
edit.renameFile(node.uri, vscode.Uri.file(newpath));
vscode.workspace.applyEdit(edit);
vscode.workspace.applyEdit(edit).then((onfulfilled) => {
if (onfulfilled) {
node.updateUri(vscode.Uri.file(newpath));
this.refresh(node);
} else {
Logger.error(
"OneExplorer",
`Failed to rename a file ${node.uri.fsPath}`
);
}
});
});
}

Expand Down Expand Up @@ -870,7 +900,19 @@ export class OneTreeDataProvider implements vscode.TreeDataProvider<Node> {
recursive: recursive,
ignoreIfNotExists: true,
});
vscode.workspace.applyEdit(edit);
vscode.workspace.applyEdit(edit).then((onfulfilled) => {
if (onfulfilled) {
OneStorage.delete(node, recursive);
this.refresh(node.parent, false);

// TODO Remove parent directory nodes if it is empty, recursively if needed
} else {
Logger.error(
"OneExplorer",
`Failed to delete a file ${node.uri.fsPath}`
);
}
});
}
});
}
Expand Down Expand Up @@ -930,6 +972,18 @@ input_path=${modelName}.${extName}

vscode.workspace.applyEdit(edit).then((isSuccess) => {
if (isSuccess) {
const cfgNode = NodeFactory.create(
NodeType.config,
uri.fsPath,
node
);
cfgNode.getChildren();

OneStorage.insert(cfgNode);
node.addChild(cfgNode);
this.refresh(node);
this.reveal(cfgNode);

vscode.workspace.openTextDocument(uri).then((document) => {
document.save();
vscode.commands.executeCommand(
Expand Down
11 changes: 9 additions & 2 deletions src/Toolchain/ToolchainEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { strict as assert } from "assert";
import * as path from "path";

import * as vscode from 'vscode';
import { Compiler } from "../Backend/Compiler";
import { Toolchain } from "../Backend/Toolchain";
import { BuilderJob } from "../Job/BuilderJob";
Expand Down Expand Up @@ -182,8 +183,14 @@ class ToolchainEnv extends Env {
const jobs: Array<Job> = [];
const job = new JobConfig(toolchain.run(cfg));
job.workDir = path.dirname(cfg);
job.successCallback = () => resolve(true);
job.failureCallback = () => reject();
job.successCallback = () => {
vscode.commands.executeCommand("one.explorer.rebuild", cfg);
resolve(true);
};
job.failureCallback = () => {
vscode.commands.executeCommand("one.explorer.rebuild", cfg);
reject();
};
jobs.push(job);
this.executeEnv(jobs);
});
Expand Down