Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"debugger"
],
"engines": {
"vscode": "^1.32.0"
"vscode": "^1.38.0"
},
"license": "SEE LICENSE IN LICENSE.txt",
"repository": {
Expand Down Expand Up @@ -529,7 +529,7 @@
"@types/lodash": "^4.14.137",
"@types/mocha": "^5.2.7",
"@types/node": "^8.10.51",
"@types/vscode": "1.32.0",
"@types/vscode": "1.38.0",
"cross-env": "^5.2.0",
"gulp": "^4.0.2",
"gulp-tslint": "^8.1.4",
Expand Down
23 changes: 7 additions & 16 deletions src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,8 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
await updateDebugSettings();
}

/**
* If no launch.json exists in the current workspace folder
* delegate to provideDebugConfigurations api to generate the initial launch.json configurations
*/
if (this.isEmptyConfig(config) && folder) {
// Follow the feature request https://github.com/Microsoft/vscode/issues/54213#issuecomment-420965778,
// in order to generate launch.json, the resolveDebugConfiguration api must return null explicitly.
return null;
}

// If it's the single file case that no workspace folder is opened, generate debug config in memory
if (this.isEmptyConfig(config) && !folder) {
// If no debug configuration is provided, then generate one in memory.
if (this.isEmptyConfig(config)) {
config.type = "java";
config.name = "Java Debug";
config.request = "launch";
Expand Down Expand Up @@ -293,13 +283,13 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
return mainEntries[0];
} else if (mainEntries.length > 1) {
return this.showMainClassQuickPick(this.formatMainClassOptions(mainEntries),
`Multiple main classes found in the file '${path.basename(currentFile)}', please select one first.`);
`Please select a main class you want to run.`);
}
}

const hintMessage = currentFile ?
`No main class found in the file '${path.basename(currentFile)}', please select main class<project name> again.` :
"Please select main class<project name>.";
`The file '${path.basename(currentFile)}' is not executable, please select a main class you want to run.` :
"Please select a main class you want to run.";
return this.promptMainClass(folder, hintMessage);
}

Expand Down Expand Up @@ -389,8 +379,9 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
private async promptMainClass(folder: vscode.Uri | undefined, hintMessage?: string): Promise<lsPlugin.IMainClassOption | undefined> {
const res = await lsPlugin.resolveMainClass(folder);
if (res.length === 0) {
const workspaceFolder = folder ? vscode.workspace.getWorkspaceFolder(folder) : undefined;
throw new utility.UserError({
message: "Cannot find a class with the main method.",
message: `Cannot find a class with the main method${ workspaceFolder ? " in the folder '" + workspaceFolder.name + "'" : ""}.`,
type: Type.USAGEERROR,
anchor: anchor.CANNOT_FIND_MAIN_CLASS,
});
Expand Down
14 changes: 12 additions & 2 deletions src/debugCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ async function constructDebugConfig(mainClass: string, projectName: string, work
projectName,
};

// Persist the default debug configuration only if the workspace exists.
if (workspace) {
// Persist the configuration into launch.json only if the launch.json file already exists in the workspace.
if ((rawConfigs && rawConfigs.length) || await launchJsonExists(workspace)) {
try {
// Insert the default debug configuration to the beginning of launch.json.
rawConfigs.splice(0, 0, debugConfig);
Expand All @@ -166,6 +166,16 @@ async function constructDebugConfig(mainClass: string, projectName: string, work
return _.cloneDeep(debugConfig);
}

async function launchJsonExists(workspace: vscode.Uri): Promise<boolean> {
if (!workspace) {
return false;
}

const workspaceFolder = vscode.workspace.getWorkspaceFolder(workspace);
const results: vscode.Uri[] = await vscode.workspace.findFiles(".vscode/launch.json");
return !!results.find((launchJson) => vscode.workspace.getWorkspaceFolder(launchJson) === workspaceFolder);
}

export async function startDebugging(mainClass: string, projectName: string, uri: vscode.Uri, noDebug: boolean): Promise<boolean> {
const workspaceFolder: vscode.WorkspaceFolder = vscode.workspace.getWorkspaceFolder(uri);
const workspaceUri: vscode.Uri = workspaceFolder ? workspaceFolder.uri : undefined;
Expand Down