forked from redhat-developer/vscode-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverStatusBarProvider.ts
More file actions
118 lines (104 loc) · 3.72 KB
/
serverStatusBarProvider.ts
File metadata and controls
118 lines (104 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'use strict';
import { StatusBarItem, window, StatusBarAlignment, version } from "vscode";
import { Commands } from "./commands";
import { Disposable } from "vscode-languageclient";
import * as semver from "semver";
import { ServerStatusItemFactory, StatusCommands, supportsLanguageStatus } from "./languageStatusItemFactory";
class ServerStatusBarProvider implements Disposable {
private statusBarItem: StatusBarItem;
private languageStatusItem: any;
// Adopt new API for status bar item, meanwhile keep the compatibility with Theia.
// See: https://github.com/redhat-developer/vscode-java/issues/1982
private isAdvancedStatusBarItem: boolean;
constructor() {
this.isAdvancedStatusBarItem = semver.gte(version, "1.57.0");
}
public initialize(): void {
if (supportsLanguageStatus()) {
this.languageStatusItem = ServerStatusItemFactory.create();
} else {
if (this.isAdvancedStatusBarItem) {
this.statusBarItem = (window.createStatusBarItem as any)("java.serverStatus", StatusBarAlignment.Right, Number.MIN_VALUE);
} else {
this.statusBarItem = window.createStatusBarItem(StatusBarAlignment.Right, Number.MIN_VALUE);
}
}
}
public showLightWeightStatus(): void {
if (supportsLanguageStatus()) {
ServerStatusItemFactory.showLightWeightStatus(this.languageStatusItem);
} else {
if (this.isAdvancedStatusBarItem) {
(this.statusBarItem as any).name = "Java Server Mode";
}
this.statusBarItem.text = StatusIcon.lightWeight;
this.statusBarItem.command = StatusCommands.switchToStandardCommand;
this.statusBarItem.tooltip = "Java language server is running in LightWeight mode, click to switch to Standard mode";
this.statusBarItem.show();
}
}
public showStandardStatus(): void {
if (supportsLanguageStatus()) {
ServerStatusItemFactory.showStandardStatus(this.languageStatusItem);
ServerStatusItemFactory.setBusy(this.languageStatusItem);
} else {
if (this.isAdvancedStatusBarItem) {
(this.statusBarItem as any).name = "Java Server Status";
}
this.statusBarItem.text = StatusIcon.busy;
this.statusBarItem.command = Commands.SHOW_SERVER_TASK_STATUS;
this.statusBarItem.tooltip = "";
this.statusBarItem.show();
}
}
public setBusy(): void {
if (supportsLanguageStatus()) {
ServerStatusItemFactory.setBusy(this.languageStatusItem);
} else {
this.statusBarItem.text = StatusIcon.busy;
}
}
public setError(): void {
if (supportsLanguageStatus()) {
ServerStatusItemFactory.setError(this.languageStatusItem);
} else {
this.statusBarItem.text = StatusIcon.error;
this.statusBarItem.command = Commands.OPEN_LOGS;
}
}
public setWarning(): void {
if (supportsLanguageStatus()) {
ServerStatusItemFactory.setWarning(this.languageStatusItem);
} else {
this.statusBarItem.text = StatusIcon.warning;
this.statusBarItem.command = "workbench.panel.markers.view.focus";
this.statusBarItem.tooltip = "Errors occurred in project configurations, click to show the PROBLEMS panel";
}
}
public setReady(): void {
if (supportsLanguageStatus()) {
ServerStatusItemFactory.setReady(this.languageStatusItem);
} else {
this.statusBarItem.text = StatusIcon.ready;
this.statusBarItem.command = Commands.SHOW_SERVER_TASK_STATUS;
this.statusBarItem.tooltip = "ServiceReady";
}
}
public updateTooltip(tooltip: string): void {
if (!supportsLanguageStatus()) {
this.statusBarItem.tooltip = tooltip;
}
}
public dispose(): void {
this.statusBarItem?.dispose();
this.languageStatusItem?.dispose();
}
}
export enum StatusIcon {
lightWeight = "$(rocket)",
busy = "$(sync~spin)",
ready = "$(thumbsup)",
warning = "$(thumbsdown)",
error = "$(thumbsdown)"
}
export const serverStatusBarProvider: ServerStatusBarProvider = new ServerStatusBarProvider();