@theia/editor 1.45.1 → 1.46.0-next.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -30
- package/lib/browser/decorations/editor-decoration-style.d.ts +8 -8
- package/lib/browser/decorations/editor-decoration-style.js +36 -36
- package/lib/browser/decorations/editor-decoration.d.ts +106 -106
- package/lib/browser/decorations/editor-decoration.js +37 -37
- package/lib/browser/decorations/editor-decorator.d.ts +6 -6
- package/lib/browser/decorations/editor-decorator.js +43 -43
- package/lib/browser/decorations/index.d.ts +3 -3
- package/lib/browser/decorations/index.js +30 -30
- package/lib/browser/diff-navigator.d.ts +9 -10
- package/lib/browser/diff-navigator.d.ts.map +1 -1
- package/lib/browser/diff-navigator.js +19 -19
- package/lib/browser/diff-navigator.js.map +1 -1
- package/lib/browser/editor-command.d.ts +102 -102
- package/lib/browser/editor-command.js +426 -426
- package/lib/browser/editor-contribution.d.ts +26 -26
- package/lib/browser/editor-contribution.js +198 -198
- package/lib/browser/editor-frontend-module.d.ts +5 -5
- package/lib/browser/editor-frontend-module.js +74 -74
- package/lib/browser/editor-generated-preference-schema.d.ts +282 -249
- package/lib/browser/editor-generated-preference-schema.d.ts.map +1 -1
- package/lib/browser/editor-generated-preference-schema.js +2451 -2316
- package/lib/browser/editor-generated-preference-schema.js.map +1 -1
- package/lib/browser/editor-keybinding.d.ts +5 -5
- package/lib/browser/editor-keybinding.js +55 -55
- package/lib/browser/editor-linenumber-contribution.d.ts +15 -15
- package/lib/browser/editor-linenumber-contribution.d.ts.map +1 -1
- package/lib/browser/editor-linenumber-contribution.js +95 -96
- package/lib/browser/editor-linenumber-contribution.js.map +1 -1
- package/lib/browser/editor-manager.d.ts +115 -115
- package/lib/browser/editor-manager.js +428 -428
- package/lib/browser/editor-menu.d.ts +48 -48
- package/lib/browser/editor-menu.js +210 -210
- package/lib/browser/editor-navigation-contribution.d.ts +67 -67
- package/lib/browser/editor-navigation-contribution.js +343 -343
- package/lib/browser/editor-preferences.d.ts +41 -41
- package/lib/browser/editor-preferences.js +176 -176
- package/lib/browser/editor-variable-contribution.d.ts +8 -8
- package/lib/browser/editor-variable-contribution.js +64 -64
- package/lib/browser/editor-widget-factory.d.ts +17 -17
- package/lib/browser/editor-widget-factory.js +91 -91
- package/lib/browser/editor-widget.d.ts +24 -24
- package/lib/browser/editor-widget.d.ts.map +1 -1
- package/lib/browser/editor-widget.js +122 -114
- package/lib/browser/editor-widget.js.map +1 -1
- package/lib/browser/editor.d.ts +295 -293
- package/lib/browser/editor.d.ts.map +1 -1
- package/lib/browser/editor.js +103 -103
- package/lib/browser/editor.js.map +1 -1
- package/lib/browser/index.d.ts +10 -10
- package/lib/browser/index.js +37 -37
- package/lib/browser/language-status/editor-language-status-service.d.ts +77 -77
- package/lib/browser/language-status/editor-language-status-service.js +251 -251
- package/lib/browser/navigation/navigation-location-service.d.ts +103 -103
- package/lib/browser/navigation/navigation-location-service.js +281 -281
- package/lib/browser/navigation/navigation-location-service.spec.d.ts +1 -1
- package/lib/browser/navigation/navigation-location-service.spec.js +184 -184
- package/lib/browser/navigation/navigation-location-similarity.d.ts +15 -15
- package/lib/browser/navigation/navigation-location-similarity.js +62 -62
- package/lib/browser/navigation/navigation-location-similarity.spec.d.ts +1 -1
- package/lib/browser/navigation/navigation-location-similarity.spec.js +32 -32
- package/lib/browser/navigation/navigation-location-updater.d.ts +35 -35
- package/lib/browser/navigation/navigation-location-updater.js +210 -210
- package/lib/browser/navigation/navigation-location-updater.spec.d.ts +1 -1
- package/lib/browser/navigation/navigation-location-updater.spec.js +177 -177
- package/lib/browser/navigation/navigation-location.d.ts +191 -191
- package/lib/browser/navigation/navigation-location.js +300 -300
- package/lib/browser/navigation/test/mock-navigation-location-updater.d.ts +15 -15
- package/lib/browser/navigation/test/mock-navigation-location-updater.js +38 -38
- package/lib/browser/quick-editor-service.d.ts +16 -16
- package/lib/browser/quick-editor-service.js +109 -109
- package/lib/browser/undo-redo-service.d.ts +23 -23
- package/lib/browser/undo-redo-service.js +110 -110
- package/lib/common/language-selector.d.ts +13 -13
- package/lib/common/language-selector.js +90 -90
- package/lib/package.spec.js +25 -25
- package/package.json +5 -5
- package/src/browser/decorations/editor-decoration-style.ts +41 -41
- package/src/browser/decorations/editor-decoration.ts +127 -127
- package/src/browser/decorations/editor-decorator.ts +36 -36
- package/src/browser/decorations/index.ts +19 -19
- package/src/browser/diff-navigator.ts +27 -28
- package/src/browser/editor-command.ts +414 -414
- package/src/browser/editor-contribution.ts +185 -185
- package/src/browser/editor-frontend-module.ts +87 -87
- package/src/browser/editor-generated-preference-schema.ts +2707 -2539
- package/src/browser/editor-keybinding.ts +55 -55
- package/src/browser/editor-linenumber-contribution.ts +88 -89
- package/src/browser/editor-manager.ts +442 -442
- package/src/browser/editor-menu.ts +224 -224
- package/src/browser/editor-navigation-contribution.ts +343 -343
- package/src/browser/editor-preferences.ts +226 -226
- package/src/browser/editor-variable-contribution.ts +54 -54
- package/src/browser/editor-widget-factory.ts +82 -82
- package/src/browser/editor-widget.ts +137 -130
- package/src/browser/editor.ts +360 -358
- package/src/browser/index.ts +26 -26
- package/src/browser/language-status/editor-language-status-service.ts +271 -271
- package/src/browser/language-status/editor-language-status.css +101 -101
- package/src/browser/navigation/navigation-location-service.spec.ts +245 -245
- package/src/browser/navigation/navigation-location-service.ts +284 -284
- package/src/browser/navigation/navigation-location-similarity.spec.ts +46 -46
- package/src/browser/navigation/navigation-location-similarity.ts +58 -58
- package/src/browser/navigation/navigation-location-updater.spec.ts +197 -197
- package/src/browser/navigation/navigation-location-updater.ts +220 -220
- package/src/browser/navigation/navigation-location.ts +418 -418
- package/src/browser/navigation/test/mock-navigation-location-updater.ts +41 -41
- package/src/browser/quick-editor-service.ts +94 -94
- package/src/browser/style/index.css +19 -19
- package/src/browser/undo-redo-service.ts +120 -120
- package/src/common/language-selector.ts +104 -104
- package/src/package.spec.ts +28 -28
package/src/browser/index.ts
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2018 TypeFox and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
export * from './diff-navigator';
|
|
18
|
-
export * from './editor';
|
|
19
|
-
export * from './editor-widget';
|
|
20
|
-
export * from './editor-manager';
|
|
21
|
-
export * from './editor-command';
|
|
22
|
-
export * from './editor-menu';
|
|
23
|
-
export * from './editor-frontend-module';
|
|
24
|
-
export * from './editor-preferences';
|
|
25
|
-
export * from './decorations';
|
|
26
|
-
export * from './editor-linenumber-contribution';
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2018 TypeFox and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
export * from './diff-navigator';
|
|
18
|
+
export * from './editor';
|
|
19
|
+
export * from './editor-widget';
|
|
20
|
+
export * from './editor-manager';
|
|
21
|
+
export * from './editor-command';
|
|
22
|
+
export * from './editor-menu';
|
|
23
|
+
export * from './editor-frontend-module';
|
|
24
|
+
export * from './editor-preferences';
|
|
25
|
+
export * from './decorations';
|
|
26
|
+
export * from './editor-linenumber-contribution';
|
|
@@ -1,271 +1,271 @@
|
|
|
1
|
-
// *****************************************************************************
|
|
2
|
-
// Copyright (C) 2022 Ericsson and others.
|
|
3
|
-
//
|
|
4
|
-
// This program and the accompanying materials are made available under the
|
|
5
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
-
//
|
|
8
|
-
// This Source Code may also be made available under the following Secondary
|
|
9
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
-
// with the GNU Classpath Exception which is available at
|
|
12
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
-
//
|
|
14
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
-
// *****************************************************************************
|
|
16
|
-
|
|
17
|
-
import { injectable, inject } from '@theia/core/shared/inversify';
|
|
18
|
-
import { codicon, StatusBar, StatusBarAlignment, StatusBarEntry } from '@theia/core/lib/browser';
|
|
19
|
-
import { LanguageService } from '@theia/core/lib/browser/language-service';
|
|
20
|
-
import { CommandRegistry, nls } from '@theia/core';
|
|
21
|
-
import { TextEditor } from '../editor';
|
|
22
|
-
import { EditorCommands } from '../editor-command';
|
|
23
|
-
import { LanguageSelector, score } from '../../common/language-selector';
|
|
24
|
-
import { AccessibilityInformation } from '@theia/core/lib/common/accessibility';
|
|
25
|
-
import URI from '@theia/core/lib/common/uri';
|
|
26
|
-
import { CurrentEditorAccess } from '../editor-manager';
|
|
27
|
-
import { Severity } from '@theia/core/lib/common/severity';
|
|
28
|
-
import { LabelParser } from '@theia/core/lib/browser/label-parser';
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Represents the severity of a language status item.
|
|
32
|
-
*/
|
|
33
|
-
export enum LanguageStatusSeverity {
|
|
34
|
-
Information = 0,
|
|
35
|
-
Warning = 1,
|
|
36
|
-
Error = 2
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Command represents a particular invocation of a registered command.
|
|
41
|
-
*/
|
|
42
|
-
export interface Command {
|
|
43
|
-
/**
|
|
44
|
-
* The identifier of the actual command handler.
|
|
45
|
-
*/
|
|
46
|
-
id: string;
|
|
47
|
-
/**
|
|
48
|
-
* Title of the command invocation, like "Add local variable 'foo'".
|
|
49
|
-
*/
|
|
50
|
-
title?: string;
|
|
51
|
-
/**
|
|
52
|
-
* A tooltip for for command, when represented in the UI.
|
|
53
|
-
*/
|
|
54
|
-
tooltip?: string;
|
|
55
|
-
/**
|
|
56
|
-
* Arguments that the command handler should be
|
|
57
|
-
* invoked with.
|
|
58
|
-
*/
|
|
59
|
-
arguments?: unknown[];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* A language status item is the preferred way to present language status reports for the active text editors,
|
|
64
|
-
* such as selected linter or notifying about a configuration problem.
|
|
65
|
-
*/
|
|
66
|
-
export interface LanguageStatus {
|
|
67
|
-
readonly id: string;
|
|
68
|
-
readonly name: string;
|
|
69
|
-
readonly selector: LanguageSelector;
|
|
70
|
-
readonly severity: Severity;
|
|
71
|
-
readonly label: string;
|
|
72
|
-
readonly detail: string;
|
|
73
|
-
readonly busy: boolean;
|
|
74
|
-
readonly source: string;
|
|
75
|
-
readonly command: Command | undefined;
|
|
76
|
-
readonly accessibilityInfo: AccessibilityInformation | undefined;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@injectable()
|
|
80
|
-
export class EditorLanguageStatusService {
|
|
81
|
-
@inject(StatusBar) protected readonly statusBar: StatusBar;
|
|
82
|
-
@inject(LanguageService) protected readonly languages: LanguageService;
|
|
83
|
-
@inject(CurrentEditorAccess) protected readonly editorAccess: CurrentEditorAccess;
|
|
84
|
-
@inject(CommandRegistry) protected readonly commandRegistry: CommandRegistry;
|
|
85
|
-
@inject(LabelParser) protected readonly labelParser: LabelParser;
|
|
86
|
-
protected static LANGUAGE_MODE_ID = 'editor-status-language';
|
|
87
|
-
protected static LANGUAGE_STATUS_ID = 'editor-language-status-items';
|
|
88
|
-
|
|
89
|
-
protected readonly status = new Map<number, LanguageStatus>();
|
|
90
|
-
protected pinnedCommands = new Set<string>();
|
|
91
|
-
|
|
92
|
-
setLanguageStatusItem(handle: number, item: LanguageStatus): void {
|
|
93
|
-
this.status.set(handle, item);
|
|
94
|
-
this.updateLanguageStatusItems();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
removeLanguageStatusItem(handle: number): void {
|
|
98
|
-
this.status.delete(handle);
|
|
99
|
-
this.updateLanguageStatusItems();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
updateLanguageStatus(editor: TextEditor | undefined): void {
|
|
103
|
-
if (!editor) {
|
|
104
|
-
this.statusBar.removeElement(EditorLanguageStatusService.LANGUAGE_MODE_ID);
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const language = this.languages.getLanguage(editor.document.languageId);
|
|
108
|
-
const languageName = language ? language.name : '';
|
|
109
|
-
this.statusBar.setElement(EditorLanguageStatusService.LANGUAGE_MODE_ID, {
|
|
110
|
-
text: languageName,
|
|
111
|
-
alignment: StatusBarAlignment.RIGHT,
|
|
112
|
-
priority: 1,
|
|
113
|
-
command: EditorCommands.CHANGE_LANGUAGE.id,
|
|
114
|
-
tooltip: nls.localizeByDefault('Select Language Mode')
|
|
115
|
-
});
|
|
116
|
-
this.updateLanguageStatusItems(editor);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
protected updateLanguageStatusItems(editor = this.editorAccess.editor): void {
|
|
120
|
-
if (!editor) {
|
|
121
|
-
this.statusBar.removeElement(EditorLanguageStatusService.LANGUAGE_STATUS_ID);
|
|
122
|
-
this.updatePinnedItems();
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
const uri = new URI(editor.document.uri);
|
|
126
|
-
const items = Array.from(this.status.values())
|
|
127
|
-
.filter(item => score(item.selector, uri.scheme, uri.path.toString(), editor.document.languageId, true))
|
|
128
|
-
.sort((left, right) => right.severity - left.severity);
|
|
129
|
-
if (!items.length) {
|
|
130
|
-
this.statusBar.removeElement(EditorLanguageStatusService.LANGUAGE_STATUS_ID);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const severityText = items[0].severity === Severity.Info
|
|
134
|
-
? '$(bracket)'
|
|
135
|
-
: items[0].severity === Severity.Warning
|
|
136
|
-
? '$(bracket-dot)'
|
|
137
|
-
: '$(bracket-error)';
|
|
138
|
-
this.statusBar.setElement(EditorLanguageStatusService.LANGUAGE_STATUS_ID, {
|
|
139
|
-
text: severityText,
|
|
140
|
-
alignment: StatusBarAlignment.RIGHT,
|
|
141
|
-
priority: 2,
|
|
142
|
-
tooltip: this.createTooltip(items),
|
|
143
|
-
affinity: { id: EditorLanguageStatusService.LANGUAGE_MODE_ID, alignment: StatusBarAlignment.LEFT, compact: true },
|
|
144
|
-
});
|
|
145
|
-
this.updatePinnedItems(items);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
protected updatePinnedItems(items?: LanguageStatus[]): void {
|
|
149
|
-
const toRemoveFromStatusBar = new Set(this.pinnedCommands);
|
|
150
|
-
items?.forEach(item => {
|
|
151
|
-
if (toRemoveFromStatusBar.has(item.id)) {
|
|
152
|
-
toRemoveFromStatusBar.delete(item.id);
|
|
153
|
-
this.statusBar.setElement(item.id, this.toPinnedItem(item));
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
toRemoveFromStatusBar.forEach(id => this.statusBar.removeElement(id));
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
protected toPinnedItem(item: LanguageStatus): StatusBarEntry {
|
|
160
|
-
return {
|
|
161
|
-
text: item.label,
|
|
162
|
-
affinity: { id: EditorLanguageStatusService.LANGUAGE_MODE_ID, alignment: StatusBarAlignment.RIGHT, compact: false },
|
|
163
|
-
alignment: StatusBarAlignment.RIGHT,
|
|
164
|
-
onclick: item.command && (e => { e.preventDefault(); this.commandRegistry.executeCommand(item.command!.id, ...(item.command?.arguments ?? [])); }),
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
protected createTooltip(items: LanguageStatus[]): HTMLElement {
|
|
169
|
-
const hoverContainer = document.createElement('div');
|
|
170
|
-
hoverContainer.classList.add('hover-row');
|
|
171
|
-
for (const item of items) {
|
|
172
|
-
const itemContainer = document.createElement('div');
|
|
173
|
-
itemContainer.classList.add('hover-language-status');
|
|
174
|
-
{
|
|
175
|
-
const severityContainer = document.createElement('div');
|
|
176
|
-
severityContainer.classList.add('severity', `sev${item.severity}`);
|
|
177
|
-
severityContainer.classList.toggle('show', item.severity === Severity.Error || item.severity === Severity.Warning);
|
|
178
|
-
{
|
|
179
|
-
const severityIcon = document.createElement('span');
|
|
180
|
-
severityIcon.className = this.getSeverityIconClasses(item.severity);
|
|
181
|
-
severityContainer.appendChild(severityIcon);
|
|
182
|
-
}
|
|
183
|
-
itemContainer.appendChild(severityContainer);
|
|
184
|
-
}
|
|
185
|
-
const textContainer = document.createElement('div');
|
|
186
|
-
textContainer.className = 'element';
|
|
187
|
-
const labelContainer = document.createElement('div');
|
|
188
|
-
labelContainer.className = 'left';
|
|
189
|
-
const label = document.createElement('span');
|
|
190
|
-
label.classList.add('label');
|
|
191
|
-
this.renderWithIcons(label, item.busy ? `$(sync~spin)\u00A0\u00A0${item.label}` : item.label);
|
|
192
|
-
labelContainer.appendChild(label);
|
|
193
|
-
const detail = document.createElement('span');
|
|
194
|
-
detail.classList.add('detail');
|
|
195
|
-
this.renderWithIcons(detail, item.detail);
|
|
196
|
-
labelContainer.appendChild(detail);
|
|
197
|
-
textContainer.appendChild(labelContainer);
|
|
198
|
-
const commandContainer = document.createElement('div');
|
|
199
|
-
commandContainer.classList.add('right');
|
|
200
|
-
if (item.command) {
|
|
201
|
-
const link = document.createElement('a');
|
|
202
|
-
link.classList.add('language-status-link');
|
|
203
|
-
link.href = new URI()
|
|
204
|
-
.withScheme('command')
|
|
205
|
-
.withPath(item.command.id)
|
|
206
|
-
.withQuery(item.command.arguments ? encodeURIComponent(JSON.stringify(item.command.arguments)) : '')
|
|
207
|
-
.toString(false);
|
|
208
|
-
link.onclick = e => { e.preventDefault(); this.commandRegistry.executeCommand(item.command!.id, ...(item.command?.arguments ?? [])); };
|
|
209
|
-
link.textContent = item.command.title ?? item.command.id;
|
|
210
|
-
link.title = item.command.tooltip ?? '';
|
|
211
|
-
link.ariaRoleDescription = 'button';
|
|
212
|
-
link.ariaDisabled = 'false';
|
|
213
|
-
commandContainer.appendChild(link);
|
|
214
|
-
const pinContainer = document.createElement('div');
|
|
215
|
-
pinContainer.classList.add('language-status-action-bar');
|
|
216
|
-
const pin = document.createElement('a');
|
|
217
|
-
this.setPinProperties(pin, item.id);
|
|
218
|
-
pin.onclick = e => { e.preventDefault(); this.togglePinned(item); this.setPinProperties(pin, item.id); };
|
|
219
|
-
pinContainer.appendChild(pin);
|
|
220
|
-
commandContainer.appendChild(pinContainer);
|
|
221
|
-
}
|
|
222
|
-
textContainer.appendChild(commandContainer);
|
|
223
|
-
itemContainer.append(textContainer);
|
|
224
|
-
hoverContainer.appendChild(itemContainer);
|
|
225
|
-
}
|
|
226
|
-
return hoverContainer;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
protected setPinProperties(pin: HTMLElement, id: string): void {
|
|
230
|
-
pin.className = this.pinnedCommands.has(id) ? codicon('pinned', true) : codicon('pin', true);
|
|
231
|
-
pin.ariaRoleDescription = 'button';
|
|
232
|
-
const pinText = this.pinnedCommands.has(id)
|
|
233
|
-
? nls.localizeByDefault('Remove from Status Bar')
|
|
234
|
-
: nls.localizeByDefault('Add to Status Bar');
|
|
235
|
-
pin.ariaLabel = pinText;
|
|
236
|
-
pin.title = pinText;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
protected togglePinned(item: LanguageStatus): void {
|
|
240
|
-
if (this.pinnedCommands.has(item.id)) {
|
|
241
|
-
this.pinnedCommands.delete(item.id);
|
|
242
|
-
this.statusBar.removeElement(item.id);
|
|
243
|
-
} else {
|
|
244
|
-
this.pinnedCommands.add(item.id);
|
|
245
|
-
this.statusBar.setElement(item.id, this.toPinnedItem(item));
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
protected getSeverityIconClasses(severity: Severity): string {
|
|
250
|
-
switch (severity) {
|
|
251
|
-
case Severity.Error: return codicon('error');
|
|
252
|
-
case Severity.Warning: return codicon('info');
|
|
253
|
-
default: return codicon('check');
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
protected renderWithIcons(host: HTMLElement, text?: string): void {
|
|
258
|
-
if (text) {
|
|
259
|
-
for (const chunk of this.labelParser.parse(text)) {
|
|
260
|
-
if (typeof chunk === 'string') {
|
|
261
|
-
host.append(chunk);
|
|
262
|
-
} else {
|
|
263
|
-
const iconSpan = document.createElement('span');
|
|
264
|
-
const className = codicon(chunk.name) + (chunk.animation ? ` fa-${chunk.animation}` : '');
|
|
265
|
-
iconSpan.className = className;
|
|
266
|
-
host.append(iconSpan);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
}
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2022 Ericsson and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { injectable, inject } from '@theia/core/shared/inversify';
|
|
18
|
+
import { codicon, StatusBar, StatusBarAlignment, StatusBarEntry } from '@theia/core/lib/browser';
|
|
19
|
+
import { LanguageService } from '@theia/core/lib/browser/language-service';
|
|
20
|
+
import { CommandRegistry, nls } from '@theia/core';
|
|
21
|
+
import { TextEditor } from '../editor';
|
|
22
|
+
import { EditorCommands } from '../editor-command';
|
|
23
|
+
import { LanguageSelector, score } from '../../common/language-selector';
|
|
24
|
+
import { AccessibilityInformation } from '@theia/core/lib/common/accessibility';
|
|
25
|
+
import URI from '@theia/core/lib/common/uri';
|
|
26
|
+
import { CurrentEditorAccess } from '../editor-manager';
|
|
27
|
+
import { Severity } from '@theia/core/lib/common/severity';
|
|
28
|
+
import { LabelParser } from '@theia/core/lib/browser/label-parser';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Represents the severity of a language status item.
|
|
32
|
+
*/
|
|
33
|
+
export enum LanguageStatusSeverity {
|
|
34
|
+
Information = 0,
|
|
35
|
+
Warning = 1,
|
|
36
|
+
Error = 2
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Command represents a particular invocation of a registered command.
|
|
41
|
+
*/
|
|
42
|
+
export interface Command {
|
|
43
|
+
/**
|
|
44
|
+
* The identifier of the actual command handler.
|
|
45
|
+
*/
|
|
46
|
+
id: string;
|
|
47
|
+
/**
|
|
48
|
+
* Title of the command invocation, like "Add local variable 'foo'".
|
|
49
|
+
*/
|
|
50
|
+
title?: string;
|
|
51
|
+
/**
|
|
52
|
+
* A tooltip for for command, when represented in the UI.
|
|
53
|
+
*/
|
|
54
|
+
tooltip?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Arguments that the command handler should be
|
|
57
|
+
* invoked with.
|
|
58
|
+
*/
|
|
59
|
+
arguments?: unknown[];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A language status item is the preferred way to present language status reports for the active text editors,
|
|
64
|
+
* such as selected linter or notifying about a configuration problem.
|
|
65
|
+
*/
|
|
66
|
+
export interface LanguageStatus {
|
|
67
|
+
readonly id: string;
|
|
68
|
+
readonly name: string;
|
|
69
|
+
readonly selector: LanguageSelector;
|
|
70
|
+
readonly severity: Severity;
|
|
71
|
+
readonly label: string;
|
|
72
|
+
readonly detail: string;
|
|
73
|
+
readonly busy: boolean;
|
|
74
|
+
readonly source: string;
|
|
75
|
+
readonly command: Command | undefined;
|
|
76
|
+
readonly accessibilityInfo: AccessibilityInformation | undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@injectable()
|
|
80
|
+
export class EditorLanguageStatusService {
|
|
81
|
+
@inject(StatusBar) protected readonly statusBar: StatusBar;
|
|
82
|
+
@inject(LanguageService) protected readonly languages: LanguageService;
|
|
83
|
+
@inject(CurrentEditorAccess) protected readonly editorAccess: CurrentEditorAccess;
|
|
84
|
+
@inject(CommandRegistry) protected readonly commandRegistry: CommandRegistry;
|
|
85
|
+
@inject(LabelParser) protected readonly labelParser: LabelParser;
|
|
86
|
+
protected static LANGUAGE_MODE_ID = 'editor-status-language';
|
|
87
|
+
protected static LANGUAGE_STATUS_ID = 'editor-language-status-items';
|
|
88
|
+
|
|
89
|
+
protected readonly status = new Map<number, LanguageStatus>();
|
|
90
|
+
protected pinnedCommands = new Set<string>();
|
|
91
|
+
|
|
92
|
+
setLanguageStatusItem(handle: number, item: LanguageStatus): void {
|
|
93
|
+
this.status.set(handle, item);
|
|
94
|
+
this.updateLanguageStatusItems();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
removeLanguageStatusItem(handle: number): void {
|
|
98
|
+
this.status.delete(handle);
|
|
99
|
+
this.updateLanguageStatusItems();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
updateLanguageStatus(editor: TextEditor | undefined): void {
|
|
103
|
+
if (!editor) {
|
|
104
|
+
this.statusBar.removeElement(EditorLanguageStatusService.LANGUAGE_MODE_ID);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const language = this.languages.getLanguage(editor.document.languageId);
|
|
108
|
+
const languageName = language ? language.name : '';
|
|
109
|
+
this.statusBar.setElement(EditorLanguageStatusService.LANGUAGE_MODE_ID, {
|
|
110
|
+
text: languageName,
|
|
111
|
+
alignment: StatusBarAlignment.RIGHT,
|
|
112
|
+
priority: 1,
|
|
113
|
+
command: EditorCommands.CHANGE_LANGUAGE.id,
|
|
114
|
+
tooltip: nls.localizeByDefault('Select Language Mode')
|
|
115
|
+
});
|
|
116
|
+
this.updateLanguageStatusItems(editor);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
protected updateLanguageStatusItems(editor = this.editorAccess.editor): void {
|
|
120
|
+
if (!editor) {
|
|
121
|
+
this.statusBar.removeElement(EditorLanguageStatusService.LANGUAGE_STATUS_ID);
|
|
122
|
+
this.updatePinnedItems();
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const uri = new URI(editor.document.uri);
|
|
126
|
+
const items = Array.from(this.status.values())
|
|
127
|
+
.filter(item => score(item.selector, uri.scheme, uri.path.toString(), editor.document.languageId, true))
|
|
128
|
+
.sort((left, right) => right.severity - left.severity);
|
|
129
|
+
if (!items.length) {
|
|
130
|
+
this.statusBar.removeElement(EditorLanguageStatusService.LANGUAGE_STATUS_ID);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const severityText = items[0].severity === Severity.Info
|
|
134
|
+
? '$(bracket)'
|
|
135
|
+
: items[0].severity === Severity.Warning
|
|
136
|
+
? '$(bracket-dot)'
|
|
137
|
+
: '$(bracket-error)';
|
|
138
|
+
this.statusBar.setElement(EditorLanguageStatusService.LANGUAGE_STATUS_ID, {
|
|
139
|
+
text: severityText,
|
|
140
|
+
alignment: StatusBarAlignment.RIGHT,
|
|
141
|
+
priority: 2,
|
|
142
|
+
tooltip: this.createTooltip(items),
|
|
143
|
+
affinity: { id: EditorLanguageStatusService.LANGUAGE_MODE_ID, alignment: StatusBarAlignment.LEFT, compact: true },
|
|
144
|
+
});
|
|
145
|
+
this.updatePinnedItems(items);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
protected updatePinnedItems(items?: LanguageStatus[]): void {
|
|
149
|
+
const toRemoveFromStatusBar = new Set(this.pinnedCommands);
|
|
150
|
+
items?.forEach(item => {
|
|
151
|
+
if (toRemoveFromStatusBar.has(item.id)) {
|
|
152
|
+
toRemoveFromStatusBar.delete(item.id);
|
|
153
|
+
this.statusBar.setElement(item.id, this.toPinnedItem(item));
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
toRemoveFromStatusBar.forEach(id => this.statusBar.removeElement(id));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
protected toPinnedItem(item: LanguageStatus): StatusBarEntry {
|
|
160
|
+
return {
|
|
161
|
+
text: item.label,
|
|
162
|
+
affinity: { id: EditorLanguageStatusService.LANGUAGE_MODE_ID, alignment: StatusBarAlignment.RIGHT, compact: false },
|
|
163
|
+
alignment: StatusBarAlignment.RIGHT,
|
|
164
|
+
onclick: item.command && (e => { e.preventDefault(); this.commandRegistry.executeCommand(item.command!.id, ...(item.command?.arguments ?? [])); }),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
protected createTooltip(items: LanguageStatus[]): HTMLElement {
|
|
169
|
+
const hoverContainer = document.createElement('div');
|
|
170
|
+
hoverContainer.classList.add('hover-row');
|
|
171
|
+
for (const item of items) {
|
|
172
|
+
const itemContainer = document.createElement('div');
|
|
173
|
+
itemContainer.classList.add('hover-language-status');
|
|
174
|
+
{
|
|
175
|
+
const severityContainer = document.createElement('div');
|
|
176
|
+
severityContainer.classList.add('severity', `sev${item.severity}`);
|
|
177
|
+
severityContainer.classList.toggle('show', item.severity === Severity.Error || item.severity === Severity.Warning);
|
|
178
|
+
{
|
|
179
|
+
const severityIcon = document.createElement('span');
|
|
180
|
+
severityIcon.className = this.getSeverityIconClasses(item.severity);
|
|
181
|
+
severityContainer.appendChild(severityIcon);
|
|
182
|
+
}
|
|
183
|
+
itemContainer.appendChild(severityContainer);
|
|
184
|
+
}
|
|
185
|
+
const textContainer = document.createElement('div');
|
|
186
|
+
textContainer.className = 'element';
|
|
187
|
+
const labelContainer = document.createElement('div');
|
|
188
|
+
labelContainer.className = 'left';
|
|
189
|
+
const label = document.createElement('span');
|
|
190
|
+
label.classList.add('label');
|
|
191
|
+
this.renderWithIcons(label, item.busy ? `$(sync~spin)\u00A0\u00A0${item.label}` : item.label);
|
|
192
|
+
labelContainer.appendChild(label);
|
|
193
|
+
const detail = document.createElement('span');
|
|
194
|
+
detail.classList.add('detail');
|
|
195
|
+
this.renderWithIcons(detail, item.detail);
|
|
196
|
+
labelContainer.appendChild(detail);
|
|
197
|
+
textContainer.appendChild(labelContainer);
|
|
198
|
+
const commandContainer = document.createElement('div');
|
|
199
|
+
commandContainer.classList.add('right');
|
|
200
|
+
if (item.command) {
|
|
201
|
+
const link = document.createElement('a');
|
|
202
|
+
link.classList.add('language-status-link');
|
|
203
|
+
link.href = new URI()
|
|
204
|
+
.withScheme('command')
|
|
205
|
+
.withPath(item.command.id)
|
|
206
|
+
.withQuery(item.command.arguments ? encodeURIComponent(JSON.stringify(item.command.arguments)) : '')
|
|
207
|
+
.toString(false);
|
|
208
|
+
link.onclick = e => { e.preventDefault(); this.commandRegistry.executeCommand(item.command!.id, ...(item.command?.arguments ?? [])); };
|
|
209
|
+
link.textContent = item.command.title ?? item.command.id;
|
|
210
|
+
link.title = item.command.tooltip ?? '';
|
|
211
|
+
link.ariaRoleDescription = 'button';
|
|
212
|
+
link.ariaDisabled = 'false';
|
|
213
|
+
commandContainer.appendChild(link);
|
|
214
|
+
const pinContainer = document.createElement('div');
|
|
215
|
+
pinContainer.classList.add('language-status-action-bar');
|
|
216
|
+
const pin = document.createElement('a');
|
|
217
|
+
this.setPinProperties(pin, item.id);
|
|
218
|
+
pin.onclick = e => { e.preventDefault(); this.togglePinned(item); this.setPinProperties(pin, item.id); };
|
|
219
|
+
pinContainer.appendChild(pin);
|
|
220
|
+
commandContainer.appendChild(pinContainer);
|
|
221
|
+
}
|
|
222
|
+
textContainer.appendChild(commandContainer);
|
|
223
|
+
itemContainer.append(textContainer);
|
|
224
|
+
hoverContainer.appendChild(itemContainer);
|
|
225
|
+
}
|
|
226
|
+
return hoverContainer;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
protected setPinProperties(pin: HTMLElement, id: string): void {
|
|
230
|
+
pin.className = this.pinnedCommands.has(id) ? codicon('pinned', true) : codicon('pin', true);
|
|
231
|
+
pin.ariaRoleDescription = 'button';
|
|
232
|
+
const pinText = this.pinnedCommands.has(id)
|
|
233
|
+
? nls.localizeByDefault('Remove from Status Bar')
|
|
234
|
+
: nls.localizeByDefault('Add to Status Bar');
|
|
235
|
+
pin.ariaLabel = pinText;
|
|
236
|
+
pin.title = pinText;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
protected togglePinned(item: LanguageStatus): void {
|
|
240
|
+
if (this.pinnedCommands.has(item.id)) {
|
|
241
|
+
this.pinnedCommands.delete(item.id);
|
|
242
|
+
this.statusBar.removeElement(item.id);
|
|
243
|
+
} else {
|
|
244
|
+
this.pinnedCommands.add(item.id);
|
|
245
|
+
this.statusBar.setElement(item.id, this.toPinnedItem(item));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
protected getSeverityIconClasses(severity: Severity): string {
|
|
250
|
+
switch (severity) {
|
|
251
|
+
case Severity.Error: return codicon('error');
|
|
252
|
+
case Severity.Warning: return codicon('info');
|
|
253
|
+
default: return codicon('check');
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
protected renderWithIcons(host: HTMLElement, text?: string): void {
|
|
258
|
+
if (text) {
|
|
259
|
+
for (const chunk of this.labelParser.parse(text)) {
|
|
260
|
+
if (typeof chunk === 'string') {
|
|
261
|
+
host.append(chunk);
|
|
262
|
+
} else {
|
|
263
|
+
const iconSpan = document.createElement('span');
|
|
264
|
+
const className = codicon(chunk.name) + (chunk.animation ? ` fa-${chunk.animation}` : '');
|
|
265
|
+
iconSpan.className = className;
|
|
266
|
+
host.append(iconSpan);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|