Skip to content

Commit 18e9821

Browse files
authored
Explicitly show import progress (#2022)
* Reuse 'java.showBuildStatusOnStart.enabled' to control the appearance of the progress notification Signed-off-by: Sheng Chen <sheche@microsoft.com>
1 parent b9032f1 commit 18e9821

5 files changed

Lines changed: 95 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## 0.81.0
4+
* enhancement - Show job status via progress notification on start. See [#2022](https://github.com/redhat-developer/vscode-java/pull/2022)
45
* other - Change the default value of the setting `java.project.importOnFirstTimeStartup` to `automatic`. See [#2016](https://github.com/redhat-developer/vscode-java/pull/2016)
56

67
## 0.80.0 (June 30th, 2021)

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ The following settings are supported:
156156
* `java.codeGeneration.toString.listArrayContents`: List contents of arrays instead of using native toString(). Defaults to `true`.
157157
* `java.codeGeneration.toString.limitElements`: Limit number of items in arrays/collections/maps to list, if 0 then list all. Defaults to `0`.
158158
* `java.selectionRange.enabled`: Enable/disable Smart Selection support for Java. Disabling this option will not affect the VS Code built-in word-based and bracket-based smart selection.
159-
* `java.showBuildStatusOnStart.enabled`: Automatically show build status on startup. Defaults to `false`.
159+
* `java.showBuildStatusOnStart.enabled`: Automatically show build status on startup, defaults to `notification`.
160+
- `notification`: Show the build status via progress notification.
161+
- `terminal`: Show the build status via terminal.
162+
- `off`: Do not show any build status.
163+
> For backward compatibility, this setting also accepts boolean value, where `true` has the same meaning as `notification` and `false` has the same meaning as `off`.
160164
* `java.project.outputPath`: A relative path to the workspace where stores the compiled output. `Only` effective in the `WORKSPACE` scope. The setting will `NOT` affect Maven or Gradle project.
161165
* `java.project.referencedLibraries`: Configure glob patterns for referencing local libraries to a Java project.
162166
* `java.completion.maxResults`: Maximum number of completion results (not including snippets). `0` (the default value) disables the limit, all results are returned. In case of performance problems, consider setting a sensible limit..

package.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,23 @@
605605
"scope": "window"
606606
},
607607
"java.showBuildStatusOnStart.enabled": {
608-
"type": "boolean",
608+
"anyOf": [
609+
{
610+
"enum": [
611+
"notification",
612+
"terminal",
613+
"off"
614+
],
615+
"enumDescriptions": [
616+
"Show the build status via progress notification on start",
617+
"Show the build status via terminal on start",
618+
"Do not show any build status on start"
619+
]
620+
},
621+
"boolean"
622+
],
609623
"description": "Automatically show build status on startup.",
610-
"default": false,
624+
"default": "notification",
611625
"scope": "window"
612626
},
613627
"java.configuration.runtimes": {

src/serverTaskPresenter.ts

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import { tasks, Task, TaskScope, Pseudoterminal, CustomExecution, TaskExecution, TaskRevealKind, TaskPanelKind, EventEmitter, Event, TerminalDimensions } from "vscode";
2-
import * as vscode from "vscode";
1+
import { tasks, Task, TaskScope, Pseudoterminal, CustomExecution, TaskExecution, TaskRevealKind, TaskPanelKind, EventEmitter, Event, TerminalDimensions, window, ProgressLocation, Progress } from "vscode";
32
import { serverTasks } from "./serverTasks";
43
import { Disposable } from "vscode-languageclient";
54
import { ProgressReport } from "./protocol";
5+
import { Commands } from "./commands";
6+
import { getJavaConfiguration } from "./utils";
67

78
const JAVA_SERVER_TASK_PRESENTER_TASK_NAME = "Java Build Status";
89

910
export namespace serverTaskPresenter {
1011
export async function presentServerTaskView() {
1112
const execution = await getPresenterTaskExecution();
12-
const terminals = vscode.window.terminals;
13+
const terminals = window.terminals;
1314
const presenterTerminals = terminals.filter(terminal => terminal.name.indexOf(execution.task.name) >= 0);
1415
if (presenterTerminals.length > 0) {
1516
presenterTerminals[0].show();
1617
}
18+
activationProgressNotification.hide();
1719
}
1820
}
1921

@@ -57,7 +59,7 @@ async function killExistingExecutions() {
5759
execs.forEach(exec => exec.terminate());
5860
await new Promise(resolve => setTimeout(resolve, 0));
5961

60-
let terminals = vscode.window.terminals;
62+
let terminals = window.terminals;
6163
terminals = terminals.filter(terminal => terminal.name.indexOf(JAVA_SERVER_TASK_PRESENTER_TASK_NAME) >= 0);
6264
terminals.forEach(terminal => terminal.dispose());
6365
await new Promise(resolve => setTimeout(resolve, 0));
@@ -112,3 +114,48 @@ class ServerTaskTerminal implements Pseudoterminal {
112114
serverTasks.suggestTaskEntrySize(dimensions.rows - 1);
113115
}
114116
}
117+
118+
export class ActivationProgressNotification {
119+
private hideEmitter = new EventEmitter<void>();
120+
private onHide = this.hideEmitter.event;
121+
private disposables: Disposable[] = [];
122+
private lastJobId: string;
123+
124+
public showProgress() {
125+
const showBuildStatusEnabled = getJavaConfiguration().get("showBuildStatusOnStart.enabled");
126+
if (typeof showBuildStatusEnabled === "string" || showBuildStatusEnabled instanceof String) {
127+
if (showBuildStatusEnabled !== "notification") {
128+
return;
129+
}
130+
} else if (!showBuildStatusEnabled) {
131+
return;
132+
}
133+
const isProgressReportEnabled: boolean = getJavaConfiguration().get("progressReports.enabled");
134+
const title = isProgressReportEnabled ? "Opening Java Projects" : "Opening Java Projects...";
135+
window.withProgress({
136+
location: ProgressLocation.Notification,
137+
title,
138+
cancellable: false,
139+
}, (progress: Progress<{ message?: string; increment?: number }>) => {
140+
return new Promise<void>((resolve) => {
141+
if (isProgressReportEnabled) {
142+
progress.report({
143+
message: `[check details](command:${Commands.SHOW_SERVER_TASK_STATUS})`
144+
});
145+
}
146+
this.onHide(() => {
147+
for (const disposable of this.disposables) {
148+
disposable.dispose();
149+
}
150+
return resolve();
151+
});
152+
});
153+
});
154+
}
155+
156+
public hide() {
157+
this.hideEmitter.fire();
158+
}
159+
}
160+
161+
export const activationProgressNotification = new ActivationProgressNotification();

src/standardLanguageClient.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { LanguageClient, StreamInfo } from "vscode-languageclient/node";
1010
import { CompileWorkspaceRequest, CompileWorkspaceStatus, SourceAttachmentRequest, SourceAttachmentResult, SourceAttachmentAttribute, ProjectConfigurationUpdateRequest, FeatureStatus, StatusNotification, ProgressReportNotification, ActionableNotification, ExecuteClientCommandRequest, ServerNotification, EventNotification, EventType, LinkLocation, FindLinks } from "./protocol";
1111
import { setGradleWrapperChecksum, excludeProjectSettingsFiles, ServerMode } from "./settings";
1212
import { onExtensionChange, collectBuildFilePattern } from "./plugin";
13-
import { serverTaskPresenter } from "./serverTaskPresenter";
13+
import { activationProgressNotification, serverTaskPresenter } from "./serverTaskPresenter";
1414
import { RequirementsData } from "./requirements";
1515
import * as net from 'net';
1616
import * as path from 'path';
@@ -45,7 +45,7 @@ export class StandardLanguageClient {
4545
return;
4646
}
4747

48-
if (workspace.getConfiguration().get("java.showBuildStatusOnStart.enabled")) {
48+
if (workspace.getConfiguration().get("java.showBuildStatusOnStart.enabled") === "terminal") {
4949
commands.executeCommand(Commands.SHOW_SERVER_TASK_STATUS);
5050
}
5151

@@ -90,11 +90,14 @@ export class StandardLanguageClient {
9090
this.languageClient.registerProposedFeatures();
9191

9292
this.languageClient.onReady().then(() => {
93+
activationProgressNotification.showProgress();
9394
this.languageClient.onNotification(StatusNotification.type, (report) => {
9495
switch (report.type) {
9596
case 'ServiceReady':
9697
apiManager.updateServerMode(ServerMode.STANDARD);
9798
apiManager.fireDidServerModeChange(ServerMode.STANDARD);
99+
activationProgressNotification.hide();
100+
showImportFinishNotification(context);
98101
break;
99102
case 'Started':
100103
this.status = ClientStatus.Started;
@@ -443,6 +446,23 @@ export class StandardLanguageClient {
443446
}
444447
}
445448

449+
function showImportFinishNotification(context: ExtensionContext) {
450+
const showNotification: boolean | undefined = context.globalState.get<boolean>("java.neverShowImportFinishNotification");
451+
if (!showNotification) {
452+
const options = ["Don't show again"];
453+
if (extensions.getExtension("vscjava.vscode-java-dependency")) {
454+
options.unshift("View projects");
455+
}
456+
window.showInformationMessage("Projects are imported into workspace.", ...options).then((choice) => {
457+
if (choice === "Don't show again") {
458+
context.globalState.update("java.neverShowImportFinishNotification", true);
459+
} else if (choice === "View projects") {
460+
commands.executeCommand("javaProjectExplorer.focus");
461+
}
462+
});
463+
}
464+
}
465+
446466
function logNotification(message: string) {
447467
return new Promise(() => {
448468
logger.verbose(message);

0 commit comments

Comments
 (0)