Add HCR document update event. (#195)

* Add HCR document update event.

* Fix const value.

* Refine HCR event.
This commit is contained in:
Yaohai Zheng 2017-12-18 21:35:05 -08:00 committed by GitHub
parent 80cceab24e
commit dd884d34bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 1 deletions

View File

@ -6,6 +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";
export function activate(context: vscode.ExtensionContext) {
// The reporter will be initialized by the later telemetry handler.
@ -43,8 +44,8 @@ export function activate(context: vscode.ExtensionContext) {
});
}
}
context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider("java", new JavaDebugConfigurationProvider(reporter)));
startHotCodeReplace(context);
}
// this method is called when your extension is deactivated

81
src/hotCodeReplace.ts Normal file
View File

@ -0,0 +1,81 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as vscode from "vscode";
const runningSessions: Set<vscode.DebugSession> = new Set();
const suppressedReasons: Set<string> = new Set();
const NOT_SHOW_AGAIN: string = "Not show again";
const JAVA_LANGID: string = "java";
const HCR_EVENT = "hotCodeReplace";
const SAVEDOCUMENT_EVENT = "saveDocument";
enum HcrEventType {
ERROR = "ERROR",
WARNING = "WARNING",
STARTING = "STARTING",
END = "END",
}
export function startHotCodeReplace(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.debug.onDidStartDebugSession((session) => {
const t = session ? session.type : undefined;
if (t === JAVA_LANGID) {
runningSessions.add(session);
}
}));
context.subscriptions.push(vscode.debug.onDidTerminateDebugSession((session) => {
const t = session ? session.type : undefined;
if (t === JAVA_LANGID) {
runningSessions.delete(session);
suppressedReasons.clear();
}
}));
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);
}
});
}
} 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();
}
});
});
});
}
}
}
}
}));
context.subscriptions.push(vscode.workspace.onDidSaveTextDocument((e) => {
if (e.languageId === JAVA_LANGID) {
runningSessions.forEach((session) => {
return session.customRequest(SAVEDOCUMENT_EVENT, { documentUri: e.uri.toString() }).then(() => {
}, () => { });
});
}
}));
}