Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
return vscode.window.withProgress({location: vscode.ProgressLocation.Window}, (p) => {
return new Promise((resolve, reject) => {
p.report({message: "Auto generating configuration..."});
resolveMainClass(folder.uri).then((res: any[]) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which case the folder in empty? Single file?

Does the java-debug also should be changed for this changes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if client only opens a file, the folder is undefined. java-debug has handled this.

resolveMainClass(folder ? folder.uri : undefined).then((res: any[]) => {
let cache;
cache = {};
const launchConfigs = res.map((item) => {
Expand Down Expand Up @@ -86,20 +86,22 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
await updateDebugSettings();
}

try {
const buildResult = await vscode.commands.executeCommand(commands.JAVA_BUILD_WORKSPACE);
console.log(buildResult);
} catch (err) {
vscode.window.showErrorMessage("Build failed, please fix build error first.");
return config;
}

if (Object.keys(config).length === 0) { // No launch.json in current workspace.
// check whether it is opened as a folder
if (folder !== undefined) {
// for opened with folder, return directly.
return config;
}
// only rebuild for single file case before the build error issue is resolved.
try {
const buildResult = await vscode.commands.executeCommand(commands.JAVA_BUILD_WORKSPACE, false);
console.log(buildResult);
} catch (err) {
const ans = await vscode.window.showErrorMessage("Build failed, do you want to continue?", "Proceed", "Abort");
if (ans !== "Proceed") {
return undefined;
}
}
// Generate config in memory for single file
config.type = "java";
config.name = "Java Debug";
Expand All @@ -111,7 +113,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration

if (config.request === "launch") {
if (!config.mainClass) {
const res = <any[]>(await resolveMainClass(folder.uri));
const res = <any[]>(await resolveMainClass(folder ? folder.uri : undefined));
if (res.length === 0) {
vscode.window.showErrorMessage(
"Cannot resolve main class automatically, please specify the mainClass " +
Expand Down Expand Up @@ -223,7 +225,10 @@ function resolveClasspath(mainClass, projectName) {
}

function resolveMainClass(workspaceUri: vscode.Uri) {
return commands.executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_MAINCLASS, workspaceUri.toString());
if (workspaceUri) {
return commands.executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_MAINCLASS, workspaceUri.toString());
}
return commands.executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_MAINCLASS);
}

async function updateDebugSettings() {
Expand Down