Skip to content

Commit e8d1c40

Browse files
authored
Show the error status when imported projects having errors (#2244)
* Show project status in the status bar Signed-off-by: sheche <[email protected]>
1 parent 562afa8 commit e8d1c40

File tree

3 files changed

+63
-14
lines changed

3 files changed

+63
-14
lines changed

src/serverStatus.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { serverTasks } from "./serverTasks";
55

66
export enum ServerStatusKind {
77
Ready = "Ready",
8+
Warning = "Warning",
89
Error = "Error",
910
Busy = "Busy",
1011
}
@@ -24,6 +25,8 @@ function fireEvent() {
2425

2526
export namespace serverStatus {
2627

28+
let hasError: boolean = false;
29+
2730
export const onServerStatusChanged = _emitter.event;
2831

2932
export function initialize() {
@@ -38,7 +41,21 @@ export namespace serverStatus {
3841
throw new Error("Busy status cannot be set directly.");
3942
}
4043

44+
if (status === ServerStatusKind.Error || status === ServerStatusKind.Warning) {
45+
hasError = true;
46+
} else if (hasError) {
47+
return;
48+
}
49+
4150
_status = status;
4251
fireEvent();
4352
}
53+
54+
export function hasErrors() {
55+
return hasError;
56+
}
57+
58+
export function errorResolved() {
59+
hasError = false;
60+
}
4461
}

src/serverStatusBarProvider.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,19 @@ class ServerStatusBarProvider implements Disposable {
5555

5656
public setError(): void {
5757
this.statusBarItem.text = StatusIcon.Error;
58+
this.statusBarItem.command = Commands.OPEN_LOGS;
59+
}
60+
61+
public setWarning(): void {
62+
this.statusBarItem.text = StatusIcon.Warning;
63+
this.statusBarItem.command = "workbench.panel.markers.view.focus";
64+
this.statusBarItem.tooltip = "Errors occurred in project configurations, click to show the PROBLEMS panel";
5865
}
5966

6067
public setReady(): void {
6168
this.statusBarItem.text = StatusIcon.Ready;
69+
this.statusBarItem.command = Commands.SHOW_SERVER_TASK_STATUS;
70+
this.statusBarItem.tooltip = "ServiceReady";
6271
}
6372

6473
public updateTooltip(tooltip: string): void {
@@ -74,6 +83,7 @@ enum StatusIcon {
7483
LightWeight = "$(rocket)",
7584
Busy = "$(sync~spin)",
7685
Ready = "$(thumbsup)",
86+
Warning = "$(thumbsdown)",
7787
Error = "$(thumbsdown)"
7888
}
7989

src/standardLanguageClient.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export class StandardLanguageClient {
6262
serverStatusBarProvider.setBusy();
6363
} else if (status === ServerStatusKind.Error) {
6464
serverStatusBarProvider.setError();
65+
} else if (status === ServerStatusKind.Warning) {
66+
serverStatusBarProvider.setWarning();
6567
} else {
6668
serverStatusBarProvider.setReady();
6769
}
@@ -116,12 +118,23 @@ export class StandardLanguageClient {
116118
apiManager.updateStatus(ClientStatus.Error);
117119
resolve(apiManager.getApiInstance());
118120
break;
121+
case 'ProjectStatus':
122+
if (report.message === "WARNING") {
123+
serverStatus.updateServerStatus(ServerStatusKind.Warning);
124+
} else if (report.message === "OK") {
125+
this.status = ClientStatus.Started;
126+
serverStatus.errorResolved();
127+
serverStatus.updateServerStatus(ServerStatusKind.Ready);
128+
}
129+
return;
119130
case 'Starting':
120131
case 'Message':
121132
// message goes to progress report instead
122133
break;
123134
}
124-
serverStatusBarProvider.updateTooltip(report.message);
135+
if (!serverStatus.hasErrors()) {
136+
serverStatusBarProvider.updateTooltip(report.message);
137+
}
125138
});
126139

127140
this.languageClient.onNotification(ProgressReportNotification.type, (progress) => {
@@ -453,22 +466,31 @@ export class StandardLanguageClient {
453466
async function showImportFinishNotification(context: ExtensionContext) {
454467
const neverShow: boolean | undefined = context.globalState.get<boolean>("java.neverShowImportFinishNotification");
455468
if (!neverShow) {
456-
const projectUris: string[] = await commands.executeCommand<string[]>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.GET_ALL_JAVA_PROJECTS);
457-
if (projectUris.length === 0 || (projectUris.length === 1 && projectUris[0].includes("jdt.ls-java-project"))) {
458-
return;
469+
let choice: string | undefined;
470+
const options = ["Don't show again"];
471+
if (serverStatus.hasErrors()) {
472+
options.unshift("Show errors");
473+
choice = await window.showWarningMessage("Errors occurred during import of Java projects.", ...options);
474+
} else {
475+
const projectUris: string[] = await commands.executeCommand<string[]>(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.GET_ALL_JAVA_PROJECTS);
476+
if (projectUris.length === 0 || (projectUris.length === 1 && projectUris[0].includes("jdt.ls-java-project"))) {
477+
return;
478+
}
479+
480+
if (extensions.getExtension("vscjava.vscode-java-dependency")) {
481+
options.unshift("View projects");
482+
}
483+
484+
choice = await window.showInformationMessage("Projects are imported into workspace.", ...options);
459485
}
460486

461-
const options = ["Don't show again"];
462-
if (extensions.getExtension("vscjava.vscode-java-dependency")) {
463-
options.unshift("View projects");
487+
if (choice === "Don't show again") {
488+
context.globalState.update("java.neverShowImportFinishNotification", true);
489+
} else if (choice === "View projects") {
490+
commands.executeCommand("javaProjectExplorer.focus");
491+
} else if (choice === "Show errors") {
492+
commands.executeCommand("workbench.panel.markers.view.focus");
464493
}
465-
window.showInformationMessage("Projects are imported into workspace.", ...options).then((choice) => {
466-
if (choice === "Don't show again") {
467-
context.globalState.update("java.neverShowImportFinishNotification", true);
468-
} else if (choice === "View projects") {
469-
commands.executeCommand("javaProjectExplorer.focus");
470-
}
471-
});
472494
}
473495
}
474496

0 commit comments

Comments
 (0)