Skip to content

Commit

Permalink
Explorer view, should be faster now
Browse files Browse the repository at this point in the history
  • Loading branch information
daimor committed Oct 7, 2019
1 parent 25f0ec7 commit 86bb545
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 132 deletions.
26 changes: 6 additions & 20 deletions src/explorer/models/packageNode.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import * as vscode from "vscode";
import { ClassNode } from "./classesNode";
import { NodeBase } from "./nodeBase";
import { RootNode } from "./rootNode";

export class PackageNode extends NodeBase {
public static readonly contextValue: string = "dataNode:packageNode";
private readonly _items;
public constructor(label: string, items, workspaceFolder: string, namespace: string) {
super(label, label, workspaceFolder, namespace);
this._items = items;
export class PackageNode extends RootNode {
public constructor(label: string, fullName: string, category: string, workspaceFolder: string, namespace: string) {
super(label, fullName, "dataNode:packageNode", category, workspaceFolder, namespace);
}

public getTreeItem(): vscode.TreeItem {
const displayName: string = this.label;

return {
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
contextValue: "dataNode:packageNode",
contextValue: this.contextValue,
label: `${displayName}`,
// iconPath: {
// light: path.join(__filename, '..', '..', '..', '..', 'images', 'light', 'package.svg'),
Expand All @@ -24,17 +20,7 @@ export class PackageNode extends NodeBase {
};
}

public async getChildren(element): Promise<NodeBase[]> {
return this._items.map(({ name, fullName, nodes }) =>
nodes.length
? new PackageNode(name, nodes, this.workspaceFolder, this.namespace)
: new ClassNode(name, fullName, this.workspaceFolder, this.namespace)
);
}

public getClasses(): string[] {
const getNodes = (list, el) => list.concat(el.nodes.length ? el.nodes.reduce(getNodes, []) : el);
const nodes = this._items.reduce(getNodes, []);
return nodes.map(el => el.fullName);
return [];
}
}
114 changes: 60 additions & 54 deletions src/explorer/models/rootNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ import * as vscode from "vscode";
import { NodeBase } from "./nodeBase";
import { PackageNode } from "./packageNode";
import { RoutineNode } from "./routineNode";
import { AtelierAPI } from "../../api";
import { ClassNode } from "./classesNode";

export class RootNode extends NodeBase {
public readonly contextValue: string;
public eventEmitter: vscode.EventEmitter<NodeBase>;
private _items: any[];
private readonly _category: string;

public constructor(
label: string,
fullName: string,
contextValue: string,
eventEmitter: vscode.EventEmitter<NodeBase>,
items: any[],
category: string,
workspaceFolder: string,
namespace: string
) {
super(label, label, workspaceFolder, namespace);
super(label, fullName, workspaceFolder, namespace);
this.contextValue = contextValue;
this.eventEmitter = eventEmitter;
this._items = items;
this._category = category;
}

public getTreeItem(): vscode.TreeItem {
Expand All @@ -32,56 +32,62 @@ export class RootNode extends NodeBase {
}

public async getChildren(element): Promise<NodeBase[]> {
if (element.contextValue === "dataRootNode:classesRootNode") {
return this.getClasses();
}

if (element.contextValue === "dataRootNode:routinesRootNode") {
return this.getRoutines();
}
}

private async getClasses(): Promise<PackageNode[]> {
const items = this.makeTree(this._items);

return items.map(
({ name, nodes }): PackageNode => new PackageNode(name, nodes, this.workspaceFolder, this.namespace)
);
const path = this instanceof PackageNode ? this.fullName + "/" : "";
return this.getItems(path, this._category);
}
public getItems(path: string, category: string): Promise<NodeBase[]> {
const sql = "CALL %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)";
// const sql = "CALL %Library.RoutineMgr_StudioOpenDialog(?,,,,,,?)";
let spec = "";
switch (category) {
case "CLS":
spec = "*.cls";
break;
case "RTN":
spec = "*.mac,*.int";
break;
case "INC":
spec = "*.inc";
break;
default:
return;
}
const direction = "1";
const orderBy = "1"; // by Name
const flat = "0";
const notStudio = "0";
const generated = "0";

private async getRoutines(): Promise<RoutineNode[]> {
return this._items.map(
({ name }): RoutineNode => new RoutineNode(name, name, this.workspaceFolder, this.namespace)
);
}
spec = path + spec;

private makeTree(items: any[]): any[] {
let tree;
tree = items.map(({ name }) => ({ name }));
tree.forEach(el => {
const parent = el.name.split(".").slice(0, -2);
el.parent = parent.join(".");
el.fullName = el.name;
el.name = el.name
.split(".")
.slice(-2)
.join(".");
const parents = parent.map((name, i) => {
return {
name,
fullName: parent.slice(0, i + 1).join("."),
parent: parent.slice(0, i).join("."),
};
});
tree = tree.concat(parents);
});
tree = tree.filter((value, index, self) => self.findIndex(({ fullName }) => fullName === value.fullName) === index);
tree = tree.sort((el1, el2) => el1.fullName.localeCompare(el2.fullName));
tree.forEach(el => {
el.nodes = tree.filter(ch => el.fullName === ch.parent);
});
tree = tree.filter(el => el.parent === "");
const systemFiles = this.namespace === "%SYS" ? "1" : "0";

return tree;
const api = new AtelierAPI(this.workspaceFolder);
api.setNamespace(this.namespace);
return api
.actionQuery(sql, [spec, direction, orderBy, systemFiles, flat, notStudio, generated])
.then(data => {
const content = data.result.content;
return content;
})
.then(data =>
data
.map(el => {
const fullName = (this instanceof PackageNode ? this.fullName + "." : "") + el.Name;
switch (el.Type) {
case "9":
return new PackageNode(el.Name, fullName, category, this.workspaceFolder, this.namespace);
case "4":
return new ClassNode(el.Name, fullName, this.workspaceFolder, this.namespace);
case "0":
case "1":
case "2":
return new RoutineNode(el.Name, fullName, this.workspaceFolder, this.namespace);
default:
return null;
}
})
.filter(el => el !== null)
);
}
}
63 changes: 5 additions & 58 deletions src/explorer/models/workspaceNode.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as vscode from "vscode";

import { AtelierAPI } from "../../api";
import { NodeBase } from "./nodeBase";
import { RootNode } from "./rootNode";

Expand All @@ -11,10 +10,6 @@ export class WorkspaceNode extends NodeBase {
this.eventEmitter = eventEmitter;
}

// get ns(): string {
// return this._namespace;
// }

public getTreeItem(): vscode.TreeItem {
return {
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
Expand All @@ -26,64 +21,16 @@ export class WorkspaceNode extends NodeBase {
public async getChildren(element): Promise<NodeBase[]> {
const children = [];
let node: RootNode;
let data: any;

data = await this.getDocNames("CLS");
node = new RootNode(
"Classes",
"dataRootNode:classesRootNode",
this.eventEmitter,
data,
this.workspaceFolder,
this.namespace
);
node = new RootNode("Classes", "", "dataRootNode:classesRootNode", "CLS", this.workspaceFolder, this.namespace);
children.push(node);

data = await this.getDocNames("RTN");
node = new RootNode(
"Routines",
"dataRootNode:routinesRootNode",
this.eventEmitter,
data,
this.workspaceFolder,
this.namespace
);
node = new RootNode("Routines", "", "dataRootNode:routinesRootNode", "RTN", this.workspaceFolder, this.namespace);
children.push(node);

return children;
}

public getDocNames(category: string): Promise<any> {
const sql = `SELECT Name name
FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?,?)
`;
let spec;
const notStudio = 0;
switch (category) {
case "CLS":
spec = "*.cls";
break;
case "RTN":
spec = "*.mac,*.int,*.inc";
break;
default:
return;
}
const direction = 1;
const orderBy = 1; // by Name
const flat = 1;
const generated = 0;
const filter = "";

const systemFiles = this.namespace === "%SYS" ? "1" : "0";
node = new RootNode("Includes", "", "dataRootNode:routinesRootNode", "INC", this.workspaceFolder, this.namespace);
children.push(node);

const api = new AtelierAPI(this.label);
api.setNamespace(this.namespace);
return api
.actionQuery(sql, [spec, direction, orderBy, systemFiles, flat, notStudio, generated, filter])
.then(data => {
const content = data.result.content;
return content;
});
return children;
}
}

0 comments on commit 86bb545

Please sign in to comment.