forked from microsoft/vscode-java-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.ts
More file actions
49 lines (44 loc) · 2.08 KB
/
extension.ts
File metadata and controls
49 lines (44 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import * as path from "path";
import * as vscode from "vscode";
import * as commands from "./commands";
export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand(commands.JAVA_START_DEBUGSESSION, async (config) => {
if (config.request === "launch") {
if (!config.mainClass) {
vscode.window.showErrorMessage("Please specify the mainClass in the launch.json.");
return;
} else if (!config.classPaths || !Array.isArray(config.classPaths) || !config.classPaths.length) {
config.classPaths = await resolveClasspath(config.mainClass, config.projectName);
}
if (!config.classPaths || !Array.isArray(config.classPaths) || !config.classPaths.length) {
vscode.window.showErrorMessage("Cannot resolve the classpaths automatically, please specify the value in the launch.json.");
return;
}
} else if (config.request === "attach") {
if (!config.hostName || !config.port) {
vscode.window.showErrorMessage("Please specify the host name and the port of the remote debuggee in the launch.json.");
return;
}
}
const debugServerPort = await startDebugSession();
if (debugServerPort) {
config.debugServer = debugServerPort;
vscode.commands.executeCommand(commands.VSCODE_STARTDEBUG, config);
} else {
// Information for diagnostic:
console.log("Cannot find a port for debugging session");
}
});
}
// this method is called when your extension is deactivated
export function deactivate() {
}
function startDebugSession() {
return executeJavaLanguageServerCommand(commands.JAVA_START_DEBUGSESSION);
}
function resolveClasspath(mainClass, projectName) {
return executeJavaLanguageServerCommand(commands.JAVA_RESOLVE_CLASSPATH, mainClass, projectName);
}
function executeJavaLanguageServerCommand(...rest) {
return vscode.commands.executeCommand(commands.JAVA_EXECUTE_WORKSPACE_COMMAND, ...rest);
}