@codingame/monaco-vscode-textmate-service-override 4.4.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/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +10 -7
- package/textmate.js +4 -3
- package/vscode/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.css.js +6 -0
- package/vscode/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.js +504 -0
- package/vscode/src/vs/workbench/services/textMate/browser/backgroundTokenization/threadedBackgroundTokenizerFactory.js +6 -6
- package/vscode/src/vs/workbench/services/textMate/browser/textMateTokenizationFeatureImpl.js +8 -8
- package/vscode/src/vs/workbench/services/textMate/common/TMHelper.js +108 -0
- /package/vscode/src/vs/workbench/services/textMate/browser/{textMateTokenizationFeature.d.ts → textMateTokenizationFeature.service.d.ts} +0 -0
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default } from './textmate.js';
|
|
2
|
-
export { ITextMateTokenizationService } from './vscode/src/vs/workbench/services/textMate/browser/textMateTokenizationFeature.js';
|
|
2
|
+
export { ITextMateTokenizationService } from './vscode/src/vs/workbench/services/textMate/browser/textMateTokenizationFeature.service.js';
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default } from './textmate.js';
|
|
2
|
-
export { ITextMateTokenizationService } from 'vscode/vscode/vs/workbench/services/textMate/browser/textMateTokenizationFeature';
|
|
2
|
+
export { ITextMateTokenizationService } from 'vscode/vscode/vs/workbench/services/textMate/browser/textMateTokenizationFeature.service';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-textmate-service-override",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "CodinGame",
|
|
@@ -17,18 +17,21 @@
|
|
|
17
17
|
"main": "index.js",
|
|
18
18
|
"module": "index.js",
|
|
19
19
|
"types": "index.d.ts",
|
|
20
|
-
"dependencies": {
|
|
21
|
-
"vscode": "npm:@codingame/monaco-vscode-api@4.4.1",
|
|
22
|
-
"vscode-oniguruma": "1.7.0",
|
|
23
|
-
"vscode-textmate": "9.0.0",
|
|
24
|
-
"@codingame/monaco-vscode-files-service-override": "4.4.1"
|
|
25
|
-
},
|
|
26
20
|
"exports": {
|
|
27
21
|
".": {
|
|
28
22
|
"default": "./index.js"
|
|
29
23
|
},
|
|
24
|
+
"./vscode/*": {
|
|
25
|
+
"default": "./vscode/src/*.js"
|
|
26
|
+
},
|
|
30
27
|
"./worker": {
|
|
31
28
|
"default": "./worker.js"
|
|
32
29
|
}
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"vscode": "npm:@codingame/monaco-vscode-api@4.5.0",
|
|
33
|
+
"vscode-oniguruma": "1.7.0",
|
|
34
|
+
"vscode-textmate": "9.0.0",
|
|
35
|
+
"@codingame/monaco-vscode-files-service-override": "4.5.0"
|
|
33
36
|
}
|
|
34
37
|
}
|
package/textmate.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { StandaloneServices } from 'vscode/vscode/vs/editor/standalone/browser/standaloneServices';
|
|
2
|
-
import { ITextMateTokenizationService } from 'vscode/vscode/vs/workbench/services/textMate/browser/textMateTokenizationFeature';
|
|
3
|
-
export { ITextMateTokenizationService } from 'vscode/vscode/vs/workbench/services/textMate/browser/textMateTokenizationFeature';
|
|
2
|
+
import { ITextMateTokenizationService } from 'vscode/vscode/vs/workbench/services/textMate/browser/textMateTokenizationFeature.service';
|
|
3
|
+
export { ITextMateTokenizationService } from 'vscode/vscode/vs/workbench/services/textMate/browser/textMateTokenizationFeature.service';
|
|
4
4
|
import { SyncDescriptor } from 'vscode/vscode/vs/platform/instantiation/common/descriptors';
|
|
5
5
|
import { TextMateTokenizationFeature } from './vscode/src/vs/workbench/services/textMate/browser/textMateTokenizationFeatureImpl.js';
|
|
6
|
-
import { ILifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle';
|
|
6
|
+
import { ILifecycleService } from 'vscode/vscode/vs/workbench/services/lifecycle/common/lifecycle.service';
|
|
7
7
|
import getServiceOverride$1 from '@codingame/monaco-vscode-files-service-override';
|
|
8
8
|
import { registerServiceInitializeParticipant } from 'vscode/lifecycle';
|
|
9
9
|
import { registerAssets } from 'vscode/assets';
|
|
10
10
|
import './vscode/src/vs/workbench/services/themes/common/tokenClassificationExtensionPoint.js';
|
|
11
|
+
import './vscode/src/vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens.js';
|
|
11
12
|
|
|
12
13
|
const _onigWasm = new URL('vscode-oniguruma/release/onig.wasm', import.meta.url).href;
|
|
13
14
|
registerAssets({
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import n from 'vscode/external/rollup-plugin-styles/dist/runtime/inject-css.js';
|
|
2
|
+
|
|
3
|
+
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)}";
|
|
4
|
+
n(css,{});
|
|
5
|
+
|
|
6
|
+
export { css, css as default };
|
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
|
+
import './inspectEditorTokens.css.js';
|
|
3
|
+
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
4
|
+
import { $ as $$1, clearNode, reset, append } from 'vscode/vscode/vs/base/browser/dom';
|
|
5
|
+
import { Color } from 'vscode/vscode/vs/base/common/color';
|
|
6
|
+
import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
7
|
+
import { EditorAction, registerEditorContribution, registerEditorAction } from 'vscode/vscode/vs/editor/browser/editorExtensions';
|
|
8
|
+
import { Range } from 'vscode/vscode/vs/editor/common/core/range';
|
|
9
|
+
import { TokenMetadata } from 'vscode/vscode/vs/editor/common/encodedTokenAttributes';
|
|
10
|
+
import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
|
|
11
|
+
import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification.service';
|
|
12
|
+
import { findMatchingThemeRule } from '../../../../services/textMate/common/TMHelper.js';
|
|
13
|
+
import { ITextMateTokenizationService } from 'vscode/vscode/vs/workbench/services/textMate/browser/textMateTokenizationFeature.service';
|
|
14
|
+
import { IWorkbenchThemeService } from 'vscode/vscode/vs/workbench/services/themes/common/workbenchThemeService.service';
|
|
15
|
+
import { CancellationTokenSource } from 'vscode/vscode/vs/base/common/cancellation';
|
|
16
|
+
import { SemanticTokenRule } from 'vscode/vscode/vs/platform/theme/common/tokenClassificationRegistry';
|
|
17
|
+
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
|
|
18
|
+
import { SEMANTIC_HIGHLIGHTING_SETTING_ID } from 'vscode/vscode/vs/editor/contrib/semanticTokens/common/semanticTokensConfig';
|
|
19
|
+
import { Schemas } from 'vscode/vscode/vs/base/common/network';
|
|
20
|
+
import { ILanguageFeaturesService } from 'vscode/vscode/vs/editor/common/services/languageFeatures';
|
|
21
|
+
|
|
22
|
+
var InspectEditorTokensController_1;
|
|
23
|
+
const $ = $$1;
|
|
24
|
+
let InspectEditorTokensController = class InspectEditorTokensController extends Disposable {
|
|
25
|
+
static { InspectEditorTokensController_1 = this; }
|
|
26
|
+
static { this.ID = 'editor.contrib.inspectEditorTokens'; }
|
|
27
|
+
static get(editor) {
|
|
28
|
+
return editor.getContribution(InspectEditorTokensController_1.ID);
|
|
29
|
+
}
|
|
30
|
+
constructor(editor, textMateService, languageService, themeService, notificationService, configurationService, languageFeaturesService) {
|
|
31
|
+
super();
|
|
32
|
+
this._editor = editor;
|
|
33
|
+
this._textMateService = textMateService;
|
|
34
|
+
this._themeService = themeService;
|
|
35
|
+
this._languageService = languageService;
|
|
36
|
+
this._notificationService = notificationService;
|
|
37
|
+
this._configurationService = configurationService;
|
|
38
|
+
this._languageFeaturesService = languageFeaturesService;
|
|
39
|
+
this._widget = null;
|
|
40
|
+
this._register(this._editor.onDidChangeModel((e) => this.stop()));
|
|
41
|
+
this._register(this._editor.onDidChangeModelLanguage((e) => this.stop()));
|
|
42
|
+
this._register(this._editor.onKeyUp((e) => e.keyCode === 9 && this.stop()));
|
|
43
|
+
}
|
|
44
|
+
dispose() {
|
|
45
|
+
this.stop();
|
|
46
|
+
super.dispose();
|
|
47
|
+
}
|
|
48
|
+
launch() {
|
|
49
|
+
if (this._widget) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!this._editor.hasModel()) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (this._editor.getModel().uri.scheme === Schemas.vscodeNotebookCell) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
this._widget = ( new InspectEditorTokensWidget(
|
|
59
|
+
this._editor,
|
|
60
|
+
this._textMateService,
|
|
61
|
+
this._languageService,
|
|
62
|
+
this._themeService,
|
|
63
|
+
this._notificationService,
|
|
64
|
+
this._configurationService,
|
|
65
|
+
this._languageFeaturesService
|
|
66
|
+
));
|
|
67
|
+
}
|
|
68
|
+
stop() {
|
|
69
|
+
if (this._widget) {
|
|
70
|
+
this._widget.dispose();
|
|
71
|
+
this._widget = null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
toggle() {
|
|
75
|
+
if (!this._widget) {
|
|
76
|
+
this.launch();
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.stop();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
InspectEditorTokensController = InspectEditorTokensController_1 = ( __decorate([
|
|
84
|
+
( __param(1, ITextMateTokenizationService)),
|
|
85
|
+
( __param(2, ILanguageService)),
|
|
86
|
+
( __param(3, IWorkbenchThemeService)),
|
|
87
|
+
( __param(4, INotificationService)),
|
|
88
|
+
( __param(5, IConfigurationService)),
|
|
89
|
+
( __param(6, ILanguageFeaturesService))
|
|
90
|
+
], InspectEditorTokensController));
|
|
91
|
+
class InspectEditorTokens extends EditorAction {
|
|
92
|
+
constructor() {
|
|
93
|
+
super({
|
|
94
|
+
id: 'editor.action.inspectTMScopes',
|
|
95
|
+
label: ( localizeWithPath(
|
|
96
|
+
'vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens',
|
|
97
|
+
'inspectEditorTokens',
|
|
98
|
+
"Developer: Inspect Editor Tokens and Scopes"
|
|
99
|
+
)),
|
|
100
|
+
alias: 'Developer: Inspect Editor Tokens and Scopes',
|
|
101
|
+
precondition: undefined
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
run(accessor, editor) {
|
|
105
|
+
const controller = InspectEditorTokensController.get(editor);
|
|
106
|
+
controller?.toggle();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function renderTokenText(tokenText) {
|
|
110
|
+
if (tokenText.length > 40) {
|
|
111
|
+
tokenText = tokenText.substr(0, 20) + '…' + tokenText.substr(tokenText.length - 20);
|
|
112
|
+
}
|
|
113
|
+
let result = '';
|
|
114
|
+
for (let charIndex = 0, len = tokenText.length; charIndex < len; charIndex++) {
|
|
115
|
+
const charCode = tokenText.charCodeAt(charIndex);
|
|
116
|
+
switch (charCode) {
|
|
117
|
+
case 9 :
|
|
118
|
+
result += '\u2192';
|
|
119
|
+
break;
|
|
120
|
+
case 32 :
|
|
121
|
+
result += '\u00B7';
|
|
122
|
+
break;
|
|
123
|
+
default:
|
|
124
|
+
result += String.fromCharCode(charCode);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
class InspectEditorTokensWidget extends Disposable {
|
|
130
|
+
static { this._ID = 'editor.contrib.inspectEditorTokensWidget'; }
|
|
131
|
+
constructor(editor, textMateService, languageService, themeService, notificationService, configurationService, languageFeaturesService) {
|
|
132
|
+
super();
|
|
133
|
+
this.allowEditorOverflow = true;
|
|
134
|
+
this._isDisposed = false;
|
|
135
|
+
this._editor = editor;
|
|
136
|
+
this._languageService = languageService;
|
|
137
|
+
this._themeService = themeService;
|
|
138
|
+
this._textMateService = textMateService;
|
|
139
|
+
this._notificationService = notificationService;
|
|
140
|
+
this._configurationService = configurationService;
|
|
141
|
+
this._languageFeaturesService = languageFeaturesService;
|
|
142
|
+
this._model = this._editor.getModel();
|
|
143
|
+
this._domNode = document.createElement('div');
|
|
144
|
+
this._domNode.className = 'token-inspect-widget';
|
|
145
|
+
this._currentRequestCancellationTokenSource = ( new CancellationTokenSource());
|
|
146
|
+
this._beginCompute(this._editor.getPosition());
|
|
147
|
+
this._register(this._editor.onDidChangeCursorPosition((e) => this._beginCompute(this._editor.getPosition())));
|
|
148
|
+
this._register(themeService.onDidColorThemeChange(_ => this._beginCompute(this._editor.getPosition())));
|
|
149
|
+
this._register(configurationService.onDidChangeConfiguration(e => e.affectsConfiguration('editor.semanticHighlighting.enabled') && this._beginCompute(this._editor.getPosition())));
|
|
150
|
+
this._editor.addContentWidget(this);
|
|
151
|
+
}
|
|
152
|
+
dispose() {
|
|
153
|
+
this._isDisposed = true;
|
|
154
|
+
this._editor.removeContentWidget(this);
|
|
155
|
+
this._currentRequestCancellationTokenSource.cancel();
|
|
156
|
+
super.dispose();
|
|
157
|
+
}
|
|
158
|
+
getId() {
|
|
159
|
+
return InspectEditorTokensWidget._ID;
|
|
160
|
+
}
|
|
161
|
+
_beginCompute(position) {
|
|
162
|
+
const grammar = this._textMateService.createTokenizer(this._model.getLanguageId());
|
|
163
|
+
const semanticTokens = this._computeSemanticTokens(position);
|
|
164
|
+
clearNode(this._domNode);
|
|
165
|
+
this._domNode.appendChild(document.createTextNode(( localizeWithPath(
|
|
166
|
+
'vs/workbench/contrib/codeEditor/browser/inspectEditorTokens/inspectEditorTokens',
|
|
167
|
+
'inspectTMScopesWidget.loading',
|
|
168
|
+
"Loading..."
|
|
169
|
+
))));
|
|
170
|
+
Promise.all([grammar, semanticTokens]).then(([grammar, semanticTokens]) => {
|
|
171
|
+
if (this._isDisposed) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
this._compute(grammar, semanticTokens, position);
|
|
175
|
+
this._domNode.style.maxWidth = `${Math.max(this._editor.getLayoutInfo().width * 0.66, 500)}px`;
|
|
176
|
+
this._editor.layoutContentWidget(this);
|
|
177
|
+
}, (err) => {
|
|
178
|
+
this._notificationService.warn(err);
|
|
179
|
+
setTimeout(() => {
|
|
180
|
+
InspectEditorTokensController.get(this._editor)?.stop();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
_isSemanticColoringEnabled() {
|
|
185
|
+
const setting = this._configurationService.getValue(SEMANTIC_HIGHLIGHTING_SETTING_ID, { overrideIdentifier: this._model.getLanguageId(), resource: this._model.uri })?.enabled;
|
|
186
|
+
if (typeof setting === 'boolean') {
|
|
187
|
+
return setting;
|
|
188
|
+
}
|
|
189
|
+
return this._themeService.getColorTheme().semanticHighlighting;
|
|
190
|
+
}
|
|
191
|
+
_compute(grammar, semanticTokens, position) {
|
|
192
|
+
const textMateTokenInfo = grammar && this._getTokensAtPosition(grammar, position);
|
|
193
|
+
const semanticTokenInfo = semanticTokens && this._getSemanticTokenAtPosition(semanticTokens, position);
|
|
194
|
+
if (!textMateTokenInfo && !semanticTokenInfo) {
|
|
195
|
+
reset(this._domNode, 'No grammar or semantic tokens available.');
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const tmMetadata = textMateTokenInfo?.metadata;
|
|
199
|
+
const semMetadata = semanticTokenInfo?.metadata;
|
|
200
|
+
const semTokenText = semanticTokenInfo && renderTokenText(this._model.getValueInRange(semanticTokenInfo.range));
|
|
201
|
+
const tmTokenText = textMateTokenInfo && renderTokenText(this._model.getLineContent(position.lineNumber).substring(textMateTokenInfo.token.startIndex, textMateTokenInfo.token.endIndex));
|
|
202
|
+
const tokenText = semTokenText || tmTokenText || '';
|
|
203
|
+
reset(this._domNode, $('h2.tiw-token', undefined, tokenText, $('span.tiw-token-length', undefined, `${tokenText.length} ${tokenText.length === 1 ? 'char' : 'chars'}`)));
|
|
204
|
+
append(this._domNode, $('hr.tiw-metadata-separator', { 'style': 'clear:both' }));
|
|
205
|
+
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))));
|
|
206
|
+
if (semanticTokenInfo) {
|
|
207
|
+
append(this._domNode, $('hr.tiw-metadata-separator'));
|
|
208
|
+
const table = append(this._domNode, $('table.tiw-metadata-table', undefined));
|
|
209
|
+
const tbody = append(table, $('tbody', undefined, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'semantic token type'), $('td.tiw-metadata-value', undefined, semanticTokenInfo.type))));
|
|
210
|
+
if (semanticTokenInfo.modifiers.length) {
|
|
211
|
+
append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'modifiers'), $('td.tiw-metadata-value', undefined, semanticTokenInfo.modifiers.join(' '))));
|
|
212
|
+
}
|
|
213
|
+
if (semanticTokenInfo.metadata) {
|
|
214
|
+
const properties = ['foreground', 'bold', 'italic', 'underline', 'strikethrough'];
|
|
215
|
+
const propertiesByDefValue = {};
|
|
216
|
+
const allDefValues = ( new Array());
|
|
217
|
+
for (const property of properties) {
|
|
218
|
+
if (semanticTokenInfo.metadata[property] !== undefined) {
|
|
219
|
+
const definition = semanticTokenInfo.definitions[property];
|
|
220
|
+
const defValue = this._renderTokenStyleDefinition(definition, property);
|
|
221
|
+
const defValueStr = ( defValue.map(el => el instanceof HTMLElement ? el.outerHTML : el)).join();
|
|
222
|
+
let properties = propertiesByDefValue[defValueStr];
|
|
223
|
+
if (!properties) {
|
|
224
|
+
propertiesByDefValue[defValueStr] = properties = [];
|
|
225
|
+
allDefValues.push([defValue, defValueStr]);
|
|
226
|
+
}
|
|
227
|
+
properties.push(property);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
for (const [defValue, defValueStr] of allDefValues) {
|
|
231
|
+
append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, propertiesByDefValue[defValueStr].join(', ')), $('td.tiw-metadata-value', undefined, ...defValue)));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (textMateTokenInfo) {
|
|
236
|
+
const theme = this._themeService.getColorTheme();
|
|
237
|
+
append(this._domNode, $('hr.tiw-metadata-separator'));
|
|
238
|
+
const table = append(this._domNode, $('table.tiw-metadata-table'));
|
|
239
|
+
const tbody = append(table, $('tbody'));
|
|
240
|
+
if (tmTokenText && tmTokenText !== tokenText) {
|
|
241
|
+
append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'textmate token'), $('td.tiw-metadata-value', undefined, `${tmTokenText} (${tmTokenText.length})`)));
|
|
242
|
+
}
|
|
243
|
+
const scopes = ( new Array());
|
|
244
|
+
for (let i = textMateTokenInfo.token.scopes.length - 1; i >= 0; i--) {
|
|
245
|
+
scopes.push(textMateTokenInfo.token.scopes[i]);
|
|
246
|
+
if (i > 0) {
|
|
247
|
+
scopes.push($('br'));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'textmate scopes'), $('td.tiw-metadata-value.tiw-metadata-scopes', undefined, ...scopes)));
|
|
251
|
+
const matchingRule = findMatchingThemeRule(theme, textMateTokenInfo.token.scopes, false);
|
|
252
|
+
const semForeground = semanticTokenInfo?.metadata?.foreground;
|
|
253
|
+
if (matchingRule) {
|
|
254
|
+
if (semForeground !== textMateTokenInfo.metadata.foreground) {
|
|
255
|
+
let defValue = $('code.tiw-theme-selector', undefined, matchingRule.rawSelector, $('br'), JSON.stringify(matchingRule.settings, null, '\t'));
|
|
256
|
+
if (semForeground) {
|
|
257
|
+
defValue = $('s', undefined, defValue);
|
|
258
|
+
}
|
|
259
|
+
append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'foreground'), $('td.tiw-metadata-value', undefined, defValue)));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
else if (!semForeground) {
|
|
263
|
+
append(tbody, $('tr', undefined, $('td.tiw-metadata-key', undefined, 'foreground'), $('td.tiw-metadata-value', undefined, 'No theme selector')));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
_formatMetadata(semantic, tm) {
|
|
268
|
+
const elements = ( new Array());
|
|
269
|
+
function render(property) {
|
|
270
|
+
const value = semantic?.[property] || tm?.[property];
|
|
271
|
+
if (value !== undefined) {
|
|
272
|
+
const semanticStyle = semantic?.[property] ? 'tiw-metadata-semantic' : '';
|
|
273
|
+
elements.push($('tr', undefined, $('td.tiw-metadata-key', undefined, property), $(`td.tiw-metadata-value.${semanticStyle}`, undefined, value)));
|
|
274
|
+
}
|
|
275
|
+
return value;
|
|
276
|
+
}
|
|
277
|
+
const foreground = render('foreground');
|
|
278
|
+
const background = render('background');
|
|
279
|
+
if (foreground && background) {
|
|
280
|
+
const backgroundColor = ( Color.fromHex(background)), foregroundColor = ( Color.fromHex(foreground));
|
|
281
|
+
if (backgroundColor.isOpaque()) {
|
|
282
|
+
elements.push($('tr', undefined, $('td.tiw-metadata-key', undefined, 'contrast ratio'), $('td.tiw-metadata-value', undefined, backgroundColor.getContrastRatio(foregroundColor.makeOpaque(backgroundColor)).toFixed(2))));
|
|
283
|
+
}
|
|
284
|
+
else {
|
|
285
|
+
elements.push($('tr', undefined, $('td.tiw-metadata-key', undefined, 'Contrast ratio cannot be precise for background colors that use transparency'), $('td.tiw-metadata-value')));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const fontStyleLabels = ( new Array());
|
|
289
|
+
function addStyle(key) {
|
|
290
|
+
let label;
|
|
291
|
+
if (semantic && semantic[key]) {
|
|
292
|
+
label = $('span.tiw-metadata-semantic', undefined, key);
|
|
293
|
+
}
|
|
294
|
+
else if (tm && tm[key]) {
|
|
295
|
+
label = key;
|
|
296
|
+
}
|
|
297
|
+
if (label) {
|
|
298
|
+
if (fontStyleLabels.length) {
|
|
299
|
+
fontStyleLabels.push(' ');
|
|
300
|
+
}
|
|
301
|
+
fontStyleLabels.push(label);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
addStyle('bold');
|
|
305
|
+
addStyle('italic');
|
|
306
|
+
addStyle('underline');
|
|
307
|
+
addStyle('strikethrough');
|
|
308
|
+
if (fontStyleLabels.length) {
|
|
309
|
+
elements.push($('tr', undefined, $('td.tiw-metadata-key', undefined, 'font style'), $('td.tiw-metadata-value', undefined, ...fontStyleLabels)));
|
|
310
|
+
}
|
|
311
|
+
return elements;
|
|
312
|
+
}
|
|
313
|
+
_decodeMetadata(metadata) {
|
|
314
|
+
const colorMap = this._themeService.getColorTheme().tokenColorMap;
|
|
315
|
+
const languageId = TokenMetadata.getLanguageId(metadata);
|
|
316
|
+
const tokenType = TokenMetadata.getTokenType(metadata);
|
|
317
|
+
const fontStyle = TokenMetadata.getFontStyle(metadata);
|
|
318
|
+
const foreground = TokenMetadata.getForeground(metadata);
|
|
319
|
+
const background = TokenMetadata.getBackground(metadata);
|
|
320
|
+
return {
|
|
321
|
+
languageId: this._languageService.languageIdCodec.decodeLanguageId(languageId),
|
|
322
|
+
tokenType: tokenType,
|
|
323
|
+
bold: ((fontStyle & 2) ) ? true : undefined,
|
|
324
|
+
italic: ((fontStyle & 1) ) ? true : undefined,
|
|
325
|
+
underline: ((fontStyle & 4) ) ? true : undefined,
|
|
326
|
+
strikethrough: ((fontStyle & 8) ) ? true : undefined,
|
|
327
|
+
foreground: colorMap[foreground],
|
|
328
|
+
background: colorMap[background]
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
_tokenTypeToString(tokenType) {
|
|
332
|
+
switch (tokenType) {
|
|
333
|
+
case 0 : return 'Other';
|
|
334
|
+
case 1 : return 'Comment';
|
|
335
|
+
case 2 : return 'String';
|
|
336
|
+
case 3 : return 'RegEx';
|
|
337
|
+
default: return '??';
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
_getTokensAtPosition(grammar, position) {
|
|
341
|
+
const lineNumber = position.lineNumber;
|
|
342
|
+
const stateBeforeLine = this._getStateBeforeLine(grammar, lineNumber);
|
|
343
|
+
const tokenizationResult1 = grammar.tokenizeLine(this._model.getLineContent(lineNumber), stateBeforeLine);
|
|
344
|
+
const tokenizationResult2 = grammar.tokenizeLine2(this._model.getLineContent(lineNumber), stateBeforeLine);
|
|
345
|
+
let token1Index = 0;
|
|
346
|
+
for (let i = tokenizationResult1.tokens.length - 1; i >= 0; i--) {
|
|
347
|
+
const t = tokenizationResult1.tokens[i];
|
|
348
|
+
if (position.column - 1 >= t.startIndex) {
|
|
349
|
+
token1Index = i;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
let token2Index = 0;
|
|
354
|
+
for (let i = (tokenizationResult2.tokens.length >>> 1); i >= 0; i--) {
|
|
355
|
+
if (position.column - 1 >= tokenizationResult2.tokens[(i << 1)]) {
|
|
356
|
+
token2Index = i;
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
token: tokenizationResult1.tokens[token1Index],
|
|
362
|
+
metadata: this._decodeMetadata(tokenizationResult2.tokens[(token2Index << 1) + 1])
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
_getStateBeforeLine(grammar, lineNumber) {
|
|
366
|
+
let state = null;
|
|
367
|
+
for (let i = 1; i < lineNumber; i++) {
|
|
368
|
+
const tokenizationResult = grammar.tokenizeLine(this._model.getLineContent(i), state);
|
|
369
|
+
state = tokenizationResult.ruleStack;
|
|
370
|
+
}
|
|
371
|
+
return state;
|
|
372
|
+
}
|
|
373
|
+
isSemanticTokens(token) {
|
|
374
|
+
return token && token.data;
|
|
375
|
+
}
|
|
376
|
+
async _computeSemanticTokens(position) {
|
|
377
|
+
if (!this._isSemanticColoringEnabled()) {
|
|
378
|
+
return null;
|
|
379
|
+
}
|
|
380
|
+
const tokenProviders = this._languageFeaturesService.documentSemanticTokensProvider.ordered(this._model);
|
|
381
|
+
if (tokenProviders.length) {
|
|
382
|
+
const provider = tokenProviders[0];
|
|
383
|
+
const tokens = await Promise.resolve(provider.provideDocumentSemanticTokens(this._model, null, this._currentRequestCancellationTokenSource.token));
|
|
384
|
+
if (this.isSemanticTokens(tokens)) {
|
|
385
|
+
return { tokens, legend: provider.getLegend() };
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
const rangeTokenProviders = this._languageFeaturesService.documentRangeSemanticTokensProvider.ordered(this._model);
|
|
389
|
+
if (rangeTokenProviders.length) {
|
|
390
|
+
const provider = rangeTokenProviders[0];
|
|
391
|
+
const lineNumber = position.lineNumber;
|
|
392
|
+
const range = ( new Range(lineNumber, 1, lineNumber, this._model.getLineMaxColumn(lineNumber)));
|
|
393
|
+
const tokens = await Promise.resolve(provider.provideDocumentRangeSemanticTokens(this._model, range, this._currentRequestCancellationTokenSource.token));
|
|
394
|
+
if (this.isSemanticTokens(tokens)) {
|
|
395
|
+
return { tokens, legend: provider.getLegend() };
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return null;
|
|
399
|
+
}
|
|
400
|
+
_getSemanticTokenAtPosition(semanticTokens, pos) {
|
|
401
|
+
const tokenData = semanticTokens.tokens.data;
|
|
402
|
+
const defaultLanguage = this._model.getLanguageId();
|
|
403
|
+
let lastLine = 0;
|
|
404
|
+
let lastCharacter = 0;
|
|
405
|
+
const posLine = pos.lineNumber - 1, posCharacter = pos.column - 1;
|
|
406
|
+
for (let i = 0; i < tokenData.length; i += 5) {
|
|
407
|
+
const lineDelta = tokenData[i], charDelta = tokenData[i + 1], len = tokenData[i + 2], typeIdx = tokenData[i + 3], modSet = tokenData[i + 4];
|
|
408
|
+
const line = lastLine + lineDelta;
|
|
409
|
+
const character = lineDelta === 0 ? lastCharacter + charDelta : charDelta;
|
|
410
|
+
if (posLine === line && character <= posCharacter && posCharacter < character + len) {
|
|
411
|
+
const type = semanticTokens.legend.tokenTypes[typeIdx] || 'not in legend (ignored)';
|
|
412
|
+
const modifiers = [];
|
|
413
|
+
let modifierSet = modSet;
|
|
414
|
+
for (let modifierIndex = 0; modifierSet > 0 && modifierIndex < semanticTokens.legend.tokenModifiers.length; modifierIndex++) {
|
|
415
|
+
if (modifierSet & 1) {
|
|
416
|
+
modifiers.push(semanticTokens.legend.tokenModifiers[modifierIndex]);
|
|
417
|
+
}
|
|
418
|
+
modifierSet = modifierSet >> 1;
|
|
419
|
+
}
|
|
420
|
+
if (modifierSet > 0) {
|
|
421
|
+
modifiers.push('not in legend (ignored)');
|
|
422
|
+
}
|
|
423
|
+
const range = ( new Range(line + 1, character + 1, line + 1, character + 1 + len));
|
|
424
|
+
const definitions = {};
|
|
425
|
+
const colorMap = this._themeService.getColorTheme().tokenColorMap;
|
|
426
|
+
const theme = this._themeService.getColorTheme();
|
|
427
|
+
const tokenStyle = theme.getTokenStyleMetadata(type, modifiers, defaultLanguage, true, definitions);
|
|
428
|
+
let metadata = undefined;
|
|
429
|
+
if (tokenStyle) {
|
|
430
|
+
metadata = {
|
|
431
|
+
languageId: undefined,
|
|
432
|
+
tokenType: 0 ,
|
|
433
|
+
bold: tokenStyle?.bold,
|
|
434
|
+
italic: tokenStyle?.italic,
|
|
435
|
+
underline: tokenStyle?.underline,
|
|
436
|
+
strikethrough: tokenStyle?.strikethrough,
|
|
437
|
+
foreground: colorMap[tokenStyle?.foreground || 0 ],
|
|
438
|
+
background: undefined
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
return { type, modifiers, range, metadata, definitions };
|
|
442
|
+
}
|
|
443
|
+
lastLine = line;
|
|
444
|
+
lastCharacter = character;
|
|
445
|
+
}
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
_renderTokenStyleDefinition(definition, property) {
|
|
449
|
+
const elements = ( new Array());
|
|
450
|
+
if (definition === undefined) {
|
|
451
|
+
return elements;
|
|
452
|
+
}
|
|
453
|
+
const theme = this._themeService.getColorTheme();
|
|
454
|
+
if (Array.isArray(definition)) {
|
|
455
|
+
const scopesDefinition = {};
|
|
456
|
+
theme.resolveScopes(definition, scopesDefinition);
|
|
457
|
+
const matchingRule = scopesDefinition[property];
|
|
458
|
+
if (matchingRule && scopesDefinition.scope) {
|
|
459
|
+
const scopes = $('ul.tiw-metadata-values');
|
|
460
|
+
const strScopes = Array.isArray(matchingRule.scope) ? matchingRule.scope : [String(matchingRule.scope)];
|
|
461
|
+
for (const strScope of strScopes) {
|
|
462
|
+
scopes.appendChild($('li.tiw-metadata-value.tiw-metadata-scopes', undefined, strScope));
|
|
463
|
+
}
|
|
464
|
+
elements.push(scopesDefinition.scope.join(' '), scopes, $('code.tiw-theme-selector', undefined, JSON.stringify(matchingRule.settings, null, '\t')));
|
|
465
|
+
return elements;
|
|
466
|
+
}
|
|
467
|
+
return elements;
|
|
468
|
+
}
|
|
469
|
+
else if (SemanticTokenRule.is(definition)) {
|
|
470
|
+
const scope = theme.getTokenStylingRuleScope(definition);
|
|
471
|
+
if (scope === 'setting') {
|
|
472
|
+
elements.push(`User settings: ${definition.selector.id} - ${this._renderStyleProperty(definition.style, property)}`);
|
|
473
|
+
return elements;
|
|
474
|
+
}
|
|
475
|
+
else if (scope === 'theme') {
|
|
476
|
+
elements.push(`Color theme: ${definition.selector.id} - ${this._renderStyleProperty(definition.style, property)}`);
|
|
477
|
+
return elements;
|
|
478
|
+
}
|
|
479
|
+
return elements;
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
const style = theme.resolveTokenStyleValue(definition);
|
|
483
|
+
elements.push(`Default: ${style ? this._renderStyleProperty(style, property) : ''}`);
|
|
484
|
+
return elements;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
_renderStyleProperty(style, property) {
|
|
488
|
+
switch (property) {
|
|
489
|
+
case 'foreground': return style.foreground ? Color.Format.CSS.formatHexA(style.foreground, true) : '';
|
|
490
|
+
default: return style[property] !== undefined ? String(style[property]) : '';
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
getDomNode() {
|
|
494
|
+
return this._domNode;
|
|
495
|
+
}
|
|
496
|
+
getPosition() {
|
|
497
|
+
return {
|
|
498
|
+
position: this._editor.getPosition(),
|
|
499
|
+
preference: [2 , 1 ]
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
registerEditorContribution(InspectEditorTokensController.ID, InspectEditorTokensController, 4 );
|
|
504
|
+
registerEditorAction(InspectEditorTokens);
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { __decorate, __param } from 'vscode/external/tslib/tslib.es6.js';
|
|
2
2
|
import { DisposableStore, toDisposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
3
|
-
import {
|
|
3
|
+
import { nodeModulesPath, nodeModulesAsarPath, FileAccess } from 'vscode/vscode/vs/base/common/network';
|
|
4
4
|
import { isWeb } from 'vscode/vscode/vs/base/common/platform';
|
|
5
5
|
import { URI } from 'vscode/vscode/vs/base/common/uri';
|
|
6
6
|
import { createWebWorker } from 'vscode/vscode/vs/editor/browser/services/webWorker';
|
|
7
7
|
import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
|
|
8
8
|
import { ILanguageConfigurationService } from 'vscode/vscode/vs/editor/common/languages/languageConfigurationRegistry';
|
|
9
9
|
import { IModelService } from 'vscode/vscode/vs/editor/common/services/model';
|
|
10
|
-
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
|
|
11
|
-
import { IEnvironmentService } from 'vscode/vscode/vs/platform/environment/common/environment';
|
|
12
|
-
import { IExtensionResourceLoaderService } from 'vscode/vscode/vs/platform/extensionResourceLoader/common/extensionResourceLoader';
|
|
13
|
-
import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification';
|
|
14
|
-
import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
|
|
10
|
+
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
|
|
11
|
+
import { IEnvironmentService } from 'vscode/vscode/vs/platform/environment/common/environment.service';
|
|
12
|
+
import { IExtensionResourceLoaderService } from 'vscode/vscode/vs/platform/extensionResourceLoader/common/extensionResourceLoader.service';
|
|
13
|
+
import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification.service';
|
|
14
|
+
import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry.service';
|
|
15
15
|
import { TextMateWorkerTokenizerController } from './textMateWorkerTokenizerController.js';
|
|
16
16
|
|
|
17
17
|
var ThreadedBackgroundTokenizerFactory_1;
|
package/vscode/src/vs/workbench/services/textMate/browser/textMateTokenizationFeatureImpl.js
CHANGED
|
@@ -16,20 +16,20 @@ import { LazyTokenizationSupport, TokenizationRegistry } from 'vscode/vscode/vs/
|
|
|
16
16
|
import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
|
|
17
17
|
import { generateTokensCSSForColorMap } from 'vscode/vscode/vs/editor/common/languages/supports/tokenization';
|
|
18
18
|
import { localizeWithPath } from 'vscode/vscode/vs/nls';
|
|
19
|
-
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
|
|
20
|
-
import { IExtensionResourceLoaderService } from 'vscode/vscode/vs/platform/extensionResourceLoader/common/extensionResourceLoader';
|
|
19
|
+
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration.service';
|
|
20
|
+
import { IExtensionResourceLoaderService } from 'vscode/vscode/vs/platform/extensionResourceLoader/common/extensionResourceLoader.service';
|
|
21
21
|
import { IInstantiationService } from 'vscode/vscode/vs/platform/instantiation/common/instantiation';
|
|
22
|
-
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
23
|
-
import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification';
|
|
24
|
-
import { IProgressService } from 'vscode/vscode/vs/platform/progress/common/progress';
|
|
25
|
-
import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
|
|
26
|
-
import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService';
|
|
22
|
+
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log.service';
|
|
23
|
+
import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification.service';
|
|
24
|
+
import { IProgressService } from 'vscode/vscode/vs/platform/progress/common/progress.service';
|
|
25
|
+
import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry.service';
|
|
26
|
+
import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService.service';
|
|
27
27
|
import { TextMateTokenizationSupport } from './tokenizationSupport/textMateTokenizationSupport.js';
|
|
28
28
|
import { TokenizationSupportWithLineLimit } from './tokenizationSupport/tokenizationSupportWithLineLimit.js';
|
|
29
29
|
import { ThreadedBackgroundTokenizerFactory } from './backgroundTokenization/threadedBackgroundTokenizerFactory.js';
|
|
30
30
|
import { TMGrammarFactory, missingTMGrammarErrorMessage } from '../common/TMGrammarFactory.js';
|
|
31
31
|
import { grammarsExtPoint } from 'vscode/vscode/vs/workbench/services/textMate/common/TMGrammars';
|
|
32
|
-
import { IWorkbenchThemeService } from 'vscode/vscode/vs/workbench/services/themes/common/workbenchThemeService';
|
|
32
|
+
import { IWorkbenchThemeService } from 'vscode/vscode/vs/workbench/services/themes/common/workbenchThemeService.service';
|
|
33
33
|
import * as vscodeTextmate from 'vscode-textmate';
|
|
34
34
|
import * as vscodeOniguruma from 'vscode-oniguruma';
|
|
35
35
|
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
|
|
108
|
+
export { ThemeRule, findMatchingThemeRule };
|