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
101 lines (89 loc) · 3.87 KB
/
extension.ts
File metadata and controls
101 lines (89 loc) · 3.87 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as path from "path";
import * as vscode from "vscode";
import * as commands from "./commands";
import { JavaDebugConfigurationProvider } from "./configurationProvider";
import { HCR_EVENT, JAVA_LANGID, USER_NOTIFICATION_EVENT } from "./constants";
import { handleHotCodeReplaceCustomEvent, initializeHotCodeReplace } from "./hotCodeReplace";
import { logger, Type } from "./logger";
import * as utility from "./utility";
export function activate(context: vscode.ExtensionContext) {
logger.initialize(context);
logger.log(Type.ACTIVATEEXTENSION, {}); // TODO: Activation belongs to usage data, remove this line.
logger.log(Type.USAGEDATA, {
description: "activateExtension",
});
const measureKeys = ["duration"];
vscode.debug.onDidTerminateDebugSession(() => {
fetchUsageData().then((ret) => {
if (Array.isArray(ret) && ret.length) {
ret.forEach((entry) => {
const commonProperties: any = {};
const measureProperties: any = {};
for (const key of Object.keys(entry)) {
if (measureKeys.indexOf(key) >= 0) {
measureProperties[key] = entry[key];
} else {
commonProperties[key] = String(entry[key]);
}
}
logger.log(entry.scope === "exception" ? Type.EXCEPTION : Type.USAGEDATA, commonProperties, measureProperties);
});
}
});
});
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("java", new JavaDebugConfigurationProvider()));
context.subscriptions.push(vscode.commands.registerCommand("JavaDebug.SpecifyProgramArgs", async () => {
return specifyProgramArguments(context);
}));
initializeHotCodeReplace(context);
context.subscriptions.push(vscode.debug.onDidReceiveDebugSessionCustomEvent((customEvent) => {
const t = customEvent.session ? customEvent.session.type : undefined;
if (t !== JAVA_LANGID) {
return;
}
if (customEvent.event === HCR_EVENT) {
handleHotCodeReplaceCustomEvent(customEvent);
} else if (customEvent.event === USER_NOTIFICATION_EVENT) {
handleUserNotification(customEvent);
}
}));
}
// this method is called when your extension is deactivated
export function deactivate() {
}
function handleUserNotification(customEvent) {
if (customEvent.body.notificationType === "ERROR") {
utility.showErrorMessageWithTroubleshooting({
message: customEvent.body.message,
});
} else if (customEvent.body.notificationType === "WARNING") {
utility.showWarningMessageWithTroubleshooting({
message: customEvent.body.message,
});
} else {
vscode.window.showInformationMessage(customEvent.body.message);
}
}
function fetchUsageData() {
return commands.executeJavaLanguageServerCommand(commands.JAVA_FETCH_USAGE_DATA);
}
function specifyProgramArguments(context: vscode.ExtensionContext): Thenable<string> {
const javaDebugProgramArgsKey = "JavaDebugProgramArgs";
const options: vscode.InputBoxOptions = {
ignoreFocusOut: true,
placeHolder: "Enter program arguments or leave empty to pass no args",
};
const prevArgs = context.workspaceState.get(javaDebugProgramArgsKey, "");
if (prevArgs.length > 0) {
options.value = prevArgs;
}
return vscode.window.showInputBox(options).then((text) => {
// When user cancels the input box (by pressing Esc), the text value is undefined.
if (text !== undefined) {
context.workspaceState.update(javaDebugProgramArgsKey, text);
}
return text || " ";
});
}