From 32ce456291e94836bd4353f3ef6db29771583a73 Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Mon, 22 Jun 2020 15:39:06 +0800 Subject: [PATCH 1/3] Report HCR progress whenever it succeeds or fails Signed-off-by: Jinbo Wang --- src/customWidget.ts | 33 +++++++++++++++++++++++++++++++++ src/extension.ts | 25 ++++++++++++++++++------- 2 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 src/customWidget.ts diff --git a/src/customWidget.ts b/src/customWidget.ts new file mode 100644 index 00000000..13c414a1 --- /dev/null +++ b/src/customWidget.ts @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +import * as vscode from "vscode"; + +export class NotificationBar { + private statusBar: vscode.StatusBarItem; + private lastUpdateTime: number; + + constructor() { + this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, Number.POSITIVE_INFINITY); + } + + public show(text: string, duration?: number) { + this.statusBar.text = text; + this.statusBar.show(); + const updateTime = Date.now(); + this.lastUpdateTime = updateTime; + if (duration) { + setTimeout(() => { + if (this.lastUpdateTime === updateTime) { + this.statusBar.text = ""; + this.statusBar.hide(); + } + }, duration); + } + } + + public clear() { + this.statusBar.text = ""; + this.statusBar.hide(); + } +} diff --git a/src/extension.ts b/src/extension.ts index bcb0786c..b866331f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -9,6 +9,7 @@ import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentO import * as commands from "./commands"; import { JavaDebugConfigurationProvider } from "./configurationProvider"; import { HCR_EVENT, JAVA_LANGID, USER_NOTIFICATION_EVENT } from "./constants"; +import { NotificationBar } from "./customWidget"; import { initializeCodeLensProvider, startDebugging } from "./debugCodeLensProvider"; import { handleHotCodeReplaceCustomEvent, initializeHotCodeReplace, NO_BUTTON, YES_BUTTON } from "./hotCodeReplace"; import { JavaDebugAdapterDescriptorFactory } from "./javaDebugAdapterDescriptorFactory"; @@ -18,6 +19,8 @@ import { pickJavaProcess } from "./processPicker"; import { initializeThreadOperations } from "./threadOperations"; import * as utility from "./utility"; +const hcrStatusBar = new NotificationBar(); + export async function activate(context: vscode.ExtensionContext) { await initializeFromJsonFile(context.asAbsolutePath("./package.json"), { firstParty: true, @@ -178,14 +181,22 @@ async function applyHCR() { } } - return vscode.window.withProgress({ location: vscode.ProgressLocation.Window }, async (progress) => { - progress.report({ message: "Applying code changes..." }); + hcrStatusBar.show("$(sync~spin)Applying code changes..."); + const response = await debugSession.customRequest("redefineClasses"); + if (response && response.errorMessage) { + // The detailed error message is handled by hotCodeReplace#handleHotCodeReplaceCustomEvent + hcrStatusBar.clear(); + return; + } - const response = await debugSession.customRequest("redefineClasses"); - if (!response || !response.changedClasses || !response.changedClasses.length) { - vscode.window.showWarningMessage("Cannot find any changed classes for hot replace!"); - } - }); + if (!response || !response.changedClasses || !response.changedClasses.length) { + hcrStatusBar.clear(); + vscode.window.showWarningMessage("Cannot find any changed classes for hot replace!"); + return; + } + + const changed = response.changedClasses.length; + hcrStatusBar.show("$(check)" + `${changed} changed classe${changed > 1 ? "s are" : " is"} reloaded!`, 5 * 1000); } async function runJavaFile(uri: vscode.Uri, noDebug: boolean) { From ce36ceb85ed6e599737e7e849e95a76b33601aa4 Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Mon, 22 Jun 2020 16:45:01 +0800 Subject: [PATCH 2/3] Address review comments Signed-off-by: Jinbo Wang --- src/customWidget.ts | 6 +++++- src/extension.ts | 12 +++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/customWidget.ts b/src/customWidget.ts index 13c414a1..2f9d9840 100644 --- a/src/customWidget.ts +++ b/src/customWidget.ts @@ -3,7 +3,7 @@ import * as vscode from "vscode"; -export class NotificationBar { +export class NotificationBar implements vscode.Disposable { private statusBar: vscode.StatusBarItem; private lastUpdateTime: number; @@ -30,4 +30,8 @@ export class NotificationBar { this.statusBar.text = ""; this.statusBar.hide(); } + + dispose() { + this.statusBar.dispose(); + } } diff --git a/src/extension.ts b/src/extension.ts index b866331f..0821d256 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -19,8 +19,6 @@ import { pickJavaProcess } from "./processPicker"; import { initializeThreadOperations } from "./threadOperations"; import * as utility from "./utility"; -const hcrStatusBar = new NotificationBar(); - export async function activate(context: vscode.ExtensionContext) { await initializeFromJsonFile(context.asAbsolutePath("./package.json"), { firstParty: true, @@ -53,7 +51,11 @@ function initializeExtension(operationId: string, context: vscode.ExtensionConte // tslint:disable-next-line return javaProcess ? String(javaProcess.pid) : "${command:PickJavaProcess}"; })); - context.subscriptions.push(instrumentOperationAsVsCodeCommand("java.debug.hotCodeReplace", applyHCR)); + const hcrStatusBar: NotificationBar = new NotificationBar(); + context.subscriptions.push(hcrStatusBar); + context.subscriptions.push(instrumentOperationAsVsCodeCommand("java.debug.hotCodeReplace", async () => { + await applyHCR(hcrStatusBar); + })); context.subscriptions.push(instrumentOperationAsVsCodeCommand("java.debug.runJavaFile", async (uri: vscode.Uri) => { await runJavaFile(uri, true); })); @@ -148,7 +150,7 @@ function specifyProgramArguments(context: vscode.ExtensionContext): Thenable 1 ? "s are" : " is"} reloaded!`, 5 * 1000); + hcrStatusBar.show("$(check)" + `${changed} changed class${changed > 1 ? "es are" : " is"} reloaded!`, 5 * 1000); } async function runJavaFile(uri: vscode.Uri, noDebug: boolean) { From 0e1bfa8dc9ea8389ce6837980e130c52945b64fd Mon Sep 17 00:00:00 2001 From: Jinbo Wang Date: Mon, 22 Jun 2020 16:50:47 +0800 Subject: [PATCH 3/3] make tslint happy Signed-off-by: Jinbo Wang --- src/customWidget.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/customWidget.ts b/src/customWidget.ts index 2f9d9840..80bcc674 100644 --- a/src/customWidget.ts +++ b/src/customWidget.ts @@ -31,7 +31,7 @@ export class NotificationBar implements vscode.Disposable { this.statusBar.hide(); } - dispose() { + public dispose() { this.statusBar.dispose(); } }