Skip to content

Commit 6bee9dd

Browse files
refactor the progress api based on feedback
1 parent 3937ed1 commit 6bee9dd

File tree

9 files changed

+155
-95
lines changed

9 files changed

+155
-95
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Please also check the documentation of [Language Support for Java by Red Hat](ht
121121
- `java.debug.settings.jdwp.limitOfVariablesPerJdwpRequest`: The maximum number of variables or fields that can be requested in one JDWP request. The higher the value, the less frequently debuggee will be requested when expanding the variable view. Also a large number can cause JDWP request timeout. Defaults to 100.
122122
- `java.debug.settings.jdwp.requestTimeout`: The timeout (ms) of JDWP request when the debugger communicates with the target JVM. Defaults to 3000.
123123
- `java.debug.settings.vmArgs`: The default VM arguments to launch the Java program. Eg. Use '-Xmx1G -ea' to increase the heap size to 1GB and enable assertions. If you want to customize the VM arguments for a specific debug session, please modify the 'vmArgs' config in launch.json.
124-
- `java.debug.settings.showRunStatusAsNotification`: Show the build status as the progress notification every time you run or debug a program. Defaults to `true`.
124+
- `java.silentNotification`: Control whether the progress notifications can be shown. Defaults to `false`.
125125

126126
Pro Tip: The documentation [Configuration.md](https://github.com/microsoft/vscode-java-debug/blob/master/Configuration.md) provides lots of samples to demonstrate how to use these debug configurations, recommend to take a look.
127127

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,10 @@
742742
"description": "%java.debugger.configuration.vmArgs.description%",
743743
"default": ""
744744
},
745-
"java.debug.settings.showRunStatusAsNotification": {
745+
"java.silentNotification": {
746746
"type": "boolean",
747-
"description": "%java.debugger.configuration.showRunStatusAsNotification%",
748-
"default": true
747+
"description": "%java.debugger.configuration.silentNotification%",
748+
"default": false
749749
}
750750
}
751751
}

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,5 @@
5959
"java.debugger.configuration.jdwp.limitOfVariablesPerJdwpRequest.description": "The maximum number of variables or fields that can be requested in one JDWP request. The higher the value, the less frequently debuggee will be requested when expanding the variable view. Also a large number can cause JDWP request timeout.",
6060
"java.debugger.configuration.jdwp.requestTimeout.description": "The timeout (ms) of JDWP request when the debugger communicates with the target JVM.",
6161
"java.debugger.configuration.vmArgs.description": "The default VM arguments to launch the Java program. Eg. Use '-Xmx1G -ea' to increase the heap size to 1GB and enable assertions. If you want to customize the VM arguments for a specific debug session, please modify the 'vmArgs' config in launch.json.",
62-
"java.debugger.configuration.showRunStatusAsNotification": "Show the build status as the progress notification every time you run or debug a program."
62+
"java.debugger.configuration.silentNotification": "Control whether the progress notifications can be shown."
6363
}

package.nls.zh.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@
5757
"java.debugger.configuration.jdwp.limitOfVariablesPerJdwpRequest.description": "一次JDWP请求中可以请求的变量或字段的最大数量。该值越高,在展开变量视图时,请求debuggee的频率就越低。同时数量过大也会导致JDWP请求超时。",
5858
"java.debugger.configuration.jdwp.requestTimeout.description": "调试器与目标JVM通信时JDWP请求的超时时间(ms)。",
5959
"java.debugger.configuration.vmArgs.description": "启动Java程序的默认VM参数。例如,使用'-Xmx1G -ea'将堆大小增加到1GB并启用断言。如果要为特定的调试会话定制VM参数,请修改launch.json中的'vmArgs'配置。",
60-
"java.debugger.configuration.showRunStatusAsNotification": "每次运行或调试程序时,将构建状态显示为进度通知"
60+
"java.debugger.configuration.silentNotification": "控制是否可以显示进度通知"
6161
}

