Skip to content

Commit e8cfa95

Browse files
authored
Optimize the display of single workspace. (#39)
1 parent 3d7eebb commit e8cfa95

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

src/views/projectExplorer.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
// Licensed under the MIT license.
33

44
import {
5-
commands, Event, EventEmitter, ExtensionContext, ProviderResult, Range, Selection,
6-
TextEditorRevealType, TreeDataProvider, TreeItem, Uri, window, workspace,
5+
commands, Event, EventEmitter, ExtensionContext, ProviderResult, Range,
6+
Selection, TextEditorRevealType, TreeDataProvider, TreeItem, Uri, window, workspace,
77
} from "vscode";
88
import { Commands } from "../commands";
9-
import { NodeKind } from "../java/nodeData";
9+
import { Jdtls } from "../java/jdtls";
10+
import { INodeData, NodeKind } from "../java/nodeData";
1011
import { Telemetry } from "../telemetry";
1112
import { ExplorerNode } from "./explorerNode";
13+
import { ProjectNode } from "./projectNode";
1214
import { WorkspaceNode } from "./workspaceNode";
1315

1416
export class ProjectExplorer implements TreeDataProvider<ExplorerNode> {
@@ -53,24 +55,36 @@ export class ProjectExplorer implements TreeDataProvider<ExplorerNode> {
5355

5456
public getChildren(element?: ExplorerNode): ProviderResult<ExplorerNode[]> {
5557
if (!this._rootItems || !element) {
56-
this._rootItems = this.getRootNodes();
57-
return this._rootItems;
58+
return this.getRootNodes();
5859
} else {
5960
return element.getChildren();
6061
}
6162
}
6263

63-
private getRootNodes() {
64-
const result: ExplorerNode[] = new Array<ExplorerNode>();
65-
const folders = workspace.workspaceFolders;
66-
Telemetry.sendEvent("create workspace node(s)");
67-
if (folders && folders.length) {
68-
folders.forEach((folder) => result.push(new WorkspaceNode({
69-
name: folder.name,
70-
uri: folder.uri.toString(),
71-
kind: NodeKind.Workspace,
72-
})));
73-
}
74-
return result;
64+
private getRootNodes(): Thenable<ExplorerNode[]> {
65+
return new Promise((resolve, reject) => {
66+
this._rootItems = new Array<ExplorerNode>();
67+
const folders = workspace.workspaceFolders;
68+
Telemetry.sendEvent("create workspace node(s)");
69+
if (folders && folders.length) {
70+
if (folders.length > 1) {
71+
folders.forEach((folder) => this._rootItems.push(new WorkspaceNode({
72+
name: folder.name,
73+
uri: folder.uri.toString(),
74+
kind: NodeKind.Workspace,
75+
})));
76+
resolve(this._rootItems);
77+
} else {
78+
Jdtls.getProjects(folders[0].uri.toString()).then((result: INodeData[]) => {
79+
result.forEach((project) => {
80+
this._rootItems.push(new ProjectNode(project));
81+
});
82+
resolve(this._rootItems);
83+
});
84+
}
85+
} else {
86+
reject("No workspace found");
87+
}
88+
});
7589
}
7690
}

0 commit comments

Comments
 (0)