forked from redhat-developer/vscode-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverStatus.ts
More file actions
61 lines (47 loc) · 1.19 KB
/
serverStatus.ts
File metadata and controls
61 lines (47 loc) · 1.19 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
'use strict';
import { EventEmitter } from "vscode";
import { serverTasks } from "./serverTasks";
export enum ServerStatusKind {
ready = "Ready",
warning = "Warning",
error = "Error",
busy = "Busy",
}
const emitter = new EventEmitter<ServerStatusKind>();
let status: ServerStatusKind = ServerStatusKind.ready;
let isBusy: boolean = false;
function fireEvent() {
if (isBusy) {
emitter.fire(ServerStatusKind.busy);
return;
}
emitter.fire(status);
}
export namespace serverStatus {
let hasError: boolean = false;
export const onServerStatusChanged = emitter.event;
export function initialize() {
serverTasks.onDidUpdateServerTask(tasks => {
isBusy = tasks.some(task => !task.complete);
fireEvent();
});
}
export function updateServerStatus(newStatus: ServerStatusKind) {
if (newStatus === ServerStatusKind.busy) {
throw new Error("Busy status cannot be set directly.");
}
if (newStatus === ServerStatusKind.error || newStatus === ServerStatusKind.warning) {
hasError = true;
} else if (hasError) {
return;
}
status = newStatus;
fireEvent();
}
export function hasErrors() {
return hasError;
}
export function errorResolved() {
hasError = false;
}
}