@codingame/monaco-vscode-api 4.5.0-improve-code-splitting.1 → 4.5.0

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 CHANGED
@@ -16,14 +16,6 @@ npm install -D @types/vscode
16
16
 
17
17
  ## Troubleshooting
18
18
 
19
- ### `process` node builtin
20
-
21
- Since v1.86, VSCode detects its running environment by checking if a global variable `process` exists.
22
- For backward compatibility reasons or to be able to use node libraries in the browser, bundlers can be configured to inject a polyfill for it.
23
- Doing so may create unexpected behaviors and crashes.
24
-
25
- Make sure `typeof process === 'undefined'` returns true when using this library.
26
-
27
19
  ### If you use Webpack
28
20
 
29
21
  Starting from v2, [monaco-editor-webpack-plugin](https://www.npmjs.com/package/monaco-editor-webpack-plugin) can't be used
@@ -119,6 +111,8 @@ Additionally, several packages that include the VSCode version of some services
119
111
 
120
112
  - **Base** (included by default): `@codingame/monaco-vscode-base-service-override`
121
113
  - Contains some general-use services that are mandatory to most of the other features
114
+ - **Monarch**:
115
+ - When textmate and theme service overrides are not used, it allows to restore some standalone features (Token inspection and toggle high contrast commands)
122
116
  - **Host** (included by default): `@codingame/monaco-vscode-host-service-override`
123
117
  - Interaction with the host/browser (shutdown veto, focus/active management, window opening, fullscreen...)
124
118
  - **Extensions** (included by default): `@codingame/monaco-vscode-extensions-service-override`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-api",
3
- "version": "4.5.0-improve-code-splitting.1",
3
+ "version": "4.5.0",
4
4
  "description": "VSCode public API plugged on the monaco editor",
5
5
  "keywords": [],
6
6
  "author": {
@@ -97,12 +97,12 @@
97
97
  }
98
98
  },
99
99
  "dependencies": {
100
- "@codingame/monaco-vscode-extensions-service-override": "4.5.0-improve-code-splitting.1",
101
- "@codingame/monaco-vscode-files-service-override": "4.5.0-improve-code-splitting.1",
102
- "@codingame/monaco-vscode-quickaccess-service-override": "4.5.0-improve-code-splitting.1",
103
- "@codingame/monaco-vscode-environment-service-override": "4.5.0-improve-code-splitting.1",
104
- "@codingame/monaco-vscode-layout-service-override": "4.5.0-improve-code-splitting.1",
105
- "@codingame/monaco-vscode-host-service-override": "4.5.0-improve-code-splitting.1",
106
- "@codingame/monaco-vscode-base-service-override": "4.5.0-improve-code-splitting.1"
100
+ "@codingame/monaco-vscode-extensions-service-override": "4.5.0",
101
+ "@codingame/monaco-vscode-files-service-override": "4.5.0",
102
+ "@codingame/monaco-vscode-quickaccess-service-override": "4.5.0",
103
+ "@codingame/monaco-vscode-environment-service-override": "4.5.0",
104
+ "@codingame/monaco-vscode-layout-service-override": "4.5.0",
105
+ "@codingame/monaco-vscode-host-service-override": "4.5.0",
106
+ "@codingame/monaco-vscode-base-service-override": "4.5.0"
107
107
  }
108
108
  }
package/services.js CHANGED
@@ -7,7 +7,6 @@ import './vscode/src/vs/workbench/contrib/codeEditor/browser/workbenchReferenceS
7
7
  import './vscode/src/vs/workbench/contrib/codeEditor/browser/menuPreventer.js';
8
8
  import './vscode/src/vs/workbench/contrib/codeEditor/browser/diffEditorHelper.js';
9
9
  import './vscode/src/vs/workbench/contrib/codeEditor/browser/largeFileOptimizations.js';
10
- import './vscode/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.js';
11
10
  import './vscode/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.js';
12
11
  import './vscode/src/vs/workbench/contrib/codeEditor/browser/toggleMinimap.js';
13
12
  import './vscode/src/vs/workbench/contrib/codeEditor/browser/toggleMultiCursorModifier.js';
@@ -234,11 +234,7 @@ class SimpleWorkerClient extends Disposable {
234
234
  }));
235
235
  this._protocol.setWorkerId(this._worker.getId());
236
236
  let loaderConfiguration = null;
