Respond to hot code replace event with custom request (#216)
This commit is contained in:
parent
c28844c8a0
commit
935dadd2ea
|
@ -6,7 +6,7 @@ import * as vscode from "vscode";
|
|||
import TelemetryReporter from "vscode-extension-telemetry";
|
||||
import * as commands from "./commands";
|
||||
import { JavaDebugConfigurationProvider } from "./configurationProvider";
|
||||
import { startHotCodeReplace } from "./hotCodeReplace";
|
||||
import { initializeHotCodeReplace } from "./hotCodeReplace";
|
||||
|
||||
export function activate(context: vscode.ExtensionContext) {
|
||||
// The reporter will be initialized by the later telemetry handler.
|
||||
|
@ -45,7 +45,7 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
}
|
||||
}
|
||||
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("java", new JavaDebugConfigurationProvider(reporter)));
|
||||
startHotCodeReplace(context);
|
||||
initializeHotCodeReplace(context);
|
||||
}
|
||||
|
||||
// this method is called when your extension is deactivated
|
||||
|
|
|
@ -9,16 +9,17 @@ const NOT_SHOW_AGAIN: string = "Not show again";
|
|||
|
||||
const JAVA_LANGID: string = "java";
|
||||
|
||||
const HCR_EVENT = "hotCodeReplace";
|
||||
const HCR_EVENT = "hotcodereplace";
|
||||
|
||||
enum HcrEventType {
|
||||
enum HcrChangeType {
|
||||
ERROR = "ERROR",
|
||||
WARNING = "WARNING",
|
||||
STARTING = "STARTING",
|
||||
END = "END",
|
||||
BUILD_COMPLETE = "BUILD_COMPLETE",
|
||||
}
|
||||
|
||||
export function startHotCodeReplace(context: vscode.ExtensionContext) {
|
||||
export function initializeHotCodeReplace(context: vscode.ExtensionContext) {
|
||||
context.subscriptions.push(vscode.debug.onDidTerminateDebugSession((session) => {
|
||||
const t = session ? session.type : undefined;
|
||||
if (t === JAVA_LANGID) {
|
||||
|
@ -28,32 +29,24 @@ export function startHotCodeReplace(context: vscode.ExtensionContext) {
|
|||
|
||||
context.subscriptions.push(vscode.debug.onDidReceiveDebugSessionCustomEvent((customEvent) => {
|
||||
const t = customEvent.session ? customEvent.session.type : undefined;
|
||||
if (t === JAVA_LANGID) {
|
||||
if (customEvent.event === HCR_EVENT) {
|
||||
if (customEvent.body.eventType === HcrEventType.ERROR || customEvent.body.eventType === HcrEventType.WARNING) {
|
||||
if (!suppressedReasons.has(customEvent.body.message)) {
|
||||
vscode.window.showInformationMessage(`Hot code replace failed - ${customEvent.body.message}`, NOT_SHOW_AGAIN).then((res) => {
|
||||
if (res === NOT_SHOW_AGAIN) {
|
||||
suppressedReasons.add(customEvent.body.message);
|
||||
}
|
||||
});
|
||||
if (t !== JAVA_LANGID || customEvent.event !== HCR_EVENT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (customEvent.body.changeType === HcrChangeType.BUILD_COMPLETE) {
|
||||
return vscode.window.withProgress({location: vscode.ProgressLocation.Window}, (progress) => {
|
||||
progress.report({message: "Applying code changes..."});
|
||||
return customEvent.session.customRequest("redefineClasses");
|
||||
});
|
||||
}
|
||||
|
||||
if (customEvent.body.changeType === HcrChangeType.ERROR || customEvent.body.changeType === HcrChangeType.WARNING) {
|
||||
if (!suppressedReasons.has(customEvent.body.message)) {
|
||||
vscode.window.showInformationMessage(`Hot code replace failed - ${customEvent.body.message}`, NOT_SHOW_AGAIN).then((res) => {
|
||||
if (res === NOT_SHOW_AGAIN) {
|
||||
suppressedReasons.add(customEvent.body.message);
|
||||
}
|
||||
} else {
|
||||
if (customEvent.body.eventType === HcrEventType.STARTING) {
|
||||
vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, (p) => {
|
||||
p.report({ message: customEvent.body.message });
|
||||
return new Promise((resolve, reject) => {
|
||||
const listener = vscode.debug.onDidReceiveDebugSessionCustomEvent((hcrEvent) => {
|
||||
p.report({ message: hcrEvent.body.message });
|
||||
if (hcrEvent.body.eventType === HcrEventType.END) {
|
||||
listener.dispose();
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
|
Loading…
Reference in New Issue