Skip to content

Commit c4eb8d7

Browse files
Vigilanstestforstephen
authored andcommitted
Replace workspace.rootPath with workspaceFolder (#184)
1 parent d6fc145 commit c4eb8d7

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/controllers/projectController.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ export class ProjectController {
1616
if (!javaVersion) {
1717
return;
1818
}
19+
const workspaceFolder = Utility.getDefaultWorkspaceFolder();
1920
const location: Uri[] = await window.showOpenDialog({
20-
defaultUri: workspace.rootPath ? Uri.file(workspace.rootPath) : undefined,
21+
defaultUri: workspaceFolder && workspaceFolder.uri,
2122
canSelectFiles: false,
2223
canSelectFolders: true,
2324
openLabel: "Select the location",

src/utility.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as child_process from "child_process";
22
import * as findJavaHome from "find-java-home";
33
import * as fse from "fs-extra";
44
import * as path from "path";
5-
import { Uri, workspace } from "vscode";
5+
import { Uri, window, workspace, WorkspaceFolder } from "vscode";
66
import * as xml2js from "xml2js";
77

88
export class Utility {
@@ -72,6 +72,21 @@ export class Utility {
7272
});
7373
}
7474

75+
public static getDefaultWorkspaceFolder(): WorkspaceFolder | undefined {
76+
const workspaceFolders: WorkspaceFolder[] | undefined = workspace.workspaceFolders;
77+
if (workspaceFolders === undefined) {
78+
return undefined;
79+
}
80+
if (workspaceFolders.length === 1) {
81+
return workspaceFolders[0];
82+
}
83+
if (window.activeTextEditor) {
84+
const activeWorkspaceFolder: WorkspaceFolder | undefined = workspace.getWorkspaceFolder(window.activeTextEditor.document.uri);
85+
return activeWorkspaceFolder;
86+
}
87+
return undefined;
88+
}
89+
7590
private static openJDKDownload(reject, cause) {
7691
let jdkUrl = "http://developers.redhat.com/products/openjdk/overview/?from=vscode";
7792
if (process.platform === "darwin") {

0 commit comments

Comments
 (0)