237
- const globalRequire = globalThis.require;
238
- if (typeof globalRequire !== 'undefined' && typeof globalRequire.getConfig === 'function') {
239
- loaderConfiguration = globalRequire.getConfig();
240
- }
241
- else if (typeof globalThis.requirejs !== 'undefined') {
237
+ if (typeof globalThis.requirejs !== 'undefined') {
242
238
  loaderConfiguration = globalThis.requirejs.s.contexts._.config;
243
239
  }
244
240
  const hostMethods = getAllMethodNames(host);
@@ -389,7 +385,7 @@ class SimpleWorkerServer {
389
385
  globalThis.require.config(loaderConfig);
390
386
  }
391
387
  return ( new Promise((resolve, reject) => {
392
- const req = globalThis.require;
388
+ const req = undefined;
393
389
  req([moduleId], (module) => {
394
390
  this._requestHandler = module.create(hostProxy);
395
391
  if (!this._requestHandler) {
@@ -1,4 +1,4 @@
1
- import { EncodedTokenizationResult, TokenizationResult, Token } from '../languages.js';
1
+ import { TokenizationResult, Token, EncodedTokenizationResult } from '../languages.js';
2
2
  const NullState = new class {
3
3
  clone() {
4
4
  return this;
@@ -127,6 +127,14 @@ var AccessibilityHelpNLS;
127
127
  "The command: Start inline chat is not currentlyt riggerable by a keybinding."
128
128
  ));
129
129
  })(AccessibilityHelpNLS || (AccessibilityHelpNLS = {})));
130
+ var InspectTokensNLS;
131
+ ( (function(InspectTokensNLS) {
132
+ InspectTokensNLS.inspectTokensAction = ( localizeWithPath(
133
+ 'vs/editor/common/standaloneStrings',
134
+ 'inspectTokens',
135
+ "Developer: Inspect Tokens"
136
+ ));
137
+ })(InspectTokensNLS || (InspectTokensNLS = {})));
130
138
  var StandaloneCodeEditorNLS;
131
139
  ( (function(StandaloneCodeEditorNLS) {
132
140
  StandaloneCodeEditorNLS.editorViewAccessibleLabel = ( localizeWithPath(
@@ -140,6 +148,14 @@ var StandaloneCodeEditorNLS;
140
148
  "Press Alt+F1 for Accessibility Options."
141
149
  ));
142
150
  })(StandaloneCodeEditorNLS || (StandaloneCodeEditorNLS = {})));
151
+ var ToggleHighContrastNLS;
152
+ ( (function(ToggleHighContrastNLS) {
153
+ ToggleHighContrastNLS.toggleHighContrast = ( localizeWithPath(
154
+ 'vs/editor/common/standaloneStrings',
155
+ 'toggleHighContrast',
156
+ "Toggle High Contrast Theme"
157
+ ));
158
+ })(ToggleHighContrastNLS || (ToggleHighContrastNLS = {})));
143
159
  var StandaloneServicesNLS;
144
160
  ( (function(StandaloneServicesNLS) {
145
161
  StandaloneServicesNLS.bulkEditServiceSummary = ( localizeWithPath(
@@ -148,4 +164,4 @@ var StandaloneServicesNLS;
148
164
  "Made {0} edits in {1} files"
149
165
  ));
150
166
  })(StandaloneServicesNLS || (StandaloneServicesNLS = {})));
151
- export { AccessibilityHelpNLS, StandaloneCodeEditorNLS, StandaloneServicesNLS };
167
+ export { AccessibilityHelpNLS, InspectTokensNLS, StandaloneCodeEditorNLS, StandaloneServicesNLS, ToggleHighContrastNLS };
@@ -1,4 +0,0 @@
1
- import n from '../../../../../../../../external/rollup-plugin-styles/dist/runtime/inject-css.js';
2
- var css = ".token-inspect-widget{border:1px solid var(--vscode-editorHoverWidget-border);padding:10px;user-select:text;-webkit-user-select:text;z-index:50}.hc-black .tokens-inspect-widget,.hc-light .tokens-inspect-widget{border-width:2px}.monaco-editor .token-inspect-widget{background-color:var(--vscode-editorHoverWidget-background)}.monaco-editor .token-inspect-widget .tiw-metadata-separator{background-color:var(--vscode-editorHoverWidget-border)}.tiw-token{font-family:var(--monaco-monospace-font)}.tiw-metadata-separator{border:0;height:1px}.tiw-token-length{float:right;font-size:60%;font-weight:400}.tiw-metadata-table{width:100%}.tiw-metadata-value{font-family:var(--monaco-monospace-font);word-break:break-word}.tiw-metadata-values{list-style:none;margin-right:-10px;max-height:300px;overflow-y:auto;padding-left:0}.tiw-metadata-values>.tiw-metadata-value{margin-right:10px}.tiw-metadata-key{min-width:150px;padding-right:10px;vertical-align:top;white-space:nowrap;width:1px}.tiw-metadata-semantic{font-style:italic}.tiw-metadata-scopes{line-height:normal}.tiw-theme-selector{font-family:var(--monaco-monospace-font)}";
3
- n(css,{});
4
- export { css, css as default };
@@ -1,503 +0,0 @@
1
- import { __decorate, __param } from '../../../../../../../../external/tslib/tslib.es6.js';
2
- import './inspectEditorTokens.css.js';
3
- import { localizeWithPath } from '../../../../../nls.js';
4
- import { clearNode, reset, append, $ as $$1 } from '../../../../../base/browser/dom.js';
5
- import { Color } from '../../../../../base/common/color.js';
6
- import { Disposable } from '../../../../../base/common/lifecycle.js';
7
- import { registerEditorContribution, registerEditorAction, EditorAction } from '../../../../../editor/browser/editorExtensions.js';
8
- import { Range } from '../../../../../editor/common/core/range.js';
9
- import { TokenMetadata } from '../../../../../editor/common/encodedTokenAttributes.js';
10
- import { ILanguageService } from '../../../../../editor/common/languages/language.js';
11
- import { INotificationService } from '../../../../../platform/notification/common/notification.service.js';
12
- import { findMatchingThemeRule } from '../../../../services/textMate/common/TMHelper.js';
13
- import { ITextMateTokenizationService } from '../../../../services/textMate/browser/textMateTokenizationFeature.service.js';
14
- import { IWorkbenchThemeService } from '../../../../services/themes/common/workbenchThemeService.service.js';
15
- import { CancellationTokenSource } from '../../../../../base/common/cancellation.js';
16
- import { SemanticTokenRule } from '../../../../../platform/theme/common/tokenClassificationRegistry.js';
17
- import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.service.js';
18
- import { SEMANTIC_HIGHLIGHTING_SETTING_ID } from '../../../../../editor/contrib/semanticTokens/common/semanticTokensConfig.js';
19
- import { Schemas } from '../../../../../base/common/network.js';
20
- import { ILanguageFeaturesService } from '../../../../../editor/common/services/languageFeatures.js';
21
- var InspectEditorTokensController_1;
22
- const $ = $$1;
23
- let InspectEditorTokensController = class InspectEditorTokensController extends Disposable {
24
- static { InspectEditorTokensController_1 = this; }
25
- static { this.ID = 'editor.contrib.inspectEditorTokens'; }
26
- static get(editor) {
27
- return editor.getContribution(InspectEditorTokensController_1.ID);
28
- }
29
- constructor(editor, textMateService, languageService, themeService, notificationService, configurationService, languageFeaturesService) {
30
- super();
31
- this._editor = editor;
32
- this._textMateService = textMateService;
33
- this._themeService = themeService;
34
- this._languageService = languageService;
35
- this._notificationService = notificationService;
36
- this._configurationService = configurationService;
37
- this._languageFeaturesService = languageFeaturesService;
38
- this._widget = null;
39
- this._register(this._editor.onDidChangeModel((e) => this.stop()));
40
- this._register(this._editor.onDidChangeModelLanguage((e) => this.stop()));
41
- this._register(this._editor.onKeyUp((e) => e.keyCode === 9 && this.stop()));
42
- }
43
- dispose() {
44
- this.stop();
45
- super.dispose();
46
- }
47
- launch() {
48
- if (this._widget) {
49
- return;
50
- }
51
- if (!this._editor.hasModel()) {
52
- return;
53
- }
54
- if (this._editor.getModel().uri.scheme === Schemas.vscodeNotebookCell) {
55
- return;
56
- }
57
- this._widget = ( new InspectEditorTokensWidget(
58
- this._editor,
59
- this._textMateService,
60
- this._languageService,
61
- this._themeService,
62
- this._notificationService,
63
- this._configurationService,
64
- this._languageFeaturesService
65
- ));
66
- }
67
- stop() {
68
- if (this._widget) {
69
- this._widget.dispose();
70
- this._widget = null;
71
- }
72
- }
73
- toggle() {
74
- if (!this._widget) {
75
- this.launch();
76
- }
77
- else {
78
- this.stop();
79
- }
80
- }
81
- };
82
- InspectEditorTokensController = InspectEditorTokensController_1 = ( __decorate([
83
- ( __param(1, ITextMateTokenizationService)),
84
- ( __param(2, ILanguageService)),
85
- ( __param(3, IWorkbenchThemeService)),
86
- ( __param(4, INotificationService)),
87
- ( __param(5, IConfigurationService)),
88
- ( __param(6, ILanguageFeaturesService))
89
- ], InspectEditorTokensController));
90
- class InspectEditorTokens extends EditorAction {
91
- constructor() {
92
- super({
93
- id: 'editor.action.inspectTMScopes',
94
- label: ( localizeWithPath(
95
- 'vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens',
96
- 'inspectEditorTokens',
97
- "Developer: Inspect Editor Tokens and Scopes"
98
- )),
99
- alias: 'Developer: Inspect Editor Tokens and Scopes',
100
- precondition: undefined
101
- });
102
- }
103
- run(accessor, editor) {
104
- const controller = InspectEditorTokensController.get(editor);
105
- controller?.toggle();
106
- }
107
- }
108
- function renderTokenText(tokenText) {
109
- if (tokenText.length > 40) {
110
- tokenText = tokenText.substr(0, 20) + '…' + tokenText.substr(tokenText.length - 20);
111
- }
112
- let result = '';
113
- for (let charIndex = 0, len = tokenText.length; charIndex < len; charIndex++) {
114
- const charCode = tokenText.charCodeAt(charIndex);
115
- switch (charCode) {
116
- case 9 :
117
- result += '\u2192';
118
- break;
119
- case 32 :
120
- result += '\u00B7';
121
- break;
122
- default:
123
- result += String.fromCharCode(charCode);
124
- }
125
- }
126
- return result;
127
- }
128
- class InspectEditorTokensWidget extends Disposable {
129
- static { this._ID = 'editor.contrib.inspectEditorTokensWidget'; }
130
- constructor(editor, textMateService, languageService, themeService, notificationService, configurationService, languageFeaturesService) {
131
- super();
132
- this.allowEditorOverflow = true;
133
- this._isDisposed = false;
134
- this._editor = editor;
135
- this._languageService = languageService;
136
- this._themeService = themeService;
137
- this._textMateService = textMateService;
138
- this._notificationService = notificationService;
139
- this._configurationService = configurationService;
140
- this._languageFeaturesService = languageFeaturesService;
141
- this._model = this._editor.getModel();
142
- this._domNode = document.createElement('div');
143
- this._domNode.className = 'token-inspect-widget';
144
- this._currentRequestCancellationTokenSource = ( new CancellationTokenSource());
145
- this._beginCompute(this._editor.getPosition());
146
- this._register(this._editor.onDidChangeCursorPosition((e) => this._beginCompute(this._editor.getPosition())));
147
- this._register(themeService.onDidColorThemeChange(_ => this._beginCompute(this._editor.getPosition())));
148
- this._register(configurationService.onDidChangeConfiguration(e => e.affectsConfiguration('editor.semanticHighlighting.enabled') && this._beginCompute(this._editor.getPosition())));
149
- this._editor.addContentWidget(this);
150
- }
151
- dispose() {
152
- this._isDisposed = true;
153
- this._editor.removeContentWidget(this);
154
- this._currentRequestCancellationTokenSource.cancel();
155
- super.dispose();
156
- }
157
- getId() {
158
- return InspectEditorTokensWidget._ID;
159
- }
160
- _beginCompute(position) {
161
- const grammar = this._textMateService.createTokenizer(this._model.getLanguageId());
162
- const semanticTokens = this._computeSemanticTokens(position);
163
- clearNode(this._domNode);
164
- this._domNode.appendChild(document.createTextNode(( localizeWithPath(
165
- 'vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens',
166
- 'inspectTMScopesWidget.loading',
167
- "Loading..."
168
- ))));
169
- Promise.all([grammar, semanticTokens]).then(([grammar, semanticTokens]) => {
170
- if (this._isDisposed) {
171
- return;
172
- }
173
- this._compute(grammar, semanticTokens, position);
174
- this._domNode.style.maxWidth = `${Math.max(this._editor.getLayoutInfo().width * 0.66, 500)}px`;
175
- this._editor.layoutContentWidget(this);
176
- }, (err) => {
177
- this._notificationService.warn(err);
178
- setTimeout(() => {
179
- InspectEditorTokensController.get(this._editor)?.stop();
180
- });
181
- });
182
- }
183
- _isSemanticColoringEnabled() {
184
- const setting = this._configurationService.getValue(SEMANTIC_HIGHLIGHTING_SETTING_ID, { overrideIdentifier: this._model.getLanguageId(), resource: this._model.uri })?.enabled;
185
- if (typeof setting === 'boolean') {
186
- return setting;
187
- }
188
- return this._themeService.getColorTheme().semanticHighlighting;
189
- }
190
- _compute(grammar, semanticTokens, position) {
191
- const textMateTokenInfo = grammar && this._getTokensAtPosition(grammar, position);
192
- const semanticTokenInfo = semanticTokens && this._getSemanticTokenAtPosition(semanticTokens, position);
193
- if (!textMateTokenInfo && !semanticTokenInfo) {
194
- reset(this._domNode, 'No grammar or semantic tokens available.');
195
- return;
196
- }
197
- const tmMetadata = textMateTokenInfo?.metadata;
198
- const semMetadata = semanticTokenInfo?.metadata;
199
- const semTokenText = semanticTokenInfo && renderTokenText(this._model.getValueInRange(semanticTokenInfo.range));
200
- const tmTokenText = textMateTokenInfo && renderTokenText(this._model.getLineContent(position.lineNumber).substring(textMateTokenInfo.token.startIndex, textMateTokenInfo.token.endIndex));
201
- const tokenText = semTokenText || tmTokenText || '';
202
- reset(this._domNode, $('h2.tiw-token', undefined, tokenText, $('span.tiw-token-length', undefined, `${tokenText.length} ${tokenText.length === 1 ? 'char' : 'chars'}`)));
203
- append(this._domNode, $('hr.tiw-metadata-separator', { 'style': 'clear:both' }));
204
- append(this._domNode, $('table.tiw-metadata-table', undefined, $('tbody', undefined, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'language'), $('td.tiw-metadata-value', undefined, tmMetadata?.languageId || '')), $('tr', undefined, $('td.tiw-metadata-key', undefined, 'standard token type'), $('td.tiw-metadata-value', undefined, this._tokenTypeToString(tmMetadata?.tokenType || 0 ))), ...this._formatMetadata(semMetadata, tmMetadata))));
205
- if (semanticTokenInfo) {
206
- append(this._domNode, $('hr.tiw-metadata-separator'));
207
- const table = append(this._domNode, $('table.tiw-metadata-table', undefined));
208
- const tbody = append(table, $('tbody', undefined, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'semantic token type'), $('td.tiw-metadata-value', undefined, semanticTokenInfo.type))));
209
- if (semanticTokenInfo.modifiers.length) {
210
- append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'modifiers'), $('td.tiw-metadata-value', undefined, semanticTokenInfo.modifiers.join(' '))));
211
- }
212
- if (semanticTokenInfo.metadata) {
213
- const properties = ['foreground', 'bold', 'italic', 'underline', 'strikethrough'];
214
- const propertiesByDefValue = {};
215
- const allDefValues = ( new Array());
216
- for (const property of properties) {
217
- if (semanticTokenInfo.metadata[property] !== undefined) {
218
- const definition = semanticTokenInfo.definitions[property];
219
- const defValue = this._renderTokenStyleDefinition(definition, property);
220
- const defValueStr = ( defValue.map(el => el instanceof HTMLElement ? el.outerHTML : el)).join();
221
- let properties = propertiesByDefValue[defValueStr];
222
- if (!properties) {
223
- propertiesByDefValue[defValueStr] = properties = [];
224
- allDefValues.push([defValue, defValueStr]);
225
- }
226
- properties.push(property);
227
- }
228
- }
229
- for (const [defValue, defValueStr] of allDefValues) {
230
- append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, propertiesByDefValue[defValueStr].join(', ')), $('td.tiw-metadata-value', undefined, ...defValue)));
231
- }
232
- }
233
- }
234
- if (textMateTokenInfo) {
235
- const theme = this._themeService.getColorTheme();
236
- append(this._domNode, $('hr.tiw-metadata-separator'));
237
- const table = append(this._domNode, $('table.tiw-metadata-table'));
238
- const tbody = append(table, $('tbody'));
239
- if (tmTokenText && tmTokenText !== tokenText) {
240
- append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'textmate token'), $('td.tiw-metadata-value', undefined, `${tmTokenText} (${tmTokenText.length})`)));
241
- }
242
- const scopes = ( new Array());
243
- for (let i = textMateTokenInfo.token.scopes.length - 1; i >= 0; i--) {
244
- scopes.push(textMateTokenInfo.token.scopes[i]);
245
- if (i > 0) {
246
- scopes.push($('br'));
247
- }
248
- }
249
- append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'textmate scopes'), $('td.tiw-metadata-value.tiw-metadata-scopes', undefined, ...scopes)));
250
- const matchingRule = findMatchingThemeRule(theme, textMateTokenInfo.token.scopes, false);
251
- const semForeground = semanticTokenInfo?.metadata?.foreground;
252
- if (matchingRule) {
253
- if (semForeground !== textMateTokenInfo.metadata.foreground) {
254
- let defValue = $('code.tiw-theme-selector', undefined, matchingRule.rawSelector, $('br'), JSON.stringify(matchingRule.settings, null, '\t'));
255
- if (semForeground) {
256
- defValue = $('s', undefined, defValue);
257
- }
258
- append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'foreground'), $('td.tiw-metadata-value', undefined, defValue)));
259
- }
260
- }
261
- else if (!semForeground) {
262
- append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'foreground'), $('td.tiw-metadata-value', undefined, 'No theme selector')));
263
- }
264
- }
265
- }
266
- _formatMetadata(semantic, tm) {
267
- const elements = ( new Array());
268
- function render(property) {
269
- const value = semantic?.[property] || tm?.[property];
270
- if (value !== undefined) {
271
- const semanticStyle = semantic?.[property] ? 'tiw-metadata-semantic' : '';
272
- elements.push($('tr', undefined, $('td.tiw-metadata-key', undefined, property), $(`td.tiw-metadata-value.${semanticStyle}`, undefined, value)));
273
- }
274
- return value;
275
- }
276
- const foreground = render('foreground');
277
- const background = render('background');
278
- if (foreground && background) {
279
- const backgroundColor = ( Color.fromHex(background)), foregroundColor = ( Color.fromHex(foreground));
280
- if (backgroundColor.isOpaque()) {
281
- elements.push($('tr', undefined, $('td.tiw-metadata-key', undefined, 'contrast ratio'), $('td.tiw-metadata-value', undefined, backgroundColor.getContrastRatio(foregroundColor.makeOpaque(backgroundColor)).toFixed(2))));
282
- }
283
- else {
284
- elements.push($('tr', undefined, $('td.tiw-metadata-key', undefined, 'Contrast ratio cannot be precise for background colors that use transparency'), $('td.tiw-metadata-value')));
285
- }
286
- }
287
- const fontStyleLabels = ( new Array());
288
- function addStyle(key) {
289
- let label;
290
- if (semantic && semantic[key]) {
291
- label = $('span.tiw-metadata-semantic', undefined, key);
292
- }
293
- else if (tm && tm[key]) {
294
- label = key;
295
- }
296
- if (label) {
297
- if (fontStyleLabels.length) {
298
- fontStyleLabels.push(' ');
299
- }
300
- fontStyleLabels.push(label);
301
- }
302
- }
303
- addStyle('bold');
304
- addStyle('italic');
305
- addStyle('underline');
306
- addStyle('strikethrough');
307
- if (fontStyleLabels.length) {
308
- elements.push($('tr', undefined, $('td.tiw-metadata-key', undefined, 'font style'), $('td.tiw-metadata-value', undefined, ...fontStyleLabels)));
309
- }
310
- return elements;
311
- }
312
- _decodeMetadata(metadata) {
313
- const colorMap = this._themeService.getColorTheme().tokenColorMap;
314
- const languageId = TokenMetadata.getLanguageId(metadata);
315
- const tokenType = TokenMetadata.getTokenType(metadata);
316
- const fontStyle = TokenMetadata.getFontStyle(metadata);
317
- const foreground = TokenMetadata.getForeground(metadata);
318
- const background = TokenMetadata.getBackground(metadata);
319
- return {
320
- languageId: this._languageService.languageIdCodec.decodeLanguageId(languageId),
321
- tokenType: tokenType,
322
- bold: ((fontStyle & 2) ) ? true : undefined,
323
- italic: ((fontStyle & 1) ) ? true : undefined,
324
- underline: ((fontStyle & 4) ) ? true : undefined,
325
- strikethrough: ((fontStyle & 8) ) ? true : undefined,
326
- foreground: colorMap[foreground],
327
- background: colorMap[background]
328
- };
329
- }
330
- _tokenTypeToString(tokenType) {
331
- switch (tokenType) {
332
- case 0 : return 'Other';
333
- case 1 : return 'Comment';
334
- case 2 : return 'String';
335
- case 3 : return 'RegEx';
336
- default: return '??';
337
- }
338
- }
339
- _getTokensAtPosition(grammar, position) {
340
- const lineNumber = position.lineNumber;
341
- const stateBeforeLine = this._getStateBeforeLine(grammar, lineNumber);
342
- const tokenizationResult1 = grammar.tokenizeLine(this._model.getLineContent(lineNumber), stateBeforeLine);
343
- const tokenizationResult2 = grammar.tokenizeLine2(this._model.getLineContent(lineNumber), stateBeforeLine);
344
- let token1Index = 0;
345
- for (let i = tokenizationResult1.tokens.length - 1; i >= 0; i--) {
346
- const t = tokenizationResult1.tokens[i];
347
- if (position.column - 1 >= t.startIndex) {
348
- token1Index = i;
349
- break;
350
- }
351
- }
352
- let token2Index = 0;
353
- for (let i = (tokenizationResult2.tokens.length >>> 1); i >= 0; i--) {
354
- if (position.column - 1 >= tokenizationResult2.tokens[(i << 1)]) {
355
- token2Index = i;
356
- break;
357
- }
358
- }
359
- return {
360
- token: tokenizationResult1.tokens[token1Index],
361
- metadata: this._decodeMetadata(tokenizationResult2.tokens[(token2Index << 1) + 1])
362
- };
363
- }
364
- _getStateBeforeLine(grammar, lineNumber) {
365
- let state = null;
366
- for (let i = 1; i < lineNumber; i++) {
367
- const tokenizationResult = grammar.tokenizeLine(this._model.getLineContent(i), state);
368
- state = tokenizationResult.ruleStack;
369
- }
370
- return state;
371
- }
372
- isSemanticTokens(token) {
373
- return token && token.data;
374
- }
375
- async _computeSemanticTokens(position) {
376
- if (!this._isSemanticColoringEnabled()) {
377
- return null;
378
- }
379
- const tokenProviders = this._languageFeaturesService.documentSemanticTokensProvider.ordered(this._model);
380
- if (tokenProviders.length) {
381
- const provider = tokenProviders[0];
382
- const tokens = await Promise.resolve(provider.provideDocumentSemanticTokens(this._model, null, this._currentRequestCancellationTokenSource.token));
383
- if (this.isSemanticTokens(tokens)) {
384
- return { tokens, legend: provider.getLegend() };
385
- }
386
- }
387
- const rangeTokenProviders = this._languageFeaturesService.documentRangeSemanticTokensProvider.ordered(this._model);
388
- if (rangeTokenProviders.length) {
389
- const provider = rangeTokenProviders[0];
390
- const lineNumber = position.lineNumber;
391
- const range = ( new Range(lineNumber, 1, lineNumber, this._model.getLineMaxColumn(lineNumber)));
392
- const tokens = await Promise.resolve(provider.provideDocumentRangeSemanticTokens(this._model, range, this._currentRequestCancellationTokenSource.token));
393
- if (this.isSemanticTokens(tokens)) {
394
- return { tokens, legend: provider.getLegend() };
395
- }
396
- }
397
- return null;
398
- }
399
- _getSemanticTokenAtPosition(semanticTokens, pos) {
400
- const tokenData = semanticTokens.tokens.data;
401
- const defaultLanguage = this._model.getLanguageId();
402
- let lastLine = 0;
403
- let lastCharacter = 0;
404
- const posLine = pos.lineNumber - 1, posCharacter = pos.column - 1;
405
- for (let i = 0; i < tokenData.length; i += 5) {
406
- const lineDelta = tokenData[i], charDelta = tokenData[i + 1], len = tokenData[i + 2], typeIdx = tokenData[i + 3], modSet = tokenData[i + 4];
407
- const line = lastLine + lineDelta;
408
- const character = lineDelta === 0 ? lastCharacter + charDelta : charDelta;
409
- if (posLine === line && character <= posCharacter && posCharacter < character + len) {
410
- const type = semanticTokens.legend.tokenTypes[typeIdx] || 'not in legend (ignored)';
411
- const modifiers = [];
412
- let modifierSet = modSet;
413
- for (let modifierIndex = 0; modifierSet > 0 && modifierIndex < semanticTokens.legend.tokenModifiers.length; modifierIndex++) {
414
- if (modifierSet & 1) {
415
- modifiers.push(semanticTokens.legend.tokenModifiers[modifierIndex]);
416
- }
417
- modifierSet = modifierSet >> 1;
418
- }
419
- if (modifierSet > 0) {
420
- modifiers.push('not in legend (ignored)');
421
- }
422
- const range = ( new Range(line + 1, character + 1, line + 1, character + 1 + len));
423
- const definitions = {};
424
- const colorMap = this._themeService.getColorTheme().tokenColorMap;
425
- const theme = this._themeService.getColorTheme();
426
- const tokenStyle = theme.getTokenStyleMetadata(type, modifiers, defaultLanguage, true, definitions);
427
- let metadata = undefined;
428
- if (tokenStyle) {
429
- metadata = {
430
- languageId: undefined,
431
- tokenType: 0 ,
432
- bold: tokenStyle?.bold,
433
- italic: tokenStyle?.italic,
434
- underline: tokenStyle?.underline,
435
- strikethrough: tokenStyle?.strikethrough,
436
- foreground: colorMap[tokenStyle?.foreground || 0 ],
437
- background: undefined
438
- };
439
- }
440
- return { type, modifiers, range, metadata, definitions };
441
- }
442
- lastLine = line;
443
- lastCharacter = character;
444
- }
445
- return null;
446
- }
447
- _renderTokenStyleDefinition(definition, property) {
448
- const elements = ( new Array());
449
- if (definition === undefined) {
450
- return elements;
451
- }
452
- const theme = this._themeService.getColorTheme();
453
- if (Array.isArray(definition)) {
454
- const scopesDefinition = {};
455
- theme.resolveScopes(definition, scopesDefinition);
456
- const matchingRule = scopesDefinition[property];
457
- if (matchingRule && scopesDefinition.scope) {
458
- const scopes = $('ul.tiw-metadata-values');
459
- const strScopes = Array.isArray(matchingRule.scope) ? matchingRule.scope : [String(matchingRule.scope)];
460
- for (const strScope of strScopes) {
461
- scopes.appendChild($('li.tiw-metadata-value.tiw-metadata-scopes', undefined, strScope));
462
- }
463
- elements.push(scopesDefinition.scope.join(' '), scopes, $('code.tiw-theme-selector', undefined, JSON.stringify(matchingRule.settings, null, '\t')));
464
- return elements;
465
- }
466
- return elements;
467
- }
468
- else if (SemanticTokenRule.is(definition)) {
469
- const scope = theme.getTokenStylingRuleScope(definition);
470
- if (scope === 'setting') {
471
- elements.push(`User settings: ${definition.selector.id} - ${this._renderStyleProperty(definition.style, property)}`);
472
- return elements;
473
- }
474
- else if (scope === 'theme') {
475
- elements.push(`Color theme: ${definition.selector.id} - ${this._renderStyleProperty(definition.style, property)}`);
476
- return elements;
477
- }
478
- return elements;
479
- }
480
- else {
481
- const style = theme.resolveTokenStyleValue(definition);
482
- elements.push(`Default: ${style ? this._renderStyleProperty(style, property) : ''}`);
483
- return elements;
484
- }
485
- }
486
- _renderStyleProperty(style, property) {
487
- switch (property) {
488
- case 'foreground': return style.foreground ? Color.Format.CSS.formatHexA(style.foreground, true) : '';
489
- default: return style[property] !== undefined ? String(style[property]) : '';
490
- }
491
- }
492
- getDomNode() {
493
- return this._domNode;
494
- }
495
- getPosition() {
496
- return {
497
- position: this._editor.getPosition(),
498
- preference: [2 , 1 ]
499
- };
500
- }
501
- }
502
- registerEditorContribution(InspectEditorTokensController.ID, InspectEditorTokensController, 4 );
503
- registerEditorAction(InspectEditorTokens);
@@ -1,107 +0,0 @@
1
- function findMatchingThemeRule(theme, scopes, onlyColorRules = true) {
2
- for (let i = scopes.length - 1; i >= 0; i--) {
3
- const parentScopes = scopes.slice(0, i);
4
- const scope = scopes[i];
5
- const r = findMatchingThemeRule2(theme, scope, parentScopes, onlyColorRules);
6
- if (r) {
7
- return r;
8
- }
9
- }
10
- return null;
11
- }
12
- function findMatchingThemeRule2(theme, scope, parentScopes, onlyColorRules) {
13
- let result = null;
14
- for (let i = theme.tokenColors.length - 1; i >= 0; i--) {
15
- const rule = theme.tokenColors[i];
16
- if (onlyColorRules && !rule.settings.foreground) {
17
- continue;
18
- }
19
- let selectors;
20
- if (typeof rule.scope === 'string') {
21
- selectors = ( rule.scope.split(/,/).map(scope => scope.trim()));
22
- }
23
- else if (Array.isArray(rule.scope)) {
24
- selectors = rule.scope;
25
- }
26
- else {
27
- continue;
28
- }
29
- for (let j = 0, lenJ = selectors.length; j < lenJ; j++) {
30
- const rawSelector = selectors[j];
31
- const themeRule = ( new ThemeRule(rawSelector, rule.settings));
32
- if (themeRule.matches(scope, parentScopes)) {
33
- if (themeRule.isMoreSpecific(result)) {
34
- result = themeRule;
35
- }
36
- }
37
- }
38
- }
39
- return result;
40
- }
41
- class ThemeRule {
42
- constructor(rawSelector, settings) {
43
- this.rawSelector = rawSelector;
44
- this.settings = settings;
45
- const rawSelectorPieces = this.rawSelector.split(/ /);
46
- this.scope = rawSelectorPieces[rawSelectorPieces.length - 1];
47
- this.parentScopes = rawSelectorPieces.slice(0, rawSelectorPieces.length - 1);
48
- }
49
- matches(scope, parentScopes) {
50
- return ThemeRule._matches(this.scope, this.parentScopes, scope, parentScopes);
51
- }
52
- static _cmp(a, b) {
53
- if (a === null && b === null) {
54
- return 0;
55
- }
56
- if (a === null) {
57
- return -1;
58
- }
59
- if (b === null) {
60
- return 1;
61
- }
62
- if (a.scope.length !== b.scope.length) {
63
- return a.scope.length - b.scope.length;
64
- }
65
- const aParentScopesLen = a.parentScopes.length;
66
- const bParentScopesLen = b.parentScopes.length;
67
- if (aParentScopesLen !== bParentScopesLen) {
68
- return aParentScopesLen - bParentScopesLen;
69
- }
70
- for (let i = 0; i < aParentScopesLen; i++) {
71
- const aLen = a.parentScopes[i].length;
72
- const bLen = b.parentScopes[i].length;
73
- if (aLen !== bLen) {
74
- return aLen - bLen;
75
- }
76
- }
77
- return 0;
78
- }
79
- isMoreSpecific(other) {
80
- return (ThemeRule._cmp(this, other) > 0);
81
- }
82
- static _matchesOne(selectorScope, scope) {
83
- const selectorPrefix = selectorScope + '.';
84
- if (selectorScope === scope || scope.substring(0, selectorPrefix.length) === selectorPrefix) {
85
- return true;
86
- }
87
- return false;
88
- }
89
- static _matches(selectorScope, selectorParentScopes, scope, parentScopes) {
90
- if (!this._matchesOne(selectorScope, scope)) {
91
- return false;
92
- }
93
- let selectorParentIndex = selectorParentScopes.length - 1;
94
- let parentIndex = parentScopes.length - 1;
95
- while (selectorParentIndex >= 0 && parentIndex >= 0) {
96
- if (this._matchesOne(selectorParentScopes[selectorParentIndex], parentScopes[parentIndex])) {
97
- selectorParentIndex--;
98
- }
99
- parentIndex--;
100
- }
101
- if (selectorParentIndex === -1) {
102
- return true;
103
- }
104
- return false;
105
- }
106
- }
107
- export { ThemeRule, findMatchingThemeRule };