forked from microsoft/vscode-java-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotCodeReplace.ts
More file actions
54 lines (44 loc) · 1.92 KB
/
hotCodeReplace.ts
File metadata and controls
54 lines (44 loc) · 1.92 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as vscode from "vscode";
import { HCR_EVENT, JAVA_LANGID } from "./constants";
const suppressedReasons: Set<string> = new Set();
const YES_BUTTON: string = "Yes";
const NO_BUTTON: string = "No";
const NEVER_BUTTON: string = "Not show again";
enum HcrChangeType {
ERROR = "ERROR",
WARNING = "WARNING",
STARTING = "STARTING",
END = "END",
BUILD_COMPLETE = "BUILD_COMPLETE",
}
export function initializeHotCodeReplace(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.debug.onDidTerminateDebugSession((session) => {
const t = session ? session.type : undefined;
if (t === JAVA_LANGID) {
suppressedReasons.clear();
}
}));
}
export function handleHotCodeReplaceCustomEvent(hcrEvent) {
if (hcrEvent.body.changeType === HcrChangeType.BUILD_COMPLETE) {
return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, (progress) => {
progress.report({ message: "Applying code changes..." });
return hcrEvent.session.customRequest("redefineClasses");
});
}
if (hcrEvent.body.changeType === HcrChangeType.ERROR || hcrEvent.body.changeType === HcrChangeType.WARNING
3B50
) {
if (!suppressedReasons.has(hcrEvent.body.message)) {
vscode.window.showInformationMessage(
`Hot code replace failed - ${hcrEvent.body.message}. Would you like to restart the debug session?`,
YES_BUTTON, NO_BUTTON, NEVER_BUTTON).then((res) => {
if (res === NEVER_BUTTON) {
suppressedReasons.add(hcrEvent.body.message);
} else if (res === YES_BUTTON) {
vscode.commands.executeCommand("workbench.action.debug.restart");
}
});
}
}
}