|
2 | 2 | // Licensed under the MIT license.
|
3 | 3 |
|
4 | 4 | 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, |
7 | 7 | } from "vscode";
|
8 | 8 | import { Commands } from "../commands";
|
9 |
| -import { NodeKind } from "../java/nodeData"; |
| 9 | +import { Jdtls } from "../java/jdtls"; |
| 10 | +import { INodeData, NodeKind } from "../java/nodeData"; |
10 | 11 | import { Telemetry } from "../telemetry";
|
11 | 12 | import { ExplorerNode } from "./explorerNode";
|
| 13 | +import { ProjectNode } from "./projectNode"; |
12 | 14 | import { WorkspaceNode } from "./workspaceNode";
|
13 | 15 |
|
14 | 16 | export class ProjectExplorer implements TreeDataProvider<ExplorerNode> {
|
@@ -53,24 +55,36 @@ export class ProjectExplorer implements TreeDataProvider<ExplorerNode> {
|
53 | 55 |
|
54 | 56 | public getChildren(element?: ExplorerNode): ProviderResult<ExplorerNode[]> {
|
55 | 57 | if (!this._rootItems || !element) {
|
56 |
| - this._rootItems = this.getRootNodes(); |
57 |
| - return this._rootItems; |
| 58 | + return this.getRootNodes(); |
58 | 59 | } else {
|
59 | 60 | return element.getChildren();
|
60 | 61 | }
|
61 | 62 | }
|
62 | 63 |
|
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 | + }); |
75 | 89 | }
|
76 | 90 | }
|
0 commit comments