src/build.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,13 @@ async function handleBuildFailure(operationId: string, err: any, progressReporte
5656
});
5757
setErrorCode(error, Number(err));
5858
sendOperationError(operationId, "build", error);
59-
if (err === lsPlugin.CompileWorkspaceStatus.WITHERROR || err === lsPlugin.CompileWorkspaceStatus.FAILED) {
59+
if (!onBuildFailureProceed && (err === lsPlugin.CompileWorkspaceStatus.WITHERROR || err === lsPlugin.CompileWorkspaceStatus.FAILED)) {
6060
if (checkErrorsReportedByJavaExtension()) {
6161
vscode.commands.executeCommand("workbench.actions.view.problems");
6262
}
6363

64-
if (!onBuildFailureProceed) {
65-
progressReporter.report("Confirm Build Errors", "Build failed, please select the next action...");
66-
}
67-
const ans = onBuildFailureProceed ? "Proceed" : (await vscode.window.showErrorMessage("Build failed, do you want to continue?",
68-
"Proceed", "Fix...", "Cancel"));
64+
progressReporter.hide(true);
65+
const ans = await vscode.window.showErrorMessage("Build failed, do you want to continue?", "Proceed", "Fix...", "Cancel");
6966
sendInfo(operationId, {
7067
operationName: "build",
7168
choiceForBuildError: ans || "esc",

src/configurationProvider.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { logger, Type } from "./logger";
1717
import { mainClassPicker } from "./mainClassPicker";
1818
import { resolveJavaProcess } from "./processPicker";
1919
import { IProgressReporter } from "./progressAPI";
20-
import { progressReporterManager } from "./progressImpl";
20+
import { progressProvider } from "./progressImpl";
2121
import * as utility from "./utility";
2222

2323
const platformNameMappings: {[key: string]: string} = {
@@ -90,7 +90,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
9090

9191
private provideDebugConfigurationsAsync(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken) {
9292
return new Promise(async (resolve, _reject) => {
93-
const progressReporter = progressReporterManager.create("Create launch.json", true);
93+
const progressReporter = progressProvider.createProgressReporter("Create launch.json", vscode.ProgressLocation.Window);
9494
progressReporter.observe(token);
9595
const defaultLaunchConfig = {
9696
type: "java",
@@ -171,11 +171,11 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
171171

172172
private async resolveAndValidateDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration,
173173
token?: vscode.CancellationToken) {
174-
let progressReporter = progressReporterManager.get(config.__progressId);
174+
let progressReporter = progressProvider.getProgressReporter(config.__progressId);
175175
if (!progressReporter && config.__progressId) {
176176
return undefined;
177177
}
178-
progressReporter = progressReporter || progressReporterManager.create(config.noDebug ? "Run" : "Debug");
178+
progressReporter = progressReporter || progressProvider.createProgressReporterForPreLaunchTask(config.noDebug ? "Run" : "Debug");
179179
progressReporter.observe(token);
180180
if (progressReporter.isCancelled()) {
181181
return undefined;
@@ -221,6 +221,8 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
221221
if (!proceed) {
222222
return undefined;
223223
}
224+
225+
progressReporter.show();
224226
}
225227

226228
if (progressReporter.isCancelled()) {
@@ -353,7 +355,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
353355
utility.showErrorMessageWithTroubleshooting(utility.convertErrorToMessage(ex));
354356
return undefined;
355357
} finally {
356-
progressReporter.cancel();
358+
progressReporter.done();
357359
}
358360
}
359361

@@ -388,7 +390,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
388390
if (currentFile) {
389391
const mainEntries = await lsPlugin.resolveMainMethod(vscode.Uri.file(currentFile));
390392
if (mainEntries.length) {
391-
progressReporter.report("Select mainClass", "Selecting the main class to run...");
393+
progressReporter.hide(true);
392394
return mainClassPicker.showQuickPick(mainEntries, "Please select a main class you want to run.");
393395
}
394396
}
@@ -433,14 +435,13 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
433435
}
434436

435437
if (validationResponse.proposals && validationResponse.proposals.length) {
436-
progressReporter.report("Confirm Config Error", "Config error, please select the next action...");
438+
progressReporter.hide(true);
437439
const answer = await utility.showErrorMessageWithTroubleshooting({
438440
message: errors.join(os.EOL),
439441
type: Type.USAGEERROR,
440442
anchor: anchor.FAILED_TO_RESOLVE_CLASSPATH,
441443
}, "Fix");
442444
if (answer === "Fix") {
443-
progressReporter.report("Select mainClass", "Select the main class to run...");
444445
const selectedFix = await mainClassPicker.showQuickPick(validationResponse.proposals,
445446
"Please select main class<project name>.", false);
446447
if (selectedFix) {
@@ -502,7 +503,7 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
502503
});
503504
}
504505

505-
progressReporter.report("Select mainClass", "Selecting the main class to run...");
506+
progressReporter.hide(true);
506507
return mainClassPicker.showQuickPickWithRecentlyUsed(res, hintMessage || "Select main class<project name>");
507508
}
508509
}

src/extension.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { logger, Type } from "./logger";
2020
import { mainClassPicker } from "./mainClassPicker";
2121
import { pickJavaProcess } from "./processPicker";
2222
import { IProgressReporter } from "./progressAPI";
23-
import { progressReporterManager, registerProgressReporters } from "./progressImpl";
23+
import { progressProvider } from "./progressImpl";
2424
import { JavaTerminalLinkProvder } from "./terminalLinkProvider";
2525
import { initializeThreadOperations } from "./threadOperations";
2626
import * as utility from "./utility";
@@ -36,7 +36,6 @@ function initializeExtension(_operationId: string, context: vscode.ExtensionCont
3636
// Deprecated
3737
logger.initialize(context, true);
3838

39-
registerProgressReporters(context);
4039
registerDebugEventListener(context);
4140
context.subscriptions.push(logger);
4241
context.subscriptions.push(vscode.window.registerTerminalLinkProvider(new JavaTerminalLinkProvder()));
@@ -78,7 +77,7 @@ function initializeExtension(_operationId: string, context: vscode.ExtensionCont
7877
initializeThreadOperations(context);
7978

8079
return {
81-
progressReporterManager,
80+
progressProvider,
8281
};
8382
}
8483

@@ -233,7 +232,7 @@ async function applyHCR(hcrStatusBar: NotificationBar) {
233232
}
234233

235234
async function runJavaFile(uri: vscode.Uri, noDebug: boolean) {
236-
const progressReporter = progressReporterManager.create(noDebug ? "Run" : "Debug");
235+
const progressReporter = progressProvider.createProgressReporterForPreLaunchTask(noDebug ? "Run" : "Debug");
237236
try {
238237
// Wait for Java Language Support extension being on Standard mode.
239238
const isOnStandardMode = await utility.waitForStandardMode(progressReporter);
@@ -323,12 +322,13 @@ async function launchMain(mainMethods: IMainClassOption[], uri: vscode.Uri, noDe
323322
throw new utility.OperationCancelledError("");
324323
}
325324

326-
progressReporter.report("Select mainClass", "Selecting the main class to run...");
325+
progressReporter.hide(true);
327326
const pick = await mainClassPicker.showQuickPickWithRecentlyUsed(mainMethods, placeHolder, autoPick);
328327
if (!pick) {
329328
throw new utility.OperationCancelledError("");
330329
}
331330

331+
progressReporter.show();
332332
startDebugging(pick.mainClass, pick.projectName || "", uri, noDebug, progressReporter);
333333
}
334334

@@ -341,7 +341,7 @@ async function runJavaProject(node: any, noDebug: boolean) {
341341
throw error;
342342
}
343343

344-
const progressReporter = progressReporterManager.create(noDebug ? "Run" : "Debug");
344+
const progressReporter = progressProvider.createProgressReporterForPreLaunchTask(noDebug ? "Run" : "Debug");
345345
try {
346346
progressReporter.report("Resolve mainClass", "Resolving main class...");
347347
const mainClassesOptions: IMainClassOption[] = await utility.searchMainMethods(vscode.Uri.parse(node.uri));
@@ -355,13 +355,14 @@ async function runJavaProject(node: any, noDebug: boolean) {
355355
throw new utility.OperationCancelledError("");
356356
}
357357

358-
progressReporter.report("Select mainClass", "Selecting the main class to run...");
358+
progressReporter.hide(true);
359359
const pick = await mainClassPicker.showQuickPickWithRecentlyUsed(mainClassesOptions,
360360
"Select the main class to run.");
361361
if (!pick || progressReporter.isCancelled()) {
362362
throw new utility.OperationCancelledError("");
363363
}
364364

365+
progressReporter.show();
365366
const projectName: string | undefined = pick.projectName;
366367
const mainClass: string = pick.mainClass;
367368
const filePath: string | undefined = pick.filePath;

src/progressAPI.ts

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import { CancellationToken } from "vscode";
4+
import { CancellationToken, ProgressLocation } from "vscode";
55

66
export interface IProgressReporter {
77
/**
@@ -10,51 +10,71 @@ export interface IProgressReporter {
1010
getId(): string;
1111

1212
/**
13-
* Update the progress message.
14-
* @param subTaskName the sub task name to update
15-
* @param detailedMessage the detailed message to update
13+
* Reports a progress message update.
14+
* @param subTaskName the message shown in the status bar
15+
* @param detailedMessage the detailed message shown in the notification
1616
*/
1717
report(subTaskName: string, detailedMessage: string): void;
1818

1919
/**
20-
* Cancel the progress reporter.
20+
* Shows the progress reporter.
21+
*/
22+
show(): void;
23+
24+
/**
25+
* Hides the progress reporter.
26+
* @param onlyNotifications only hide the progress reporter when it's shown as notification
27+
*/
28+
hide(onlyNotifications?: boolean): void;
29+
30+
/**
31+
* Cancels the progress reporter.
2132
*/
2233
cancel(): void;
2334

2435
/**
25-
* Is the progress reporter cancelled.
36+
* Returns whether the progress reporter has been cancelled or completed.
2637
*/
2738
isCancelled(): boolean;
2839

40+
/**
41+
* Notifies the work is done that is either the task is completed or the user has cancelled it.
42+
*/
43+
done(): void;
44+
2945
/**
3046
* The CancellationToken to monitor if the progress reporter has been cancelled by the user.
3147
*/
3248
getCancellationToken(): CancellationToken;
3349

3450
/**
35-
* Dispose the progress reporter if the observed token has been cancelled.
51+
* Disposes the progress reporter if the observed token has been cancelled.
3652
* @param token the cancellation token to observe
3753
*/
3854
observe(token?: CancellationToken): void;
3955
}
4056

41-
export interface IProgressReporterManager {
57+
export interface IProgressReporterProvider {
4258
/**
43-
* Create a progress reporter.
59+
* Creates a progress reporter.
4460
* @param jobName the job name
45-
* @param showInStatusBar whether to show the progress in the status bar
61+
* @param progressLocation The location at which progress should show
62+
* @param cancellable Controls if a cancel button should show to allow the user
63+
* to cancel the progress reporter. Note that currently only
64+
* `ProgressLocation.Notification` is supporting to show a cancel
65+
* button.
4666
*/
47-
create(jobName: string, showInStatusBar?: boolean): IProgressReporter;
67+
createProgressReporter(jobName: string, progressLocation: ProgressLocation | { viewId: string }, cancellable?: boolean): IProgressReporter;
4868

4969
/**
50-
* Return the progress repoter with the progress id.
51-
* @param progressId the progress id
70+
* Creates a progress reporter for the task to run before the debug session starts.
71+
* @param jobName the job name
5272
*/
53-
get(progressId: string): IProgressReporter | undefined;
73+
createProgressReporterForPreLaunchTask(jobName: string): IProgressReporter;
5474

5575
/**
56-
* Remove the progress reporter from the progress reporter manager.
57-
* @param progressReporter the progress reporter to remove
76+
* Returns the progress reporter with the progress id.
77+
* @param progressId the progress id
5878
*/
59-
remove(progressReporter: IProgressReporter): void;
79+
getProgressReporter(progressId: string): IProgressReporter | undefined;
6080
}

0 commit comments

Comments
 (0)