@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
|
@@ -1,252 +1,252 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// *****************************************************************************
|
|
3
|
-
// Copyright (C) 2022 Ericsson and others.
|
|
4
|
-
//
|
|
5
|
-
// This program and the accompanying materials are made available under the
|
|
6
|
-
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
-
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
-
//
|
|
9
|
-
// This Source Code may also be made available under the following Secondary
|
|
10
|
-
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
-
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
-
// with the GNU Classpath Exception which is available at
|
|
13
|
-
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
-
//
|
|
15
|
-
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
-
// *****************************************************************************
|
|
17
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
-
};
|
|
23
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
-
};
|
|
26
|
-
var EditorLanguageStatusService_1;
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.EditorLanguageStatusService = exports.LanguageStatusSeverity = void 0;
|
|
29
|
-
const inversify_1 = require("@theia/core/shared/inversify");
|
|
30
|
-
const browser_1 = require("@theia/core/lib/browser");
|
|
31
|
-
const language_service_1 = require("@theia/core/lib/browser/language-service");
|
|
32
|
-
const core_1 = require("@theia/core");
|
|
33
|
-
const editor_command_1 = require("../editor-command");
|
|
34
|
-
const language_selector_1 = require("../../common/language-selector");
|
|
35
|
-
const uri_1 = require("@theia/core/lib/common/uri");
|
|
36
|
-
const editor_manager_1 = require("../editor-manager");
|
|
37
|
-
const severity_1 = require("@theia/core/lib/common/severity");
|
|
38
|
-
const label_parser_1 = require("@theia/core/lib/browser/label-parser");
|
|
39
|
-
/**
|
|
40
|
-
* Represents the severity of a language status item.
|
|
41
|
-
*/
|
|
42
|
-
var LanguageStatusSeverity;
|
|
43
|
-
(function (LanguageStatusSeverity) {
|
|
44
|
-
LanguageStatusSeverity[LanguageStatusSeverity["Information"] = 0] = "Information";
|
|
45
|
-
LanguageStatusSeverity[LanguageStatusSeverity["Warning"] = 1] = "Warning";
|
|
46
|
-
LanguageStatusSeverity[LanguageStatusSeverity["Error"] = 2] = "Error";
|
|
47
|
-
})(LanguageStatusSeverity = exports.LanguageStatusSeverity || (exports.LanguageStatusSeverity = {}));
|
|
48
|
-
let EditorLanguageStatusService = EditorLanguageStatusService_1 = class EditorLanguageStatusService {
|
|
49
|
-
constructor() {
|
|
50
|
-
this.status = new Map();
|
|
51
|
-
this.pinnedCommands = new Set();
|
|
52
|
-
}
|
|
53
|
-
setLanguageStatusItem(handle, item) {
|
|
54
|
-
this.status.set(handle, item);
|
|
55
|
-
this.updateLanguageStatusItems();
|
|
56
|
-
}
|
|
57
|
-
removeLanguageStatusItem(handle) {
|
|
58
|
-
this.status.delete(handle);
|
|
59
|
-
this.updateLanguageStatusItems();
|
|
60
|
-
}
|
|
61
|
-
updateLanguageStatus(editor) {
|
|
62
|
-
if (!editor) {
|
|
63
|
-
this.statusBar.removeElement(EditorLanguageStatusService_1.LANGUAGE_MODE_ID);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
const language = this.languages.getLanguage(editor.document.languageId);
|
|
67
|
-
const languageName = language ? language.name : '';
|
|
68
|
-
this.statusBar.setElement(EditorLanguageStatusService_1.LANGUAGE_MODE_ID, {
|
|
69
|
-
text: languageName,
|
|
70
|
-
alignment: browser_1.StatusBarAlignment.RIGHT,
|
|
71
|
-
priority: 1,
|
|
72
|
-
command: editor_command_1.EditorCommands.CHANGE_LANGUAGE.id,
|
|
73
|
-
tooltip: core_1.nls.localizeByDefault('Select Language Mode')
|
|
74
|
-
});
|
|
75
|
-
this.updateLanguageStatusItems(editor);
|
|
76
|
-
}
|
|
77
|
-
updateLanguageStatusItems(editor = this.editorAccess.editor) {
|
|
78
|
-
if (!editor) {
|
|
79
|
-
this.statusBar.removeElement(EditorLanguageStatusService_1.LANGUAGE_STATUS_ID);
|
|
80
|
-
this.updatePinnedItems();
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
const uri = new uri_1.default(editor.document.uri);
|
|
84
|
-
const items = Array.from(this.status.values())
|
|
85
|
-
.filter(item => (0, language_selector_1.score)(item.selector, uri.scheme, uri.path.toString(), editor.document.languageId, true))
|
|
86
|
-
.sort((left, right) => right.severity - left.severity);
|
|
87
|
-
if (!items.length) {
|
|
88
|
-
this.statusBar.removeElement(EditorLanguageStatusService_1.LANGUAGE_STATUS_ID);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
const severityText = items[0].severity === severity_1.Severity.Info
|
|
92
|
-
? '$(bracket)'
|
|
93
|
-
: items[0].severity === severity_1.Severity.Warning
|
|
94
|
-
? '$(bracket-dot)'
|
|
95
|
-
: '$(bracket-error)';
|
|
96
|
-
this.statusBar.setElement(EditorLanguageStatusService_1.LANGUAGE_STATUS_ID, {
|
|
97
|
-
text: severityText,
|
|
98
|
-
alignment: browser_1.StatusBarAlignment.RIGHT,
|
|
99
|
-
priority: 2,
|
|
100
|
-
tooltip: this.createTooltip(items),
|
|
101
|
-
affinity: { id: EditorLanguageStatusService_1.LANGUAGE_MODE_ID, alignment: browser_1.StatusBarAlignment.LEFT, compact: true },
|
|
102
|
-
});
|
|
103
|
-
this.updatePinnedItems(items);
|
|
104
|
-
}
|
|
105
|
-
updatePinnedItems(items) {
|
|
106
|
-
const toRemoveFromStatusBar = new Set(this.pinnedCommands);
|
|
107
|
-
items === null || items === void 0 ? void 0 : items.forEach(item => {
|
|
108
|
-
if (toRemoveFromStatusBar.has(item.id)) {
|
|
109
|
-
toRemoveFromStatusBar.delete(item.id);
|
|
110
|
-
this.statusBar.setElement(item.id, this.toPinnedItem(item));
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
toRemoveFromStatusBar.forEach(id => this.statusBar.removeElement(id));
|
|
114
|
-
}
|
|
115
|
-
toPinnedItem(item) {
|
|
116
|
-
return {
|
|
117
|
-
text: item.label,
|
|
118
|
-
affinity: { id: EditorLanguageStatusService_1.LANGUAGE_MODE_ID, alignment: browser_1.StatusBarAlignment.RIGHT, compact: false },
|
|
119
|
-
alignment: browser_1.StatusBarAlignment.RIGHT,
|
|
120
|
-
onclick: item.command && (e => { var _a, _b; e.preventDefault(); this.commandRegistry.executeCommand(item.command.id, ...((_b = (_a = item.command) === null || _a === void 0 ? void 0 : _a.arguments) !== null && _b !== void 0 ? _b : [])); }),
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
createTooltip(items) {
|
|
124
|
-
var _a, _b;
|
|
125
|
-
const hoverContainer = document.createElement('div');
|
|
126
|
-
hoverContainer.classList.add('hover-row');
|
|
127
|
-
for (const item of items) {
|
|
128
|
-
const itemContainer = document.createElement('div');
|
|
129
|
-
itemContainer.classList.add('hover-language-status');
|
|
130
|
-
{
|
|
131
|
-
const severityContainer = document.createElement('div');
|
|
132
|
-
severityContainer.classList.add('severity', `sev${item.severity}`);
|
|
133
|
-
severityContainer.classList.toggle('show', item.severity === severity_1.Severity.Error || item.severity === severity_1.Severity.Warning);
|
|
134
|
-
{
|
|
135
|
-
const severityIcon = document.createElement('span');
|
|
136
|
-
severityIcon.className = this.getSeverityIconClasses(item.severity);
|
|
137
|
-
severityContainer.appendChild(severityIcon);
|
|
138
|
-
}
|
|
139
|
-
itemContainer.appendChild(severityContainer);
|
|
140
|
-
}
|
|
141
|
-
const textContainer = document.createElement('div');
|
|
142
|
-
textContainer.className = 'element';
|
|
143
|
-
const labelContainer = document.createElement('div');
|
|
144
|
-
labelContainer.className = 'left';
|
|
145
|
-
const label = document.createElement('span');
|
|
146
|
-
label.classList.add('label');
|
|
147
|
-
this.renderWithIcons(label, item.busy ? `$(sync~spin)\u00A0\u00A0${item.label}` : item.label);
|
|
148
|
-
labelContainer.appendChild(label);
|
|
149
|
-
const detail = document.createElement('span');
|
|
150
|
-
detail.classList.add('detail');
|
|
151
|
-
this.renderWithIcons(detail, item.detail);
|
|
152
|
-
labelContainer.appendChild(detail);
|
|
153
|
-
textContainer.appendChild(labelContainer);
|
|
154
|
-
const commandContainer = document.createElement('div');
|
|
155
|
-
commandContainer.classList.add('right');
|
|
156
|
-
if (item.command) {
|
|
157
|
-
const link = document.createElement('a');
|
|
158
|
-
link.classList.add('language-status-link');
|
|
159
|
-
link.href = new uri_1.default()
|
|
160
|
-
.withScheme('command')
|
|
161
|
-
.withPath(item.command.id)
|
|
162
|
-
.withQuery(item.command.arguments ? encodeURIComponent(JSON.stringify(item.command.arguments)) : '')
|
|
163
|
-
.toString(false);
|
|
164
|
-
link.onclick = e => { var _a, _b; e.preventDefault(); this.commandRegistry.executeCommand(item.command.id, ...((_b = (_a = item.command) === null || _a === void 0 ? void 0 : _a.arguments) !== null && _b !== void 0 ? _b : [])); };
|
|
165
|
-
link.textContent = (_a = item.command.title) !== null && _a !== void 0 ? _a : item.command.id;
|
|
166
|
-
link.title = (_b = item.command.tooltip) !== null && _b !== void 0 ? _b : '';
|
|
167
|
-
link.ariaRoleDescription = 'button';
|
|
168
|
-
link.ariaDisabled = 'false';
|
|
169
|
-
commandContainer.appendChild(link);
|
|
170
|
-
const pinContainer = document.createElement('div');
|
|
171
|
-
pinContainer.classList.add('language-status-action-bar');
|
|
172
|
-
const pin = document.createElement('a');
|
|
173
|
-
this.setPinProperties(pin, item.id);
|
|
174
|
-
pin.onclick = e => { e.preventDefault(); this.togglePinned(item); this.setPinProperties(pin, item.id); };
|
|
175
|
-
pinContainer.appendChild(pin);
|
|
176
|
-
commandContainer.appendChild(pinContainer);
|
|
177
|
-
}
|
|
178
|
-
textContainer.appendChild(commandContainer);
|
|
179
|
-
itemContainer.append(textContainer);
|
|
180
|
-
hoverContainer.appendChild(itemContainer);
|
|
181
|
-
}
|
|
182
|
-
return hoverContainer;
|
|
183
|
-
}
|
|
184
|
-
setPinProperties(pin, id) {
|
|
185
|
-
pin.className = this.pinnedCommands.has(id) ? (0, browser_1.codicon)('pinned', true) : (0, browser_1.codicon)('pin', true);
|
|
186
|
-
pin.ariaRoleDescription = 'button';
|
|
187
|
-
const pinText = this.pinnedCommands.has(id)
|
|
188
|
-
? core_1.nls.localizeByDefault('Remove from Status Bar')
|
|
189
|
-
: core_1.nls.localizeByDefault('Add to Status Bar');
|
|
190
|
-
pin.ariaLabel = pinText;
|
|
191
|
-
pin.title = pinText;
|
|
192
|
-
}
|
|
193
|
-
togglePinned(item) {
|
|
194
|
-
if (this.pinnedCommands.has(item.id)) {
|
|
195
|
-
this.pinnedCommands.delete(item.id);
|
|
196
|
-
this.statusBar.removeElement(item.id);
|
|
197
|
-
}
|
|
198
|
-
else {
|
|
199
|
-
this.pinnedCommands.add(item.id);
|
|
200
|
-
this.statusBar.setElement(item.id, this.toPinnedItem(item));
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
getSeverityIconClasses(severity) {
|
|
204
|
-
switch (severity) {
|
|
205
|
-
case severity_1.Severity.Error: return (0, browser_1.codicon)('error');
|
|
206
|
-
case severity_1.Severity.Warning: return (0, browser_1.codicon)('info');
|
|
207
|
-
default: return (0, browser_1.codicon)('check');
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
renderWithIcons(host, text) {
|
|
211
|
-
if (text) {
|
|
212
|
-
for (const chunk of this.labelParser.parse(text)) {
|
|
213
|
-
if (typeof chunk === 'string') {
|
|
214
|
-
host.append(chunk);
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
const iconSpan = document.createElement('span');
|
|
218
|
-
const className = (0, browser_1.codicon)(chunk.name) + (chunk.animation ? ` fa-${chunk.animation}` : '');
|
|
219
|
-
iconSpan.className = className;
|
|
220
|
-
host.append(iconSpan);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
EditorLanguageStatusService.LANGUAGE_MODE_ID = 'editor-status-language';
|
|
227
|
-
EditorLanguageStatusService.LANGUAGE_STATUS_ID = 'editor-language-status-items';
|
|
228
|
-
__decorate([
|
|
229
|
-
(0, inversify_1.inject)(browser_1.StatusBar),
|
|
230
|
-
__metadata("design:type", Object)
|
|
231
|
-
], EditorLanguageStatusService.prototype, "statusBar", void 0);
|
|
232
|
-
__decorate([
|
|
233
|
-
(0, inversify_1.inject)(language_service_1.LanguageService),
|
|
234
|
-
__metadata("design:type", language_service_1.LanguageService)
|
|
235
|
-
], EditorLanguageStatusService.prototype, "languages", void 0);
|
|
236
|
-
__decorate([
|
|
237
|
-
(0, inversify_1.inject)(editor_manager_1.CurrentEditorAccess),
|
|
238
|
-
__metadata("design:type", editor_manager_1.CurrentEditorAccess)
|
|
239
|
-
], EditorLanguageStatusService.prototype, "editorAccess", void 0);
|
|
240
|
-
__decorate([
|
|
241
|
-
(0, inversify_1.inject)(core_1.CommandRegistry),
|
|
242
|
-
__metadata("design:type", core_1.CommandRegistry)
|
|
243
|
-
], EditorLanguageStatusService.prototype, "commandRegistry", void 0);
|
|
244
|
-
__decorate([
|
|
245
|
-
(0, inversify_1.inject)(label_parser_1.LabelParser),
|
|
246
|
-
__metadata("design:type", label_parser_1.LabelParser)
|
|
247
|
-
], EditorLanguageStatusService.prototype, "labelParser", void 0);
|
|
248
|
-
EditorLanguageStatusService = EditorLanguageStatusService_1 = __decorate([
|
|
249
|
-
(0, inversify_1.injectable)()
|
|
250
|
-
], EditorLanguageStatusService);
|
|
251
|
-
exports.EditorLanguageStatusService = EditorLanguageStatusService;
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2022 Ericsson and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
18
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
+
};
|
|
23
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
25
|
+
};
|
|
26
|
+
var EditorLanguageStatusService_1;
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.EditorLanguageStatusService = exports.LanguageStatusSeverity = void 0;
|
|
29
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
30
|
+
const browser_1 = require("@theia/core/lib/browser");
|
|
31
|
+
const language_service_1 = require("@theia/core/lib/browser/language-service");
|
|
32
|
+
const core_1 = require("@theia/core");
|
|
33
|
+
const editor_command_1 = require("../editor-command");
|
|
34
|
+
const language_selector_1 = require("../../common/language-selector");
|
|
35
|
+
const uri_1 = require("@theia/core/lib/common/uri");
|
|
36
|
+
const editor_manager_1 = require("../editor-manager");
|
|
37
|
+
const severity_1 = require("@theia/core/lib/common/severity");
|
|
38
|
+
const label_parser_1 = require("@theia/core/lib/browser/label-parser");
|
|
39
|
+
/**
|
|
40
|
+
* Represents the severity of a language status item.
|
|
41
|
+
*/
|
|
42
|
+
var LanguageStatusSeverity;
|
|
43
|
+
(function (LanguageStatusSeverity) {
|
|
44
|
+
LanguageStatusSeverity[LanguageStatusSeverity["Information"] = 0] = "Information";
|
|
45
|
+
LanguageStatusSeverity[LanguageStatusSeverity["Warning"] = 1] = "Warning";
|
|
46
|
+
LanguageStatusSeverity[LanguageStatusSeverity["Error"] = 2] = "Error";
|
|
47
|
+
})(LanguageStatusSeverity = exports.LanguageStatusSeverity || (exports.LanguageStatusSeverity = {}));
|
|
48
|
+
let EditorLanguageStatusService = EditorLanguageStatusService_1 = class EditorLanguageStatusService {
|
|
49
|
+
constructor() {
|
|
50
|
+
this.status = new Map();
|
|
51
|
+
this.pinnedCommands = new Set();
|
|
52
|
+
}
|
|
53
|
+
setLanguageStatusItem(handle, item) {
|
|
54
|
+
this.status.set(handle, item);
|
|
55
|
+
this.updateLanguageStatusItems();
|
|
56
|
+
}
|
|
57
|
+
removeLanguageStatusItem(handle) {
|
|
58
|
+
this.status.delete(handle);
|
|
59
|
+
this.updateLanguageStatusItems();
|
|
60
|
+
}
|
|
61
|
+
updateLanguageStatus(editor) {
|
|
62
|
+
if (!editor) {
|
|
63
|
+
this.statusBar.removeElement(EditorLanguageStatusService_1.LANGUAGE_MODE_ID);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const language = this.languages.getLanguage(editor.document.languageId);
|
|
67
|
+
const languageName = language ? language.name : '';
|
|
68
|
+
this.statusBar.setElement(EditorLanguageStatusService_1.LANGUAGE_MODE_ID, {
|
|
69
|
+
text: languageName,
|
|
70
|
+
alignment: browser_1.StatusBarAlignment.RIGHT,
|
|
71
|
+
priority: 1,
|
|
72
|
+
command: editor_command_1.EditorCommands.CHANGE_LANGUAGE.id,
|
|
73
|
+
tooltip: core_1.nls.localizeByDefault('Select Language Mode')
|
|
74
|
+
});
|
|
75
|
+
this.updateLanguageStatusItems(editor);
|
|
76
|
+
}
|
|
77
|
+
updateLanguageStatusItems(editor = this.editorAccess.editor) {
|
|
78
|
+
if (!editor) {
|
|
79
|
+
this.statusBar.removeElement(EditorLanguageStatusService_1.LANGUAGE_STATUS_ID);
|
|
80
|
+
this.updatePinnedItems();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const uri = new uri_1.default(editor.document.uri);
|
|
84
|
+
const items = Array.from(this.status.values())
|
|
85
|
+
.filter(item => (0, language_selector_1.score)(item.selector, uri.scheme, uri.path.toString(), editor.document.languageId, true))
|
|
86
|
+
.sort((left, right) => right.severity - left.severity);
|
|
87
|
+
if (!items.length) {
|
|
88
|
+
this.statusBar.removeElement(EditorLanguageStatusService_1.LANGUAGE_STATUS_ID);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const severityText = items[0].severity === severity_1.Severity.Info
|
|
92
|
+
? '$(bracket)'
|
|
93
|
+
: items[0].severity === severity_1.Severity.Warning
|
|
94
|
+
? '$(bracket-dot)'
|
|
95
|
+
: '$(bracket-error)';
|
|
96
|
+
this.statusBar.setElement(EditorLanguageStatusService_1.LANGUAGE_STATUS_ID, {
|
|
97
|
+
text: severityText,
|
|
98
|
+
alignment: browser_1.StatusBarAlignment.RIGHT,
|
|
99
|
+
priority: 2,
|
|
100
|
+
tooltip: this.createTooltip(items),
|
|
101
|
+
affinity: { id: EditorLanguageStatusService_1.LANGUAGE_MODE_ID, alignment: browser_1.StatusBarAlignment.LEFT, compact: true },
|
|
102
|
+
});
|
|
103
|
+
this.updatePinnedItems(items);
|
|
104
|
+
}
|
|
105
|
+
updatePinnedItems(items) {
|
|
106
|
+
const toRemoveFromStatusBar = new Set(this.pinnedCommands);
|
|
107
|
+
items === null || items === void 0 ? void 0 : items.forEach(item => {
|
|
108
|
+
if (toRemoveFromStatusBar.has(item.id)) {
|
|
109
|
+
toRemoveFromStatusBar.delete(item.id);
|
|
110
|
+
this.statusBar.setElement(item.id, this.toPinnedItem(item));
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
toRemoveFromStatusBar.forEach(id => this.statusBar.removeElement(id));
|
|
114
|
+
}
|
|
115
|
+
toPinnedItem(item) {
|
|
116
|
+
return {
|
|
117
|
+
text: item.label,
|
|
118
|
+
affinity: { id: EditorLanguageStatusService_1.LANGUAGE_MODE_ID, alignment: browser_1.StatusBarAlignment.RIGHT, compact: false },
|
|
119
|
+
alignment: browser_1.StatusBarAlignment.RIGHT,
|
|
120
|
+
onclick: item.command && (e => { var _a, _b; e.preventDefault(); this.commandRegistry.executeCommand(item.command.id, ...((_b = (_a = item.command) === null || _a === void 0 ? void 0 : _a.arguments) !== null && _b !== void 0 ? _b : [])); }),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
createTooltip(items) {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
const hoverContainer = document.createElement('div');
|
|
126
|
+
hoverContainer.classList.add('hover-row');
|
|
127
|
+
for (const item of items) {
|
|
128
|
+
const itemContainer = document.createElement('div');
|
|
129
|
+
itemContainer.classList.add('hover-language-status');
|
|
130
|
+
{
|
|
131
|
+
const severityContainer = document.createElement('div');
|
|
132
|
+
severityContainer.classList.add('severity', `sev${item.severity}`);
|
|
133
|
+
severityContainer.classList.toggle('show', item.severity === severity_1.Severity.Error || item.severity === severity_1.Severity.Warning);
|
|
134
|
+
{
|
|
135
|
+
const severityIcon = document.createElement('span');
|
|
136
|
+
severityIcon.className = this.getSeverityIconClasses(item.severity);
|
|
137
|
+
severityContainer.appendChild(severityIcon);
|
|
138
|
+
}
|
|
139
|
+
itemContainer.appendChild(severityContainer);
|
|
140
|
+
}
|
|
141
|
+
const textContainer = document.createElement('div');
|
|
142
|
+
textContainer.className = 'element';
|
|
143
|
+
const labelContainer = document.createElement('div');
|
|
144
|
+
labelContainer.className = 'left';
|
|
145
|
+
const label = document.createElement('span');
|
|
146
|
+
label.classList.add('label');
|
|
147
|
+
this.renderWithIcons(label, item.busy ? `$(sync~spin)\u00A0\u00A0${item.label}` : item.label);
|
|
148
|
+
labelContainer.appendChild(label);
|
|
149
|
+
const detail = document.createElement('span');
|
|
150
|
+
detail.classList.add('detail');
|
|
151
|
+
this.renderWithIcons(detail, item.detail);
|
|
152
|
+
labelContainer.appendChild(detail);
|
|
153
|
+
textContainer.appendChild(labelContainer);
|
|
154
|
+
const commandContainer = document.createElement('div');
|
|
155
|
+
commandContainer.classList.add('right');
|
|
156
|
+
if (item.command) {
|
|
157
|
+
const link = document.createElement('a');
|
|
158
|
+
link.classList.add('language-status-link');
|
|
159
|
+
link.href = new uri_1.default()
|
|
160
|
+
.withScheme('command')
|
|
161
|
+
.withPath(item.command.id)
|
|
162
|
+
.withQuery(item.command.arguments ? encodeURIComponent(JSON.stringify(item.command.arguments)) : '')
|
|
163
|
+
.toString(false);
|
|
164
|
+
link.onclick = e => { var _a, _b; e.preventDefault(); this.commandRegistry.executeCommand(item.command.id, ...((_b = (_a = item.command) === null || _a === void 0 ? void 0 : _a.arguments) !== null && _b !== void 0 ? _b : [])); };
|
|
165
|
+
link.textContent = (_a = item.command.title) !== null && _a !== void 0 ? _a : item.command.id;
|
|
166
|
+
link.title = (_b = item.command.tooltip) !== null && _b !== void 0 ? _b : '';
|
|
167
|
+
link.ariaRoleDescription = 'button';
|
|
168
|
+
link.ariaDisabled = 'false';
|
|
169
|
+
commandContainer.appendChild(link);
|
|
170
|
+
const pinContainer = document.createElement('div');
|
|
171
|
+
pinContainer.classList.add('language-status-action-bar');
|
|
172
|
+
const pin = document.createElement('a');
|
|
173
|
+
this.setPinProperties(pin, item.id);
|
|
174
|
+
pin.onclick = e => { e.preventDefault(); this.togglePinned(item); this.setPinProperties(pin, item.id); };
|
|
175
|
+
pinContainer.appendChild(pin);
|
|
176
|
+
commandContainer.appendChild(pinContainer);
|
|
177
|
+
}
|
|
178
|
+
textContainer.appendChild(commandContainer);
|
|
179
|
+
itemContainer.append(textContainer);
|
|
180
|
+
hoverContainer.appendChild(itemContainer);
|
|
181
|
+
}
|
|
182
|
+
return hoverContainer;
|
|
183
|
+
}
|
|
184
|
+
setPinProperties(pin, id) {
|
|
185
|
+
pin.className = this.pinnedCommands.has(id) ? (0, browser_1.codicon)('pinned', true) : (0, browser_1.codicon)('pin', true);
|
|
186
|
+
pin.ariaRoleDescription = 'button';
|
|
187
|
+
const pinText = this.pinnedCommands.has(id)
|
|
188
|
+
? core_1.nls.localizeByDefault('Remove from Status Bar')
|
|
189
|
+
: core_1.nls.localizeByDefault('Add to Status Bar');
|
|
190
|
+
pin.ariaLabel = pinText;
|
|
191
|
+
pin.title = pinText;
|
|
192
|
+
}
|
|
193
|
+
togglePinned(item) {
|
|
194
|
+
if (this.pinnedCommands.has(item.id)) {
|
|
195
|
+
this.pinnedCommands.delete(item.id);
|
|
196
|
+
this.statusBar.removeElement(item.id);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
this.pinnedCommands.add(item.id);
|
|
200
|
+
this.statusBar.setElement(item.id, this.toPinnedItem(item));
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
getSeverityIconClasses(severity) {
|
|
204
|
+
switch (severity) {
|
|
205
|
+
case severity_1.Severity.Error: return (0, browser_1.codicon)('error');
|
|
206
|
+
case severity_1.Severity.Warning: return (0, browser_1.codicon)('info');
|
|
207
|
+
default: return (0, browser_1.codicon)('check');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
renderWithIcons(host, text) {
|
|
211
|
+
if (text) {
|
|
212
|
+
for (const chunk of this.labelParser.parse(text)) {
|
|
213
|
+
if (typeof chunk === 'string') {
|
|
214
|
+
host.append(chunk);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const iconSpan = document.createElement('span');
|
|
218
|
+
const className = (0, browser_1.codicon)(chunk.name) + (chunk.animation ? ` fa-${chunk.animation}` : '');
|
|
219
|
+
iconSpan.className = className;
|
|
220
|
+
host.append(iconSpan);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
EditorLanguageStatusService.LANGUAGE_MODE_ID = 'editor-status-language';
|
|
227
|
+
EditorLanguageStatusService.LANGUAGE_STATUS_ID = 'editor-language-status-items';
|
|
228
|
+
__decorate([
|
|
229
|
+
(0, inversify_1.inject)(browser_1.StatusBar),
|
|
230
|
+
__metadata("design:type", Object)
|
|
231
|
+
], EditorLanguageStatusService.prototype, "statusBar", void 0);
|
|
232
|
+
__decorate([
|
|
233
|
+
(0, inversify_1.inject)(language_service_1.LanguageService),
|
|
234
|
+
__metadata("design:type", language_service_1.LanguageService)
|
|
235
|
+
], EditorLanguageStatusService.prototype, "languages", void 0);
|
|
236
|
+
__decorate([
|
|
237
|
+
(0, inversify_1.inject)(editor_manager_1.CurrentEditorAccess),
|
|
238
|
+
__metadata("design:type", editor_manager_1.CurrentEditorAccess)
|
|
239
|
+
], EditorLanguageStatusService.prototype, "editorAccess", void 0);
|
|
240
|
+
__decorate([
|
|
241
|
+
(0, inversify_1.inject)(core_1.CommandRegistry),
|
|
242
|
+
__metadata("design:type", core_1.CommandRegistry)
|
|
243
|
+
], EditorLanguageStatusService.prototype, "commandRegistry", void 0);
|
|
244
|
+
__decorate([
|
|
245
|
+
(0, inversify_1.inject)(label_parser_1.LabelParser),
|
|
246
|
+
__metadata("design:type", label_parser_1.LabelParser)
|
|
247
|
+
], EditorLanguageStatusService.prototype, "labelParser", void 0);
|
|
248
|
+
EditorLanguageStatusService = EditorLanguageStatusService_1 = __decorate([
|
|
249
|
+
(0, inversify_1.injectable)()
|
|
250
|
+
], EditorLanguageStatusService);
|
|
251
|
+
exports.EditorLanguageStatusService = EditorLanguageStatusService;
|
|
252
252
|
//# sourceMappingURL=editor-language-status-service.js.map
|