forked from redhat-developer/vscode-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguageStatusItemFactory.ts
More file actions
159 lines (141 loc) · 4.84 KB
/
languageStatusItemFactory.ts
File metadata and controls
159 lines (141 loc) · 4.84 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
'use strict';
import * as path from "path";
import * as vscode from "vscode";
import { Commands } from "./commands";
import { StatusIcon } from "./serverStatusBarProvider";
const languageServerDocumentSelector = [
{ scheme: 'file', language: 'java' },
{ scheme: 'jdt', language: 'java' },
{ scheme: 'untitled', language: 'java' },
{ pattern: '**/pom.xml' },
{ pattern: '**/{build,settings}.gradle'},
{ pattern: '**/{build,settings}.gradle.kts'}
];
export function supportsLanguageStatus(): boolean {
return !!vscode.languages.createLanguageStatusItem;
}
export namespace StatusCommands {
export const switchToStandardCommand = {
title: "Load Projects",
command: Commands.SWITCH_SERVER_MODE,
arguments: ["Standard", true],
tooltip: "LightWeight mode only provides limited features, please load projects to get full feature set"
};
export const showServerStatusCommand = {
title: "Show Build Status",
command: Commands.SHOW_SERVER_TASK_STATUS,
tooltip: "Show Build Status"
};
export const configureJavaRuntimeCommand = {
title: "Configure Java Runtime",
command: "workbench.action.openSettings",
arguments: ["java.configuration.runtimes"],
tooltip: "Configure Java Runtime"
};
}
export namespace ServerStatusItemFactory {
export function create(): any {
if (supportsLanguageStatus()) {
const item = vscode.languages.createLanguageStatusItem("JavaServerStatusItem", languageServerDocumentSelector);
item.name = "Java Language Server Status";
return item;
}
return undefined;
}
export function showLightWeightStatus(item: any): void {
item.severity = vscode.LanguageStatusSeverity?.Warning;
item.text = StatusIcon.lightWeight;
item.detail = "Lightweight Mode";
item.command = StatusCommands.switchToStandardCommand;
}
export function showStandardStatus(item: any): void {
item.severity = vscode.LanguageStatusSeverity?.Information;
item.command = StatusCommands.showServerStatusCommand;
}
export function setBusy(item: any): void {
if (item.busy === true) {
return;
}
item.text = "Building";
item.busy = true;
}
export function setError(item: any): void {
item.busy = false;
item.severity = vscode.LanguageStatusSeverity?.Error;
item.command = {
title: "Open logs",
command: Commands.OPEN_LOGS
};
item.text = StatusIcon.error;
item.detail = "Errors occurred in initializing language server";
}
export function setWarning(item: any): void {
item.busy = false;
item.severity = vscode.LanguageStatusSeverity?.Error;
item.command = {
title: "Show PROBLEMS Panel",
command: "workbench.panel.markers.view.focus",
tooltip: "Errors occurred in project configurations, click to show the PROBLEMS panel"
};
item.text = StatusIcon.warning;
item.detail = "Project Configuration Error";
}
export function setReady(item: any): void {
if (item.text === StatusIcon.ready) {
return;
}
item.busy = false;
item.severity = vscode.LanguageStatusSeverity?.Information;
item.command = StatusCommands.showServerStatusCommand;
item.text = StatusIcon.ready;
item.detail = "";
}
}
export namespace RuntimeStatusItemFactory {
export function create(text: string, vmInstallPath: string): any {
if (supportsLanguageStatus()) {
const item = vscode.languages.createLanguageStatusItem("javaRuntimeStatusItem", languageServerDocumentSelector);
item.severity = vscode.LanguageStatusSeverity?.Information;
item.name = "Java Runtime";
item.text = text;
item.command = StatusCommands.configureJavaRuntimeCommand;
if (vmInstallPath) {
item.command.tooltip = `Language Level: ${text} <${vmInstallPath}>`;
}
return item;
}
return undefined;
}
export function update(item: any, text: string, vmInstallPath: string): void {
item.text = text;
item.command.tooltip = vmInstallPath ? `Language Level: ${text} <${vmInstallPath}>` : "Configure Java Runtime";
}
}
export namespace BuildFileStatusItemFactory {
export function create(buildFilePath: string): any {
if (supportsLanguageStatus()) {
const fileName = path.basename(buildFilePath);
const item = vscode.languages.createLanguageStatusItem("javaBuildFileStatusItem", languageServerDocumentSelector);
item.severity = vscode.LanguageStatusSeverity?.Information;
item.name = "Java Build File";
item.text = fileName;
item.command = getOpenBuildFileCommand(buildFilePath);
return item;
}
return undefined;
}
export function update(item: any, buildFilePath: string): void {
const fileName = path.basename(buildFilePath);
item.text = fileName;
item.command = getOpenBuildFileCommand(buildFilePath);
}
function getOpenBuildFileCommand(buildFilePath: string): vscode.Command {
const relativePath = vscode.workspace.asRelativePath(buildFilePath);
return {
title: `Open Config File`,
command: Commands.OPEN_BROWSER,
arguments: [vscode.Uri.file(buildFilePath)],
tooltip: `Open ${relativePath}`
};
}
}