8000 Report HCR progress whenever it succeeds or fails by testforstephen · Pull Request #833 · microsoft/vscode-java-debug · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/customWidget.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as vscode from "vscode";

export class NotificationBar implements vscode.Disposable {
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();
}

public dispose() {
this.statusBar.dispose();
}
}
31 changes: 22 additions & 9 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -50,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);
}));
Expand Down Expand Up @@ -145,7 +150,7 @@ function specifyProgramArguments(context: vscode.ExtensionContext): Thenable<str
});
}

async function applyHCR() {
async function applyHCR(hcrStatusBar: NotificationBar) {
const debugSession: vscode.DebugSession = vscode.debug.activeDebugSession;
if (!debugSession) {
return;
Expand Down Expand Up @@ -178,14 +183,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 class${changed > 1 ? "es are" : " is"} reloaded!`, 5 * 1000);
}

async function runJavaFile(uri: vscode.Uri, noDebug: boolean) {
Expand Down
0