Skip to content

Commit 9931d8f

Browse files
testforstephenJinbo Wang
andauthored
Report HCR progress whenever it succeeds or fails (#833)
* Report HCR progress whenever it succeeds or fails Signed-off-by: Jinbo Wang <[email protected]> * Address review comments Signed-off-by: Jinbo Wang <[email protected]> * make tslint happy Signed-off-by: Jinbo Wang <[email protected]> Co-authored-by: Jinbo Wang <[email protected]>
1 parent 0e623f8 commit 9931d8f

File tree

2 files changed

+59
-9
lines changed

2 files changed

+59
-9
lines changed

src/customWidget.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
import * as vscode from "vscode";
5+
6+
export class NotificationBar implements vscode.Disposable {
7+
private statusBar: vscode.StatusBarItem;
8+
private lastUpdateTime: number;
9+
10+
constructor() {
11+
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, Number.POSITIVE_INFINITY);
12+
}
13+
14+
public show(text: string, duration?: number) {
15+
this.statusBar.text = text;
16+
this.statusBar.show();
17+
const updateTime = Date.now();
18+
this.lastUpdateTime = updateTime;
19+
if (duration) {
20+
setTimeout(() => {
21+
if (this.lastUpdateTime === updateTime) {
22+
this.statusBar.text = "";
23+
this.statusBar.hide();
24+
}
25+
}, duration);
26+
}
27+
}
28+
29+
public clear() {
30+
this.statusBar.text = "";
31+
this.statusBar.hide();
32+
}
33+
34+
public dispose() {
35+
this.statusBar.dispose();
36+
}
37+
}

src/extension.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentO
99
import * as commands from "./commands";
1010
import { JavaDebugConfigurationProvider } from "./configurationProvider";
1111
import { HCR_EVENT, JAVA_LANGID, USER_NOTIFICATION_EVENT } from "./constants";
12+
import { NotificationBar } from "./customWidget";
1213
import { initializeCodeLensProvider, startDebugging } from "./debugCodeLensProvider";
1314
import { handleHotCodeReplaceCustomEvent, initializeHotCodeReplace, NO_BUTTON, YES_BUTTON } from "./hotCodeReplace";
1415
import { JavaDebugAdapterDescriptorFactory } from "./javaDebugAdapterDescriptorFactory";
@@ -50,7 +51,11 @@ function initializeExtension(operationId: string, context: vscode.ExtensionConte
5051
// tslint:disable-next-line
5152
return javaProcess ? String(javaProcess.pid) : "${command:PickJavaProcess}";
5253
}));
53-
context.subscriptions.push(instrumentOperationAsVsCodeCommand("java.debug.hotCodeReplace", applyHCR));
54+
const hcrStatusBar: NotificationBar = new NotificationBar();
55+
context.subscriptions.push(hcrStatusBar);
56+
context.subscriptions.push(instrumentOperationAsVsCodeCommand("java.debug.hotCodeReplace", async () => {
57+
await applyHCR(hcrStatusBar);
58+
}));
5459
context.subscriptions.push(instrumentOperationAsVsCodeCommand("java.debug.runJavaFile", async (uri: vscode.Uri) => {
5560
await runJavaFile(uri, true);
5661
}));
@@ -145,7 +150,7 @@ function specifyProgramArguments(context: vscode.ExtensionContext): Thenable<str
145150
});
146151
}
147152

148-
async function applyHCR() {
153+
async function applyHCR(hcrStatusBar: NotificationBar) {
149154
const debugSession: vscode.DebugSession = vscode.debug.activeDebugSession;
150155
if (!debugSession) {
151156
return;
@@ -178,14 +183,22 @@ async function applyHCR() {
178183
}
179184
}
180185

181-
return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, async (progress) => {
182-
progress.report({ message: "Applying code changes..." });
186+
hcrStatusBar.show("$(sync~spin)Applying code changes...");
187+
const response = await debugSession.customRequest("redefineClasses");
188+
if (response && response.errorMessage) {
189+
// The detailed error message is handled by hotCodeReplace#handleHotCodeReplaceCustomEvent
190+
hcrStatusBar.clear();
191+
return;
192+
}
183193

184-
const response = await debugSession.customRequest("redefineClasses");
185-
if (!response || !response.changedClasses || !response.changedClasses.length) {
186-
vscode.window.showWarningMessage("Cannot find any changed classes for hot replace!");
187-
}
188-
});
194+
if (!response || !response.changedClasses || !response.changedClasses.length) {
195+
hcrStatusBar.clear();
196+
vscode.window.showWarningMessage("Cannot find any changed classes for hot replace!");
197+
return;
198+
}
199+
200+
const changed = response.changedClasses.length;
201+
hcrStatusBar.show("$(check)" + `${changed} changed class${changed > 1 ? "es are" : " is"} reloaded!`, 5 * 1000);
189202
}
190203

191204
async function runJavaFile(uri: vscode.Uri, noDebug: boolean) {

0 commit comments

Comments
 (0)