in src/extension.ts [340:401]
async function runJavaProject(node: any, noDebug: boolean) {
if (!node || !node.name || !node.uri) {
vscode.window.showErrorMessage(`Failed to ${noDebug ? "run" : "debug"} the project because of invalid project node. `
+ "This command only applies to Project Explorer view.");
const error = new Error(`Failed to ${noDebug ? "run" : "debug"} the project because of invalid project node.`);
setUserError(error);
throw error;
}
const progressReporter = progressProvider.createProgressReporter(noDebug ? "Run" : "Debug");
try {
progressReporter.report("Resolving main class...");
const mainClassesOptions: IMainClassOption[] = await utility.searchMainMethods(vscode.Uri.parse(node.uri));
if (progressReporter.isCancelled()) {
throw new utility.OperationCancelledError("");
}
if (!mainClassesOptions || !mainClassesOptions.length) {
vscode.window.showErrorMessage(`Failed to ${noDebug ? "run" : "debug"} this project '${node._nodeData.displayName || node.name}' `
+ "because it does not contain any main class.");
throw new utility.OperationCancelledError("");
}
if (!mainClassPicker.isAutoPicked(mainClassesOptions)) {
progressReporter.hide(true);
}
const pick = await mainClassPicker.showQuickPickWithRecentlyUsed(mainClassesOptions,
"Select the main class to run.");
if (!pick || progressReporter.isCancelled()) {
throw new utility.OperationCancelledError("");
}
progressReporter.report("Launching main class...");
const projectName: string | undefined = pick.projectName;
const mainClass: string = pick.mainClass;
const filePath: string | undefined = pick.filePath;
const workspaceFolder: vscode.WorkspaceFolder | undefined =
filePath ? vscode.workspace.getWorkspaceFolder(vscode.Uri.file(filePath)) : undefined;
const launchConfigurations: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("launch", workspaceFolder);
const existingConfigs: vscode.DebugConfiguration[] = launchConfigurations.configurations;
const existConfig: vscode.DebugConfiguration | undefined = _.find(existingConfigs, (config) => {
return config.mainClass === mainClass && _.toString(config.projectName) === _.toString(projectName);
});
const debugConfig = existConfig || {
type: "java",
name: `Launch ${mainClass.substr(mainClass.lastIndexOf(".") + 1)}`,
request: "launch",
mainClass,
projectName,
};
debugConfig.noDebug = noDebug;
debugConfig.__progressId = progressReporter.getId();
vscode.debug.startDebugging(workspaceFolder, debugConfig);
} catch (ex) {
progressReporter.done();
if (ex instanceof utility.OperationCancelledError) {
return;
}
throw ex;
}
}