Skip to content

Commit 86bb545

Browse files
committed
Explorer view, should be faster now
1 parent 25f0ec7 commit 86bb545

File tree

3 files changed

+71
-132
lines changed

3 files changed

+71
-132
lines changed

src/explorer/models/packageNode.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import * as vscode from "vscode";
2-
import { ClassNode } from "./classesNode";
3-
import { NodeBase } from "./nodeBase";
2+
import { RootNode } from "./rootNode";
43

5-
export class PackageNode extends NodeBase {
6-
public static readonly contextValue: string = "dataNode:packageNode";
7-
private readonly _items;
8-
public constructor(label: string, items, workspaceFolder: string, namespace: string) {
9-
super(label, label, workspaceFolder, namespace);
10-
this._items = items;
4+
export class PackageNode extends RootNode {
5+
public constructor(label: string, fullName: string, category: string, workspaceFolder: string, namespace: string) {
6+
super(label, fullName, "dataNode:packageNode", category, workspaceFolder, namespace);
117
}
128

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

1612
return {
1713
collapsibleState: vscode.TreeItemCollapsibleState.Collapsed,
18-
contextValue: "dataNode:packageNode",
14+
contextValue: this.contextValue,
1915
label: `${displayName}`,
2016
// iconPath: {
2117
// light: path.join(__filename, '..', '..', '..', '..', 'images', 'light', 'package.svg'),
@@ -24,17 +20,7 @@ export class PackageNode extends NodeBase {
2420
};
2521
}
2622

27-
public async getChildren(element): Promise<NodeBase[]> {
28-
return this._items.map(({ name, fullName, nodes }) =>
29-
nodes.length
30-
? new PackageNode(name, nodes, this.workspaceFolder, this.namespace)
31-
: new ClassNode(name, fullName, this.workspaceFolder, this.namespace)
32-
);
33-
}
34-
3523
public getClasses(): string[] {
36-
const getNodes = (list, el) => list.concat(el.nodes.length ? el.nodes.reduce(getNodes, []) : el);
37-
const nodes = this._items.reduce(getNodes, []);
38-
return nodes.map(el => el.fullName);
24+
return [];
3925
}
4026
}

src/explorer/models/rootNode.ts

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@ import * as vscode from "vscode";
33
import { NodeBase } from "./nodeBase";
44
import { PackageNode } from "./packageNode";
55
import { RoutineNode } from "./routineNode";
6+
import { AtelierAPI } from "../../api";
7+
import { ClassNode } from "./classesNode";
68

79
export class RootNode extends NodeBase {
810
public readonly contextValue: string;
9-
public eventEmitter: vscode.EventEmitter<NodeBase>;
10-
private _items: any[];
11+
private readonly _category: string;
1112

1213
public constructor(
1314
label: string,
15+
fullName: string,
1416
contextValue: string,
15-
eventEmitter: vscode.EventEmitter<NodeBase>,
16-
items: any[],
17+
category: string,
1718
workspaceFolder: string,
1819
namespace: string
1920
) {
20-
super(label, label, workspaceFolder, namespace);
21+
super(label, fullName, workspaceFolder, namespace);
2122
this.contextValue = contextValue;
22-
this.eventEmitter = eventEmitter;
23-
this._items = items;
23+
this._category = category;
2424
}
2525

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

3434
public async getChildren(element): Promise<NodeBase[]> {
35-
if (element.contextValue === "dataRootNode:classesRootNode") {
36-
return this.getClasses();
37-
}
38-
39-
if (element.contextValue === "dataRootNode:routinesRootNode") {
40-
return this.getRoutines();
41-
}
42-
}
43-
44-
private async getClasses(): Promise<PackageNode[]> {
45-
const items = this.makeTree(this._items);
46-
47-
return items.map(
48-
({ name, nodes }): PackageNode => new PackageNode(name, nodes, this.workspaceFolder, this.namespace)
49-
);
35+
const path = this instanceof PackageNode ? this.fullName + "/" : "";
36+
return this.getItems(path, this._category);
5037
}
38+
public getItems(path: string, category: string): Promise<NodeBase[]> {
39+
const sql = "CALL %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?)";
40+
// const sql = "CALL %Library.RoutineMgr_StudioOpenDialog(?,,,,,,?)";
41+
let spec = "";
42+
switch (category) {
43+
case "CLS":
44+
spec = "*.cls";
45+
break;
46+
case "RTN":
47+
spec = "*.mac,*.int";
48+
break;
49+
case "INC":
50+
spec = "*.inc";
51+
break;
52+
default:
53+
return;
54+
}
55+
const direction = "1";
56+
const orderBy = "1"; // by Name
57+
const flat = "0";
58+
const notStudio = "0";
59+
const generated = "0";
5160

52-
private async getRoutines(): Promise<RoutineNode[]> {
53-
return this._items.map(
54-
({ name }): RoutineNode => new RoutineNode(name, name, this.workspaceFolder, this.namespace)
55-
);
56-
}
61+
spec = path + spec;
5762

58-
private makeTree(items: any[]): any[] {
59-
let tree;
60-
tree = items.map(({ name }) => ({ name }));
61-
tree.forEach(el => {
62-
const parent = el.name.split(".").slice(0, -2);
63-
el.parent = parent.join(".");
64-
el.fullName = el.name;
65-
el.name = el.name
66-
.split(".")
67-
.slice(-2)
68-
.join(".");
69-
const parents = parent.map((name, i) => {
70-
return {
71-
name,
72-
fullName: parent.slice(0, i + 1).join("."),
73-
parent: parent.slice(0, i).join("."),
74-
};
75-
});
76-
tree = tree.concat(parents);
77-
});
78-
tree = tree.filter((value, index, self) => self.findIndex(({ fullName }) => fullName === value.fullName) === index);
79-
tree = tree.sort((el1, el2) => el1.fullName.localeCompare(el2.fullName));
80-
tree.forEach(el => {
81-
el.nodes = tree.filter(ch => el.fullName === ch.parent);
82-
});
83-
tree = tree.filter(el => el.parent === "");
63+
const systemFiles = this.namespace === "%SYS" ? "1" : "0";
8464

85-
return tree;
65+
const api = new AtelierAPI(this.workspaceFolder);
66+
api.setNamespace(this.namespace);
67+
return api
68+
.actionQuery(sql, [spec, direction, orderBy, systemFiles, flat, notStudio, generated])
69+
.then(data => {
70+
const content = data.result.content;
71+
return content;
72+
})
73+
.then(data =>
74+
data
75+
.map(el => {
76+
const fullName = (this instanceof PackageNode ? this.fullName + "." : "") + el.Name;
77+
switch (el.Type) {
78+
case "9":
79+
return new PackageNode(el.Name, fullName, category, this.workspaceFolder, this.namespace);
80+
case "4":
81+
return new ClassNode(el.Name, fullName, this.workspaceFolder, this.namespace);
82+
case "0":
83+
case "1":
84+
case "2":
85+
return new RoutineNode(el.Name, fullName, this.workspaceFolder, this.namespace);
86+
default:
87+
return null;
88+
}
89+
})
90+
.filter(el => el !== null)
91+
);
8692
}
8793
}

src/explorer/models/workspaceNode.ts

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from "vscode";
22

3-
import { AtelierAPI } from "../../api";
43
import { NodeBase } from "./nodeBase";
54
import { RootNode } from "./rootNode";
65

@@ -11,10 +10,6 @@ export class WorkspaceNode extends NodeBase {
1110
this.eventEmitter = eventEmitter;
1211
}
1312

14-
// get ns(): string {
15-
// return this._namespace;
16-
// }
17-
1813
public getTreeItem(): vscode.TreeItem {
1914
return {
2015
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
@@ -26,64 +21,16 @@ export class WorkspaceNode extends NodeBase {
2621
public async getChildren(element): Promise<NodeBase[]> {
2722
const children = [];
2823
let node: RootNode;
29-
let data: any;
3024

31-
data = await this.getDocNames("CLS");
32-
node = new RootNode(
33-
"Classes",
34-
"dataRootNode:classesRootNode",
35-
this.eventEmitter,
36-
data,
37-
this.workspaceFolder,
38-
this.namespace
39-
);
25+
node = new RootNode("Classes", "", "dataRootNode:classesRootNode", "CLS", this.workspaceFolder, this.namespace);
4026
children.push(node);
4127

42-
data = await this.getDocNames("RTN");
43-
node = new RootNode(
44-
"Routines",
45-
"dataRootNode:routinesRootNode",
46-
this.eventEmitter,
47-
data,
48-
this.workspaceFolder,
49-
this.namespace
50-
);
28+
node = new RootNode("Routines", "", "dataRootNode:routinesRootNode", "RTN", this.workspaceFolder, this.namespace);
5129
children.push(node);
5230

53-
return children;
54-
}
55-
56-
public getDocNames(category: string): Promise<any> {
57-
const sql = `SELECT Name name
58-
FROM %Library.RoutineMgr_StudioOpenDialog(?,?,?,?,?,?,?,?)
59-
`;
60-
let spec;
61-
const notStudio = 0;
62-
switch (category) {
63-
case "CLS":
64-
spec = "*.cls";
65-
break;
66-
case "RTN":
67-
spec = "*.mac,*.int,*.inc";
68-
break;
69-
default:
70-
return;
71-
}
72-
const direction = 1;
73-
const orderBy = 1; // by Name
74-
const flat = 1;
75-
const generated = 0;
76-
const filter = "";
77-
78-
const systemFiles = this.namespace === "%SYS" ? "1" : "0";
31+
node = new RootNode("Includes", "", "dataRootNode:routinesRootNode", "INC", this.workspaceFolder, this.namespace);
32+
children.push(node);
7933

80-
const api = new AtelierAPI(this.label);
81-
api.setNamespace(this.namespace);
82-
return api
83-
.actionQuery(sql, [spec, direction, orderBy, systemFiles, flat, notStudio, generated, filter])
84-
.then(data => {
85-
const content = data.result.content;
86-
return content;
87-
});
34+
return children;
8835
}
8936
}

0 commit comments

Comments
 (0)