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 TelemetryReporter from "vscode-extension-telemetry";
|
||||||
import * as commands from "./commands";
|
import * as commands from "./commands";
|
||||||
import { JavaDebugConfigurationProvider } from "./configurationProvider";
|
import { JavaDebugConfigurationProvider } from "./configurationProvider";
|
||||||
import { startHotCodeReplace } from "./hotCodeReplace";
|
import { initializeHotCodeReplace } from "./hotCodeReplace";
|
||||||
|
|
||||||
export function activate(context: vscode.ExtensionContext) {
|
export function activate(context: vscode.ExtensionContext) {
|
||||||
// The reporter will be initialized by the later telemetry handler.
|
// 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)));
|
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("java", new JavaDebugConfigurationProvider(reporter)));
|
||||||
startHotCodeReplace(context);
|
initializeHotCodeReplace(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this method is called when your extension is deactivated
|
// 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 JAVA_LANGID: string = "java";
|
||||||
|
|
||||||
const HCR_EVENT = "hotCodeReplace";
|
const HCR_EVENT = "hotcodereplace";
|
||||||
|
|
||||||
enum HcrEventType {
|
enum HcrChangeType {
|
||||||
ERROR = "ERROR",
|
ERROR = "ERROR",
|
||||||
WARNING = "WARNING",
|
WARNING = "WARNING",
|
||||||
STARTING = "STARTING",
|
STARTING = "STARTING",
|
||||||
END = "END",
|
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) => {
|
context.subscriptions.push(vscode.debug.onDidTerminateDebugSession((session) => {
|
||||||
const t = session ? session.type : undefined;
|
const t = session ? session.type : undefined;
|
||||||
if (t === JAVA_LANGID) {
|
if (t === JAVA_LANGID) {
|
||||||
|
@ -28,9 +29,18 @@ export function startHotCodeReplace(context: vscode.ExtensionContext) {
|
||||||
|
|
||||||
context.subscriptions.push(vscode.debug.onDidReceiveDebugSessionCustomEvent((customEvent) => {
|
context.subscriptions.push(vscode.debug.onDidReceiveDebugSessionCustomEvent((customEvent) => {
|
||||||
const t = customEvent.session ? customEvent.session.type : undefined;
|
const t = customEvent.session ? customEvent.session.type : undefined;
|
||||||
if (t === JAVA_LANGID) {
|
if (t !== JAVA_LANGID || customEvent.event !== HCR_EVENT) {
|
||||||
if (customEvent.event === HCR_EVENT) {
|
return;
|
||||||
if (customEvent.body.eventType === HcrEventType.ERROR || customEvent.body.eventType === HcrEventType.WARNING) {
|
}
|
||||||
|
|
||||||
|
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)) {
|
if (!suppressedReasons.has(customEvent.body.message)) {
|
||||||
vscode.window.showInformationMessage(`Hot code replace failed - ${customEvent.body.message}`, NOT_SHOW_AGAIN).then((res) => {
|
vscode.window.showInformationMessage(`Hot code replace failed - ${customEvent.body.message}`, NOT_SHOW_AGAIN).then((res) => {
|
||||||
if (res === NOT_SHOW_AGAIN) {
|
if (res === NOT_SHOW_AGAIN) {
|
||||||
|
@ -38,23 +48,6 @@ export function startHotCodeReplace(context: vscode.ExtensionContext) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} 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