@codingame/monaco-vscode-api 1.69.24 → 1.76.0-next.2
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 +1 -3
- package/dist/_.contribution.js +3 -3
- package/dist/api.js +63 -31
- package/dist/async.js +9 -9
- package/dist/configuration.d.ts +109 -21
- package/dist/configuration.js +47 -217
- package/dist/{workspace.js → contextkey.js} +26 -47
- package/dist/dialogs.js +498 -426
- package/dist/extHost.js +1884 -909
- package/dist/files.js +65 -63
- package/dist/keybindings.d.ts +24 -18
- package/dist/keybindings.js +475 -404
- package/dist/languageConfiguration.js +5 -5
- package/dist/languageService.js +11 -3
- package/dist/languages.d.ts +24 -7
- package/dist/languages.js +1 -1
- package/dist/layout.js +104 -166
- package/dist/missing-services.js +230 -77
- package/dist/modelEditor.d.ts +1 -5
- package/dist/modelEditor.js +32 -58
- package/dist/monaco.d.ts +303 -713
- package/dist/monaco.js +2 -2
- package/dist/notifications.js +95 -235
- package/dist/polyfill.js +2022 -1637
- package/dist/services.d.ts +8908 -8467
- package/dist/services.js +1 -1
- package/dist/services2.js +293 -113
- package/dist/snippets.d.ts +24 -7
- package/dist/snippets.js +11 -9
- package/dist/textmate.d.ts +114 -20
- package/dist/textmate.js +825 -453
- package/dist/theme.js +13 -14
- package/dist/tokenClassification.d.ts +24 -7
- package/dist/tokenClassification.js +1 -1
- package/dist/tokenClassificationRegistry.js +1 -1
- package/dist/tools.js +104 -28
- package/package.json +12 -19
- package/dist/messages.d.ts +0 -10
- package/dist/messages.js +0 -11
- package/dist/types.js +0 -46
package/dist/textmate.js
CHANGED
|
@@ -1,124 +1,470 @@
|
|
|
1
|
-
import { _ as __decorate, a as __param, E as Emitter } from './
|
|
1
|
+
import { _ as __decorate, a as __param, E as Emitter } from './contextkey.js';
|
|
2
2
|
import './polyfill.js';
|
|
3
|
-
import {
|
|
3
|
+
import { f as ITextMateTokenizationService } from './missing-services.js';
|
|
4
4
|
import { g as getExtensionPoint, a as ExtensionMessageCollector, c as consoleExtensionMessageHandler, o as onServicesInitialized, E as ExtensionsRegistry } from './tools.js';
|
|
5
|
-
import { l as languagesExtPoint } from './languageService.js';
|
|
6
|
-
import { localize } from 'monaco-editor/esm/vs/nls.js';
|
|
7
|
-
import { I as IWorkbenchThemeService } from './workbenchThemeService.js';
|
|
8
|
-
import { Disposable, dispose } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
|
|
9
|
-
import { joinPath, isEqualOrParent, isEqual } from 'monaco-editor/esm/vs/base/common/resources.js';
|
|
10
5
|
import { r as registerExtensionFile, g as getServiceOverride$1, I as IExtensionResourceLoaderService } from './files.js';
|
|
6
|
+
import { S as Services, l as IWorkbenchEnvironmentService } from './services2.js';
|
|
7
|
+
import { Disposable, DisposableStore, toDisposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
|
|
11
8
|
import { TokenizationRegistry, EncodedTokenizationResult } from 'monaco-editor/esm/vs/editor/common/languages.js';
|
|
12
9
|
import { TokenMetadata } from 'monaco-editor/esm/vs/editor/common/encodedTokenAttributes.js';
|
|
10
|
+
import { nullTokenizeEncoded } from 'monaco-editor/esm/vs/editor/common/languages/nullTokenize.js';
|
|
11
|
+
import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
|
|
12
|
+
import { equals, compareBy, numberComparator } from 'monaco-editor/esm/vs/base/common/arrays.js';
|
|
13
|
+
import { INITIAL, applyStateStackDiff } from 'vscode-textmate';
|
|
14
|
+
import { ContiguousGrowingArray } from 'monaco-editor/esm/vs/editor/common/model/textModelTokens.js';
|
|
15
|
+
import { ContiguousMultilineTokensBuilder } from 'monaco-editor/esm/vs/editor/common/tokens/contiguousMultilineTokensBuilder.js';
|
|
16
|
+
import { countEOL } from 'monaco-editor/esm/vs/editor/common/core/eolCounter.js';
|
|
17
|
+
import { createWebWorker } from 'monaco-editor/esm/vs/editor/browser/services/webWorker.js';
|
|
18
|
+
import { onUnexpectedError, BugIndicatingError } from 'monaco-editor/esm/vs/base/common/errors.js';
|
|
19
|
+
import { URI } from 'monaco-editor/esm/vs/base/common/uri.js';
|
|
20
|
+
import { IModelService } from 'monaco-editor/esm/vs/editor/common/services/model.js';
|
|
21
|
+
import { ILanguageConfigurationService } from 'monaco-editor/esm/vs/editor/common/languages/languageConfigurationRegistry.js';
|
|
22
|
+
import { ILanguageService } from 'monaco-editor/esm/vs/editor/common/languages/language.js';
|
|
23
|
+
import { IEnvironmentService } from 'monaco-editor/esm/vs/platform/environment/common/environment.js';
|
|
24
|
+
import { FileAccess } from 'monaco-editor/esm/vs/base/common/network.js';
|
|
25
|
+
import { isWeb } from 'monaco-editor/esm/vs/base/common/platform.js';
|
|
26
|
+
import { joinPath, isEqualOrParent, isEqual } from 'monaco-editor/esm/vs/base/common/resources.js';
|
|
27
|
+
import { l as languagesExtPoint } from './languageService.js';
|
|
28
|
+
import { localize } from 'monaco-editor/esm/vs/nls.js';
|
|
29
|
+
import { I as IWorkbenchThemeService } from './workbenchThemeService.js';
|
|
13
30
|
import { createStyleSheet } from 'monaco-editor/esm/vs/base/browser/dom.js';
|
|
14
|
-
import { onUnexpectedError } from 'monaco-editor/esm/vs/base/common/errors.js';
|
|
15
|
-
import { Color } from 'monaco-editor/esm/vs/base/common/color.js';
|
|
16
|
-
import { equals } from 'monaco-editor/esm/vs/base/common/arrays.js';
|
|
17
31
|
import { generateTokensCSSForColorMap } from 'monaco-editor/esm/vs/editor/common/languages/supports/tokenization.js';
|
|
18
|
-
import { isObject } from 'monaco-editor/esm/vs/base/common/types.js';
|
|
19
|
-
import { ILanguageService } from 'monaco-editor/esm/vs/editor/common/languages/language.js';
|
|
20
32
|
import { INotificationService } from 'monaco-editor/esm/vs/platform/notification/common/notification.js';
|
|
21
33
|
import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
|
|
22
|
-
import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
|
|
23
34
|
import { IProgressService } from 'monaco-editor/esm/vs/platform/progress/common/progress.js';
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
35
|
+
import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
|
|
36
|
+
import { isObject } from 'monaco-editor/esm/vs/base/common/types.js';
|
|
37
|
+
import { Color } from 'monaco-editor/esm/vs/base/common/color.js';
|
|
27
38
|
import { c as createInjectedClass } from './injection.js';
|
|
39
|
+
import { bj as DEFAULT_EXTENSION } from './extHost.js';
|
|
28
40
|
import { SyncDescriptor } from 'monaco-editor/esm/vs/platform/instantiation/common/descriptors.js';
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
41
|
+
const nodeModulesPath = 'vs/../../node_modules';
|
|
42
|
+
const nodeModulesAsarPath = 'vs/../../node_modules.asar';
|
|
43
|
+
const nodeModulesAsarUnpackedPath = 'vs/../../node_modules.asar.unpacked';
|
|
44
|
+
class TextMateTokenizationSupport extends Disposable {
|
|
45
|
+
constructor(_grammar, _initialState, _containsEmbeddedLanguages, _createBackgroundTokenizer) {
|
|
46
|
+
super();
|
|
47
|
+
this._grammar = _grammar;
|
|
48
|
+
this._initialState = _initialState;
|
|
49
|
+
this._containsEmbeddedLanguages = _containsEmbeddedLanguages;
|
|
50
|
+
this._createBackgroundTokenizer = _createBackgroundTokenizer;
|
|
51
|
+
this._seenLanguages = [];
|
|
52
|
+
this._onDidEncounterLanguage = this._register(( (new Emitter())));
|
|
53
|
+
this.onDidEncounterLanguage = this._onDidEncounterLanguage.event;
|
|
54
|
+
}
|
|
55
|
+
getInitialState() {
|
|
56
|
+
return this._initialState;
|
|
57
|
+
}
|
|
58
|
+
tokenize(line, hasEOL, state) {
|
|
59
|
+
throw new Error('Not supported!');
|
|
60
|
+
}
|
|
61
|
+
createBackgroundTokenizer(textModel, store) {
|
|
62
|
+
if (this._createBackgroundTokenizer) {
|
|
63
|
+
return this._createBackgroundTokenizer(textModel, store);
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
tokenizeEncoded(line, hasEOL, state) {
|
|
68
|
+
const textMateResult = this._grammar.tokenizeLine2(line, state, 500);
|
|
69
|
+
if (textMateResult.stoppedEarly) {
|
|
70
|
+
console.warn(`Time limit reached when tokenizing line: ${line.substring(0, 100)}`);
|
|
71
|
+
return (
|
|
72
|
+
(new EncodedTokenizationResult(textMateResult.tokens, state))
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
if (this._containsEmbeddedLanguages) {
|
|
76
|
+
const seenLanguages = this._seenLanguages;
|
|
77
|
+
const tokens = textMateResult.tokens;
|
|
78
|
+
for (let i = 0, len = (tokens.length >>> 1); i < len; i++) {
|
|
79
|
+
const metadata = tokens[(i << 1) + 1];
|
|
80
|
+
const languageId = TokenMetadata.getLanguageId(metadata);
|
|
81
|
+
if (!seenLanguages[languageId]) {
|
|
82
|
+
seenLanguages[languageId] = true;
|
|
83
|
+
this._onDidEncounterLanguage.fire(languageId);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
let endState;
|
|
88
|
+
if (state.equals(textMateResult.ruleStack)) {
|
|
89
|
+
endState = state;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
endState = textMateResult.ruleStack;
|
|
93
|
+
}
|
|
94
|
+
return (
|
|
95
|
+
(new EncodedTokenizationResult(textMateResult.tokens, endState))
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
let TokenizationSupportWithLineLimit = class TokenizationSupportWithLineLimit {
|
|
100
|
+
constructor(_languageId, _encodedLanguageId, _actual, _configurationService) {
|
|
101
|
+
this._languageId = _languageId;
|
|
102
|
+
this._encodedLanguageId = _encodedLanguageId;
|
|
103
|
+
this._actual = _actual;
|
|
104
|
+
this._configurationService = _configurationService;
|
|
105
|
+
this._maxTokenizationLineLength = this._configurationService.getValue('editor.maxTokenizationLineLength', {
|
|
106
|
+
overrideIdentifier: this._languageId
|
|
107
|
+
});
|
|
108
|
+
this._configurationService.onDidChangeConfiguration(e => {
|
|
109
|
+
if (e.affectsConfiguration('editor.maxTokenizationLineLength')) {
|
|
110
|
+
this._maxTokenizationLineLength = this._configurationService.getValue('editor.maxTokenizationLineLength', {
|
|
111
|
+
overrideIdentifier: this._languageId
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
getInitialState() {
|
|
117
|
+
return this._actual.getInitialState();
|
|
118
|
+
}
|
|
119
|
+
tokenize(line, hasEOL, state) {
|
|
120
|
+
throw new Error('Not supported!');
|
|
121
|
+
}
|
|
122
|
+
tokenizeEncoded(line, hasEOL, state) {
|
|
123
|
+
if (line.length >= this._maxTokenizationLineLength) {
|
|
124
|
+
return nullTokenizeEncoded(this._encodedLanguageId, state);
|
|
125
|
+
}
|
|
126
|
+
return this._actual.tokenizeEncoded(line, hasEOL, state);
|
|
127
|
+
}
|
|
128
|
+
createBackgroundTokenizer(textModel, store) {
|
|
129
|
+
if (this._actual.createBackgroundTokenizer) {
|
|
130
|
+
return this._actual.createBackgroundTokenizer(textModel, store);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
TokenizationSupportWithLineLimit = ( (__decorate([
|
|
138
|
+
( (__param(3, IConfigurationService)))
|
|
139
|
+
], TokenizationSupportWithLineLimit)));
|
|
140
|
+
class ArrayEdit {
|
|
141
|
+
constructor(
|
|
142
|
+
edits) {
|
|
143
|
+
this.edits = edits.slice().sort(compareBy(c => c.offset, numberComparator));
|
|
144
|
+
}
|
|
145
|
+
applyTo(array) {
|
|
146
|
+
for (let i = this.edits.length - 1; i >= 0; i--) {
|
|
147
|
+
const c = this.edits[i];
|
|
148
|
+
array.delete(c.offset, c.length);
|
|
149
|
+
array.insert(c.offset, c.newLength);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
applyToArray(array) {
|
|
153
|
+
for (let i = this.edits.length - 1; i >= 0; i--) {
|
|
154
|
+
const c = this.edits[i];
|
|
155
|
+
array.splice(c.offset, c.length, ...( (new Array(c.newLength))));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
class SingleArrayEdit {
|
|
160
|
+
constructor(offset, length, newLength) {
|
|
161
|
+
this.offset = offset;
|
|
162
|
+
this.length = length;
|
|
163
|
+
this.newLength = newLength;
|
|
164
|
+
}
|
|
165
|
+
toString() {
|
|
166
|
+
return `[${this.offset}, +${this.length}) -> +${this.newLength}}`;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
class MonotonousIndexTransformer {
|
|
170
|
+
static fromMany(transformations) {
|
|
171
|
+
const transformers = transformations.map(t => ( (new MonotonousIndexTransformer(t))));
|
|
172
|
+
return (
|
|
173
|
+
(new CombinedIndexTransformer(transformers))
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
constructor(transformation) {
|
|
177
|
+
this.transformation = transformation;
|
|
178
|
+
this.idx = 0;
|
|
179
|
+
this.offset = 0;
|
|
180
|
+
}
|
|
181
|
+
transform(index) {
|
|
182
|
+
let nextChange = this.transformation.edits[this.idx];
|
|
183
|
+
while (nextChange && nextChange.offset + nextChange.length <= index) {
|
|
184
|
+
this.offset += nextChange.newLength - nextChange.length;
|
|
185
|
+
this.idx++;
|
|
186
|
+
nextChange = this.transformation.edits[this.idx];
|
|
187
|
+
}
|
|
188
|
+
if (nextChange && nextChange.offset <= index) {
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
return index + this.offset;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
class CombinedIndexTransformer {
|
|
195
|
+
constructor(transformers) {
|
|
196
|
+
this.transformers = transformers;
|
|
197
|
+
}
|
|
198
|
+
transform(index) {
|
|
199
|
+
for (const transformer of this.transformers) {
|
|
200
|
+
const result = transformer.transform(index);
|
|
201
|
+
if (result === undefined) {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
index = result;
|
|
205
|
+
}
|
|
206
|
+
return index;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
class TextMateWorkerTokenizerController extends Disposable {
|
|
210
|
+
constructor(_model, _worker, _languageIdCodec, _backgroundTokenizationStore, _initialState) {
|
|
211
|
+
super();
|
|
212
|
+
this._model = _model;
|
|
213
|
+
this._worker = _worker;
|
|
214
|
+
this._languageIdCodec = _languageIdCodec;
|
|
215
|
+
this._backgroundTokenizationStore = _backgroundTokenizationStore;
|
|
216
|
+
this._initialState = _initialState;
|
|
217
|
+
this._pendingChanges = [];
|
|
218
|
+
this._states = ( (new ContiguousGrowingArray(null)));
|
|
219
|
+
this._register(this._model.onDidChangeContent((e) => {
|
|
220
|
+
this._worker.acceptModelChanged(( (this._model.uri.toString())), e);
|
|
221
|
+
this._pendingChanges.push(e);
|
|
222
|
+
}));
|
|
223
|
+
this._register(this._model.onDidChangeLanguage((e) => {
|
|
224
|
+
const languageId = this._model.getLanguageId();
|
|
225
|
+
const encodedLanguageId = this._languageIdCodec.encodeLanguageId(languageId);
|
|
226
|
+
this._worker.acceptModelLanguageChanged(( (this._model.uri.toString())), languageId, encodedLanguageId);
|
|
227
|
+
}));
|
|
228
|
+
const languageId = this._model.getLanguageId();
|
|
229
|
+
const encodedLanguageId = this._languageIdCodec.encodeLanguageId(languageId);
|
|
230
|
+
this._worker.acceptNewModel({
|
|
231
|
+
uri: this._model.uri,
|
|
232
|
+
versionId: this._model.getVersionId(),
|
|
233
|
+
lines: this._model.getLinesContent(),
|
|
234
|
+
EOL: this._model.getEOL(),
|
|
235
|
+
languageId,
|
|
236
|
+
encodedLanguageId,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
dispose() {
|
|
240
|
+
super.dispose();
|
|
241
|
+
this._worker.acceptRemovedModel(( (this._model.uri.toString())));
|
|
242
|
+
}
|
|
243
|
+
setTokensAndStates(versionId, rawTokens, stateDeltas) {
|
|
244
|
+
while (this._pendingChanges.length > 0 &&
|
|
245
|
+
this._pendingChanges[0].versionId <= versionId) {
|
|
246
|
+
const change = this._pendingChanges.shift();
|
|
247
|
+
const op = lineArrayEditFromModelContentChange(change.changes);
|
|
248
|
+
op.applyTo(this._states);
|
|
249
|
+
}
|
|
250
|
+
let tokens = ContiguousMultilineTokensBuilder.deserialize(( (new Uint8Array(rawTokens))));
|
|
251
|
+
if (this._pendingChanges.length > 0) {
|
|
252
|
+
const curToFutureTransformerTokens = MonotonousIndexTransformer.fromMany(this._pendingChanges.map((c) => ( (new ArrayEdit(c.changes.map((c) => ( (new SingleArrayEdit(
|
|
253
|
+
c.range.startLineNumber - 1,
|
|
254
|
+
(c.range.endLineNumber - c.range.startLineNumber) + 1,
|
|
255
|
+
countEOL(c.text)[0] + 1
|
|
256
|
+
)))))))));
|
|
257
|
+
const b = ( (new ContiguousMultilineTokensBuilder()));
|
|
258
|
+
for (const t of tokens) {
|
|
259
|
+
for (let i = t.startLineNumber; i <= t.endLineNumber; i++) {
|
|
260
|
+
const result = curToFutureTransformerTokens.transform(i - 1);
|
|
261
|
+
if (result !== undefined) {
|
|
262
|
+
b.add(i, t.getLineTokens(i));
|
|
80
263
|
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
items: {
|
|
89
|
-
type: 'string'
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
tokens = b.finalize();
|
|
267
|
+
for (const change of this._pendingChanges) {
|
|
268
|
+
for (const innerChanges of change.changes) {
|
|
269
|
+
for (let j = 0; j < tokens.length; j++) {
|
|
270
|
+
tokens[j].applyEdit(innerChanges.range, innerChanges.text);
|
|
90
271
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
this._backgroundTokenizationStore.setTokens(tokens);
|
|
276
|
+
const curToFutureTransformerStates = MonotonousIndexTransformer.fromMany(this._pendingChanges.map((c) => lineArrayEditFromModelContentChange(c.changes)));
|
|
277
|
+
for (const d of stateDeltas) {
|
|
278
|
+
let prevState = d.startLineNumber <= 1 ? this._initialState : this._states.get(d.startLineNumber - 1 - 1);
|
|
279
|
+
for (let i = 0; i < d.stateDeltas.length; i++) {
|
|
280
|
+
const delta = d.stateDeltas[i];
|
|
281
|
+
const state = applyStateStackDiff(prevState, delta);
|
|
282
|
+
this._states.set(d.startLineNumber + i - 1, state);
|
|
283
|
+
const offset = curToFutureTransformerStates.transform(d.startLineNumber + i - 1);
|
|
284
|
+
if (offset !== undefined) {
|
|
285
|
+
this._backgroundTokenizationStore.setEndState(offset + 1, state);
|
|
286
|
+
}
|
|
287
|
+
if (d.startLineNumber + i >= this._model.getLineCount() - 1) {
|
|
288
|
+
this._backgroundTokenizationStore.backgroundTokenizationFinished();
|
|
289
|
+
}
|
|
290
|
+
prevState = state;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function lineArrayEditFromModelContentChange(c) {
|
|
296
|
+
return (
|
|
297
|
+
(new ArrayEdit(c.map((c) => ( (new SingleArrayEdit(
|
|
298
|
+
c.range.startLineNumber - 1,
|
|
299
|
+
c.range.endLineNumber - c.range.startLineNumber,
|
|
300
|
+
countEOL(c.text)[0]
|
|
301
|
+
))))))
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
let TextMateWorkerHost = class TextMateWorkerHost {
|
|
305
|
+
constructor(_extensionResourceLoaderService, _modelService, _languageConfigurationService, _configurationService, _languageService, _environmentService) {
|
|
306
|
+
this._extensionResourceLoaderService = _extensionResourceLoaderService;
|
|
307
|
+
this._modelService = _modelService;
|
|
308
|
+
this._languageConfigurationService = _languageConfigurationService;
|
|
309
|
+
this._configurationService = _configurationService;
|
|
310
|
+
this._languageService = _languageService;
|
|
311
|
+
this._environmentService = _environmentService;
|
|
312
|
+
this._workerProxyPromise = null;
|
|
313
|
+
this._worker = null;
|
|
314
|
+
this._workerProxy = null;
|
|
315
|
+
this._workerTokenizerControllers = ( (new Map()));
|
|
316
|
+
this._currentTheme = null;
|
|
317
|
+
this._currentTokenColorMap = null;
|
|
318
|
+
this._grammarDefinitions = [];
|
|
319
|
+
}
|
|
320
|
+
setGrammarDefinitions(grammarDefinitions) {
|
|
321
|
+
this._grammarDefinitions = grammarDefinitions;
|
|
322
|
+
this._killWorker();
|
|
323
|
+
}
|
|
324
|
+
dispose() {
|
|
325
|
+
this._killWorker();
|
|
326
|
+
}
|
|
327
|
+
acceptTheme(theme, colorMap) {
|
|
328
|
+
this._currentTheme = theme;
|
|
329
|
+
this._currentTokenColorMap = colorMap;
|
|
330
|
+
if (this._currentTheme && this._currentTokenColorMap && this._workerProxy) {
|
|
331
|
+
this._workerProxy.acceptTheme(this._currentTheme, this._currentTokenColorMap);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
getWorkerProxy() {
|
|
335
|
+
if (!this._workerProxyPromise) {
|
|
336
|
+
this._workerProxyPromise = this.createWorkerProxy();
|
|
337
|
+
}
|
|
338
|
+
return this._workerProxyPromise;
|
|
339
|
+
}
|
|
340
|
+
async createWorkerProxy() {
|
|
341
|
+
const textmateModuleLocation = `${nodeModulesPath}/vscode-textmate`;
|
|
342
|
+
const textmateModuleLocationAsar = `${nodeModulesAsarPath}/vscode-textmate`;
|
|
343
|
+
const onigurumaModuleLocation = `${nodeModulesPath}/vscode-oniguruma`;
|
|
344
|
+
const onigurumaModuleLocationAsar = `${nodeModulesAsarPath}/vscode-oniguruma`;
|
|
345
|
+
const useAsar = this._environmentService.isBuilt && !isWeb;
|
|
346
|
+
const textmateLocation = useAsar ? textmateModuleLocationAsar : textmateModuleLocation;
|
|
347
|
+
const onigurumaLocation = useAsar ? onigurumaModuleLocationAsar : onigurumaModuleLocation;
|
|
348
|
+
const textmateMain = `${textmateLocation}/release/main.js`;
|
|
349
|
+
const onigurumaMain = `${onigurumaLocation}/release/main.js`;
|
|
350
|
+
const onigurumaWASM = `${onigurumaLocation}/release/onig.wasm`;
|
|
351
|
+
const uri = ( (FileAccess.asBrowserUri(textmateMain).toString(true)));
|
|
352
|
+
const createData = {
|
|
353
|
+
grammarDefinitions: this._grammarDefinitions,
|
|
354
|
+
textmateMainUri: uri,
|
|
355
|
+
onigurumaMainUri: ( (FileAccess.asBrowserUri(onigurumaMain).toString(true))),
|
|
356
|
+
onigurumaWASMUri: ( (FileAccess.asBrowserUri(onigurumaWASM).toString(true))),
|
|
357
|
+
};
|
|
358
|
+
const worker = createWebWorker(this._modelService, this._languageConfigurationService, {
|
|
359
|
+
createData,
|
|
360
|
+
label: 'textMateWorker',
|
|
361
|
+
moduleId: 'vs/workbench/services/textMate/browser/worker/textMate.worker',
|
|
362
|
+
host: this,
|
|
363
|
+
});
|
|
364
|
+
this._worker = worker;
|
|
365
|
+
const proxy = await worker.getProxy();
|
|
366
|
+
if (this._worker !== worker) {
|
|
367
|
+
return null;
|
|
368
|
+
}
|
|
369
|
+
this._workerProxy = proxy;
|
|
370
|
+
if (this._currentTheme && this._currentTokenColorMap) {
|
|
371
|
+
this._workerProxy.acceptTheme(this._currentTheme, this._currentTokenColorMap);
|
|
372
|
+
}
|
|
373
|
+
return proxy;
|
|
374
|
+
}
|
|
375
|
+
_killWorker() {
|
|
376
|
+
for (const controller of ( (this._workerTokenizerControllers.values()))) {
|
|
377
|
+
controller.dispose();
|
|
378
|
+
}
|
|
379
|
+
this._workerTokenizerControllers.clear();
|
|
380
|
+
if (this._worker) {
|
|
381
|
+
this._worker.dispose();
|
|
382
|
+
this._worker = null;
|
|
383
|
+
}
|
|
384
|
+
this._workerProxy = null;
|
|
385
|
+
this._workerProxyPromise = null;
|
|
386
|
+
}
|
|
387
|
+
createBackgroundTokenizer(textModel, tokenStore) {
|
|
388
|
+
if (this._workerTokenizerControllers.has(( (textModel.uri.toString())))) {
|
|
389
|
+
throw new BugIndicatingError();
|
|
390
|
+
}
|
|
391
|
+
const shouldTokenizeAsync = this._configurationService.getValue('editor.experimental.asyncTokenization');
|
|
392
|
+
if (shouldTokenizeAsync !== true) {
|
|
393
|
+
return undefined;
|
|
394
|
+
}
|
|
395
|
+
if (textModel.isTooLargeForSyncing()) {
|
|
396
|
+
return undefined;
|
|
397
|
+
}
|
|
398
|
+
const store = ( (new DisposableStore()));
|
|
399
|
+
this.getWorkerProxy().then((workerProxy) => {
|
|
400
|
+
if (store.isDisposed || !workerProxy) {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
store.add(keepAliveWhenAttached(textModel, () => {
|
|
404
|
+
const controller = ( (new TextMateWorkerTokenizerController(
|
|
405
|
+
textModel,
|
|
406
|
+
workerProxy,
|
|
407
|
+
this._languageService.languageIdCodec,
|
|
408
|
+
tokenStore,
|
|
409
|
+
INITIAL
|
|
410
|
+
)));
|
|
411
|
+
this._workerTokenizerControllers.set(( (textModel.uri.toString())), controller);
|
|
412
|
+
return toDisposable(() => {
|
|
413
|
+
this._workerTokenizerControllers.delete(( (textModel.uri.toString())));
|
|
414
|
+
controller.dispose();
|
|
415
|
+
});
|
|
416
|
+
}));
|
|
417
|
+
});
|
|
418
|
+
return {
|
|
419
|
+
dispose() {
|
|
420
|
+
store.dispose();
|
|
114
421
|
},
|
|
115
|
-
|
|
422
|
+
requestTokens: (startLineNumber, endLineNumberExclusive) => {
|
|
423
|
+
this.getWorkerProxy().then((workerProxy) => {
|
|
424
|
+
workerProxy?.retokenize(( (textModel.uri.toString())), startLineNumber, endLineNumberExclusive);
|
|
425
|
+
});
|
|
426
|
+
},
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
async readFile(_resource) {
|
|
430
|
+
const resource = URI.revive(_resource);
|
|
431
|
+
return this._extensionResourceLoaderService.readExtensionResource(resource);
|
|
432
|
+
}
|
|
433
|
+
async setTokensAndStates(_resource, versionId, tokens, lineEndStateDeltas) {
|
|
434
|
+
const resource = URI.revive(_resource);
|
|
435
|
+
const controller = this._workerTokenizerControllers.get(( (resource.toString())));
|
|
436
|
+
if (controller) {
|
|
437
|
+
controller.setTokensAndStates(versionId, tokens, lineEndStateDeltas);
|
|
116
438
|
}
|
|
117
439
|
}
|
|
118
|
-
}
|
|
119
|
-
|
|
440
|
+
};
|
|
441
|
+
TextMateWorkerHost = ( (__decorate([
|
|
442
|
+
( (__param(0, IExtensionResourceLoaderService))),
|
|
443
|
+
( (__param(1, IModelService))),
|
|
444
|
+
( (__param(2, ILanguageConfigurationService))),
|
|
445
|
+
( (__param(3, IConfigurationService))),
|
|
446
|
+
( (__param(4, ILanguageService))),
|
|
447
|
+
( (__param(5, IEnvironmentService)))
|
|
448
|
+
], TextMateWorkerHost)));
|
|
449
|
+
function keepAliveWhenAttached(textModel, factory) {
|
|
450
|
+
const disposableStore = ( (new DisposableStore()));
|
|
451
|
+
const subStore = disposableStore.add(( (new DisposableStore())));
|
|
452
|
+
function checkAttached() {
|
|
453
|
+
if (textModel.isAttachedToEditor()) {
|
|
454
|
+
subStore.add(factory());
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
subStore.clear();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
checkAttached();
|
|
461
|
+
disposableStore.add(textModel.onDidChangeAttached(() => {
|
|
462
|
+
checkAttached();
|
|
463
|
+
}));
|
|
464
|
+
return disposableStore;
|
|
465
|
+
}
|
|
466
|
+
class TMScopeRegistry {
|
|
120
467
|
constructor() {
|
|
121
|
-
super();
|
|
122
468
|
this._scopeNameToLanguageRegistration = Object.create(null);
|
|
123
469
|
}
|
|
124
470
|
reset() {
|
|
@@ -145,7 +491,7 @@ class TMGrammarFactory extends Disposable {
|
|
|
145
491
|
super();
|
|
146
492
|
this._host = host;
|
|
147
493
|
this._initialState = vscodeTextmate.INITIAL;
|
|
148
|
-
this._scopeRegistry =
|
|
494
|
+
this._scopeRegistry = ( (new TMScopeRegistry()));
|
|
149
495
|
this._injections = {};
|
|
150
496
|
this._injectedEmbeddedLanguages = {};
|
|
151
497
|
this._languageToScope = ( (new Map()));
|
|
@@ -236,73 +582,114 @@ class TMGrammarFactory extends Disposable {
|
|
|
236
582
|
embeddedLanguages,
|
|
237
583
|
tokenTypes: grammarDefinition.tokenTypes,
|
|
238
584
|
balancedBracketSelectors: grammarDefinition.balancedBracketSelectors,
|
|
239
|
-
unbalancedBracketSelectors: grammarDefinition.unbalancedBracketSelectors,
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
catch (err) {
|
|
243
|
-
if (err.message && err.message.startsWith('No grammar provided for')) {
|
|
244
|
-
throw new Error(missingTMGrammarErrorMessage);
|
|
245
|
-
}
|
|
246
|
-
throw err;
|
|
247
|
-
}
|
|
248
|
-
return {
|
|
249
|
-
languageId: languageId,
|
|
250
|
-
grammar: grammar,
|
|
251
|
-
initialState: this._initialState,
|
|
252
|
-
containsEmbeddedLanguages: containsEmbeddedLanguages
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
class TMTokenization extends Disposable {
|
|
257
|
-
constructor(grammar, initialState, containsEmbeddedLanguages) {
|
|
258
|
-
super();
|
|
259
|
-
this._onDidEncounterLanguage = this._register(( (new Emitter())));
|
|
260
|
-
this.onDidEncounterLanguage = this._onDidEncounterLanguage.event;
|
|
261
|
-
this._grammar = grammar;
|
|
262
|
-
this._initialState = initialState;
|
|
263
|
-
this._containsEmbeddedLanguages = containsEmbeddedLanguages;
|
|
264
|
-
this._seenLanguages = [];
|
|
265
|
-
}
|
|
266
|
-
getInitialState() {
|
|
267
|
-
return this._initialState;
|
|
268
|
-
}
|
|
269
|
-
tokenize(line, hasEOL, state) {
|
|
270
|
-
throw new Error('Not supported!');
|
|
271
|
-
}
|
|
272
|
-
tokenizeEncoded(line, hasEOL, state) {
|
|
273
|
-
const textMateResult = this._grammar.tokenizeLine2(line, state, 500);
|
|
274
|
-
if (textMateResult.stoppedEarly) {
|
|
275
|
-
console.warn(`Time limit reached when tokenizing line: ${line.substring(0, 100)}`);
|
|
276
|
-
return (
|
|
277
|
-
(new EncodedTokenizationResult(textMateResult.tokens, state))
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
if (this._containsEmbeddedLanguages) {
|
|
281
|
-
const seenLanguages = this._seenLanguages;
|
|
282
|
-
const tokens = textMateResult.tokens;
|
|
283
|
-
for (let i = 0, len = (tokens.length >>> 1); i < len; i++) {
|
|
284
|
-
const metadata = tokens[(i << 1) + 1];
|
|
285
|
-
const languageId = TokenMetadata.getLanguageId(metadata);
|
|
286
|
-
if (!seenLanguages[languageId]) {
|
|
287
|
-
seenLanguages[languageId] = true;
|
|
288
|
-
this._onDidEncounterLanguage.fire(languageId);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
let endState;
|
|
293
|
-
if (state.equals(textMateResult.ruleStack)) {
|
|
294
|
-
endState = state;
|
|
585
|
+
unbalancedBracketSelectors: grammarDefinition.unbalancedBracketSelectors,
|
|
586
|
+
});
|
|
295
587
|
}
|
|
296
|
-
|
|
297
|
-
|
|
588
|
+
catch (err) {
|
|
589
|
+
if (err.message && err.message.startsWith('No grammar provided for')) {
|
|
590
|
+
throw new Error(missingTMGrammarErrorMessage);
|
|
591
|
+
}
|
|
592
|
+
throw err;
|
|
298
593
|
}
|
|
299
|
-
return
|
|
300
|
-
|
|
301
|
-
|
|
594
|
+
return {
|
|
595
|
+
languageId: languageId,
|
|
596
|
+
grammar: grammar,
|
|
597
|
+
initialState: this._initialState,
|
|
598
|
+
containsEmbeddedLanguages: containsEmbeddedLanguages
|
|
599
|
+
};
|
|
302
600
|
}
|
|
303
601
|
}
|
|
304
|
-
|
|
305
|
-
|
|
602
|
+
const grammarsExtPoint = ( (ExtensionsRegistry.registerExtensionPoint({
|
|
603
|
+
extensionPoint: 'grammars',
|
|
604
|
+
deps: [languagesExtPoint],
|
|
605
|
+
jsonSchema: {
|
|
606
|
+
description: ( (localize(
|
|
607
|
+
'vscode.extension.contributes.grammars',
|
|
608
|
+
'Contributes textmate tokenizers.'
|
|
609
|
+
))),
|
|
610
|
+
type: 'array',
|
|
611
|
+
defaultSnippets: [{ body: [{ language: '${1:id}', scopeName: 'source.${2:id}', path: './syntaxes/${3:id}.tmLanguage.' }] }],
|
|
612
|
+
items: {
|
|
613
|
+
type: 'object',
|
|
614
|
+
defaultSnippets: [{ body: { language: '${1:id}', scopeName: 'source.${2:id}', path: './syntaxes/${3:id}.tmLanguage.' } }],
|
|
615
|
+
properties: {
|
|
616
|
+
language: {
|
|
617
|
+
description: ( (localize(
|
|
618
|
+
'vscode.extension.contributes.grammars.language',
|
|
619
|
+
'Language identifier for which this syntax is contributed to.'
|
|
620
|
+
))),
|
|
621
|
+
type: 'string'
|
|
622
|
+
},
|
|
623
|
+
scopeName: {
|
|
624
|
+
description: ( (localize(
|
|
625
|
+
'vscode.extension.contributes.grammars.scopeName',
|
|
626
|
+
'Textmate scope name used by the tmLanguage file.'
|
|
627
|
+
))),
|
|
628
|
+
type: 'string'
|
|
629
|
+
},
|
|
630
|
+
path: {
|
|
631
|
+
description: ( (localize(
|
|
632
|
+
'vscode.extension.contributes.grammars.path',
|
|
633
|
+
'Path of the tmLanguage file. The path is relative to the extension folder and typically starts with \'./syntaxes/\'.'
|
|
634
|
+
))),
|
|
635
|
+
type: 'string'
|
|
636
|
+
},
|
|
637
|
+
embeddedLanguages: {
|
|
638
|
+
description: ( (localize(
|
|
639
|
+
'vscode.extension.contributes.grammars.embeddedLanguages',
|
|
640
|
+
'A map of scope name to language id if this grammar contains embedded languages.'
|
|
641
|
+
))),
|
|
642
|
+
type: 'object'
|
|
643
|
+
},
|
|
644
|
+
tokenTypes: {
|
|
645
|
+
description: ( (localize(
|
|
646
|
+
'vscode.extension.contributes.grammars.tokenTypes',
|
|
647
|
+
'A map of scope name to token types.'
|
|
648
|
+
))),
|
|
649
|
+
type: 'object',
|
|
650
|
+
additionalProperties: {
|
|
651
|
+
enum: ['string', 'comment', 'other']
|
|
652
|
+
}
|
|
653
|
+
},
|
|
654
|
+
injectTo: {
|
|
655
|
+
description: ( (localize(
|
|
656
|
+
'vscode.extension.contributes.grammars.injectTo',
|
|
657
|
+
'List of language scope names to which this grammar is injected to.'
|
|
658
|
+
))),
|
|
659
|
+
type: 'array',
|
|
660
|
+
items: {
|
|
661
|
+
type: 'string'
|
|
662
|
+
}
|
|
663
|
+
},
|
|
664
|
+
balancedBracketScopes: {
|
|
665
|
+
description: ( (localize(
|
|
666
|
+
'vscode.extension.contributes.grammars.balancedBracketScopes',
|
|
667
|
+
'Defines which scope names contain balanced brackets.'
|
|
668
|
+
))),
|
|
669
|
+
type: 'array',
|
|
670
|
+
items: {
|
|
671
|
+
type: 'string'
|
|
672
|
+
},
|
|
673
|
+
default: ['*'],
|
|
674
|
+
},
|
|
675
|
+
unbalancedBracketScopes: {
|
|
676
|
+
description: ( (localize(
|
|
677
|
+
'vscode.extension.contributes.grammars.unbalancedBracketScopes',
|
|
678
|
+
'Defines which scope names do not contain balanced brackets.'
|
|
679
|
+
))),
|
|
680
|
+
type: 'array',
|
|
681
|
+
items: {
|
|
682
|
+
type: 'string'
|
|
683
|
+
},
|
|
684
|
+
default: [],
|
|
685
|
+
},
|
|
686
|
+
},
|
|
687
|
+
required: ['scopeName', 'path']
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
})));
|
|
691
|
+
let TextMateTokenizationFeature = class TextMateTokenizationFeature extends Disposable {
|
|
692
|
+
constructor(_languageService, _themeService, _extensionResourceLoaderService, _notificationService, _logService, _configurationService, _progressService, _environmentService, _instantiationService) {
|
|
306
693
|
super();
|
|
307
694
|
this._languageService = _languageService;
|
|
308
695
|
this._themeService = _themeService;
|
|
@@ -311,108 +698,120 @@ let AbstractTextMateService = class AbstractTextMateService extends Disposable {
|
|
|
311
698
|
this._logService = _logService;
|
|
312
699
|
this._configurationService = _configurationService;
|
|
313
700
|
this._progressService = _progressService;
|
|
701
|
+
this._environmentService = _environmentService;
|
|
702
|
+
this._instantiationService = _instantiationService;
|
|
314
703
|
this._onDidEncounterLanguage = this._register(( (new Emitter())));
|
|
315
704
|
this.onDidEncounterLanguage = this._onDidEncounterLanguage.event;
|
|
316
|
-
this._vscodeOniguruma = null;
|
|
317
|
-
this._styleElement = createStyleSheet();
|
|
318
|
-
this._styleElement.className = 'vscode-tokens-styles';
|
|
319
705
|
this._createdModes = [];
|
|
320
706
|
this._encounteredLanguages = [];
|
|
321
707
|
this._debugMode = false;
|
|
322
708
|
this._debugModePrintFunc = () => { };
|
|
323
709
|
this._grammarDefinitions = null;
|
|
324
710
|
this._grammarFactory = null;
|
|
325
|
-
this._tokenizersRegistrations =
|
|
711
|
+
this._tokenizersRegistrations = ( (new DisposableStore()));
|
|
326
712
|
this._currentTheme = null;
|
|
327
713
|
this._currentTokenColorMap = null;
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
this._tokenizersRegistrations = dispose(this._tokenizersRegistrations);
|
|
336
|
-
this._grammarDefinitions = [];
|
|
337
|
-
for (const extension of extensions) {
|
|
338
|
-
const grammars = extension.value;
|
|
339
|
-
for (const grammar of grammars) {
|
|
340
|
-
if (!this._validateGrammarExtensionPoint(extension.description.extensionLocation, grammar, extension.collector)) {
|
|
341
|
-
continue;
|
|
342
|
-
}
|
|
343
|
-
const grammarLocation = joinPath(extension.description.extensionLocation, grammar.path);
|
|
344
|
-
const embeddedLanguages = Object.create(null);
|
|
345
|
-
if (grammar.embeddedLanguages) {
|
|
346
|
-
const scopes = ( (Object.keys(grammar.embeddedLanguages)));
|
|
347
|
-
for (let i = 0, len = scopes.length; i < len; i++) {
|
|
348
|
-
const scope = scopes[i];
|
|
349
|
-
const language = grammar.embeddedLanguages[scope];
|
|
350
|
-
if (typeof language !== 'string') {
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
if (this._languageService.isRegisteredLanguageId(language)) {
|
|
354
|
-
embeddedLanguages[scope] = this._languageService.languageIdCodec.encodeLanguageId(language);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
const tokenTypes = Object.create(null);
|
|
359
|
-
if (grammar.tokenTypes) {
|
|
360
|
-
const scopes = ( (Object.keys(grammar.tokenTypes)));
|
|
361
|
-
for (const scope of scopes) {
|
|
362
|
-
const tokenType = grammar.tokenTypes[scope];
|
|
363
|
-
switch (tokenType) {
|
|
364
|
-
case 'string':
|
|
365
|
-
tokenTypes[scope] = 2 ;
|
|
366
|
-
break;
|
|
367
|
-
case 'other':
|
|
368
|
-
tokenTypes[scope] = 0 ;
|
|
369
|
-
break;
|
|
370
|
-
case 'comment':
|
|
371
|
-
tokenTypes[scope] = 1 ;
|
|
372
|
-
break;
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
let validLanguageId = null;
|
|
377
|
-
if (grammar.language && this._languageService.isRegisteredLanguageId(grammar.language)) {
|
|
378
|
-
validLanguageId = grammar.language;
|
|
379
|
-
}
|
|
380
|
-
function asStringArray(array, defaultValue) {
|
|
381
|
-
if (!Array.isArray(array)) {
|
|
382
|
-
return defaultValue;
|
|
383
|
-
}
|
|
384
|
-
if (!array.every(e => typeof e === 'string')) {
|
|
385
|
-
return defaultValue;
|
|
386
|
-
}
|
|
387
|
-
return array;
|
|
388
|
-
}
|
|
389
|
-
this._grammarDefinitions.push({
|
|
390
|
-
location: grammarLocation,
|
|
391
|
-
language: validLanguageId ? validLanguageId : undefined,
|
|
392
|
-
scopeName: grammar.scopeName,
|
|
393
|
-
embeddedLanguages: embeddedLanguages,
|
|
394
|
-
tokenTypes: tokenTypes,
|
|
395
|
-
injectTo: grammar.injectTo,
|
|
396
|
-
balancedBracketSelectors: asStringArray(grammar.balancedBracketScopes, ['*']),
|
|
397
|
-
unbalancedBracketSelectors: asStringArray(grammar.unbalancedBracketScopes, []),
|
|
398
|
-
});
|
|
399
|
-
if (validLanguageId) {
|
|
400
|
-
this._tokenizersRegistrations.push(TokenizationRegistry.registerFactory(validLanguageId, this._createFactory(validLanguageId)));
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
for (const createMode of this._createdModes) {
|
|
405
|
-
TokenizationRegistry.getOrCreate(createMode);
|
|
406
|
-
}
|
|
407
|
-
});
|
|
408
|
-
this._updateTheme(this._grammarFactory, this._themeService.getColorTheme(), true);
|
|
714
|
+
this._workerHost = this._instantiationService.createInstance(TextMateWorkerHost);
|
|
715
|
+
this._vscodeOniguruma = null;
|
|
716
|
+
this._styleElement = createStyleSheet();
|
|
717
|
+
this._styleElement.className = 'vscode-tokens-styles';
|
|
718
|
+
grammarsExtPoint.setHandler((extensions) => this.handleGrammarsExtPoint(extensions));
|
|
719
|
+
this._updateTheme(this._themeService.getColorTheme(), true);
|
|
409
720
|
this._register(this._themeService.onDidColorThemeChange(() => {
|
|
410
|
-
this._updateTheme(this.
|
|
721
|
+
this._updateTheme(this._themeService.getColorTheme(), false);
|
|
411
722
|
}));
|
|
412
723
|
this._languageService.onDidEncounterLanguage((languageId) => {
|
|
413
724
|
this._createdModes.push(languageId);
|
|
414
725
|
});
|
|
415
726
|
}
|
|
727
|
+
handleGrammarsExtPoint(extensions) {
|
|
728
|
+
this._grammarDefinitions = null;
|
|
729
|
+
if (this._grammarFactory) {
|
|
730
|
+
this._grammarFactory.dispose();
|
|
731
|
+
this._grammarFactory = null;
|
|
732
|
+
}
|
|
733
|
+
this._tokenizersRegistrations.clear();
|
|
734
|
+
this._grammarDefinitions = [];
|
|
735
|
+
for (const extension of extensions) {
|
|
736
|
+
const grammars = extension.value;
|
|
737
|
+
for (const grammar of grammars) {
|
|
738
|
+
const def = this.createValidGrammarDefinition(extension, grammar);
|
|
739
|
+
if (def) {
|
|
740
|
+
this._grammarDefinitions.push(def);
|
|
741
|
+
if (def.language) {
|
|
742
|
+
this._tokenizersRegistrations.add(TokenizationRegistry.registerFactory(def.language, {
|
|
743
|
+
createTokenizationSupport: async () => this.createTokenizationSupport(def.language)
|
|
744
|
+
}));
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
this._workerHost.setGrammarDefinitions(this._grammarDefinitions);
|
|
750
|
+
for (const createdMode of this._createdModes) {
|
|
751
|
+
TokenizationRegistry.getOrCreate(createdMode);
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
createValidGrammarDefinition(extension, grammar) {
|
|
755
|
+
if (!validateGrammarExtensionPoint(extension.description.extensionLocation, grammar, extension.collector, this._languageService)) {
|
|
756
|
+
return null;
|
|
757
|
+
}
|
|
758
|
+
const grammarLocation = joinPath(extension.description.extensionLocation, grammar.path);
|
|
759
|
+
const embeddedLanguages = Object.create(null);
|
|
760
|
+
if (grammar.embeddedLanguages) {
|
|
761
|
+
const scopes = ( (Object.keys(grammar.embeddedLanguages)));
|
|
762
|
+
for (let i = 0, len = scopes.length; i < len; i++) {
|
|
763
|
+
const scope = scopes[i];
|
|
764
|
+
const language = grammar.embeddedLanguages[scope];
|
|
765
|
+
if (typeof language !== 'string') {
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
if (this._languageService.isRegisteredLanguageId(language)) {
|
|
769
|
+
embeddedLanguages[scope] = this._languageService.languageIdCodec.encodeLanguageId(language);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
const tokenTypes = Object.create(null);
|
|
774
|
+
if (grammar.tokenTypes) {
|
|
775
|
+
const scopes = ( (Object.keys(grammar.tokenTypes)));
|
|
776
|
+
for (const scope of scopes) {
|
|
777
|
+
const tokenType = grammar.tokenTypes[scope];
|
|
778
|
+
switch (tokenType) {
|
|
779
|
+
case 'string':
|
|
780
|
+
tokenTypes[scope] = 2 ;
|
|
781
|
+
break;
|
|
782
|
+
case 'other':
|
|
783
|
+
tokenTypes[scope] = 0 ;
|
|
784
|
+
break;
|
|
785
|
+
case 'comment':
|
|
786
|
+
tokenTypes[scope] = 1 ;
|
|
787
|
+
break;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
let validLanguageId = null;
|
|
792
|
+
if (grammar.language && this._languageService.isRegisteredLanguageId(grammar.language)) {
|
|
793
|
+
validLanguageId = grammar.language;
|
|
794
|
+
}
|
|
795
|
+
function asStringArray(array, defaultValue) {
|
|
796
|
+
if (!Array.isArray(array)) {
|
|
797
|
+
return defaultValue;
|
|
798
|
+
}
|
|
799
|
+
if (!array.every(e => typeof e === 'string')) {
|
|
800
|
+
return defaultValue;
|
|
801
|
+
}
|
|
802
|
+
return array;
|
|
803
|
+
}
|
|
804
|
+
return {
|
|
805
|
+
location: grammarLocation,
|
|
806
|
+
language: validLanguageId || undefined,
|
|
807
|
+
scopeName: grammar.scopeName,
|
|
808
|
+
embeddedLanguages: embeddedLanguages,
|
|
809
|
+
tokenTypes: tokenTypes,
|
|
810
|
+
injectTo: grammar.injectTo,
|
|
811
|
+
balancedBracketSelectors: asStringArray(grammar.balancedBracketScopes, ['*']),
|
|
812
|
+
unbalancedBracketSelectors: asStringArray(grammar.unbalancedBracketScopes, []),
|
|
813
|
+
};
|
|
814
|
+
}
|
|
416
815
|
startDebugMode(printFn, onStop) {
|
|
417
816
|
if (this._debugMode) {
|
|
418
817
|
this._notificationService.error(( (localize('alreadyDebugging', "Already Logging."))));
|
|
@@ -451,7 +850,7 @@ let AbstractTextMateService = class AbstractTextMateService extends Disposable {
|
|
|
451
850
|
}
|
|
452
851
|
}
|
|
453
852
|
_canCreateGrammarFactory() {
|
|
454
|
-
return
|
|
853
|
+
return !!this._grammarDefinitions;
|
|
455
854
|
}
|
|
456
855
|
async _getOrCreateGrammarFactory() {
|
|
457
856
|
if (this._grammarFactory) {
|
|
@@ -470,162 +869,66 @@ let AbstractTextMateService = class AbstractTextMateService extends Disposable {
|
|
|
470
869
|
logError: (msg, err) => this._logService.error(msg, err),
|
|
471
870
|
readFile: (resource) => this._extensionResourceLoaderService.readExtensionResource(resource)
|
|
472
871
|
}, this._grammarDefinitions || [], vscodeTextmate, onigLib)));
|
|
473
|
-
this.
|
|
474
|
-
this._updateTheme(this._grammarFactory, this._themeService.getColorTheme(), true);
|
|
872
|
+
this._updateTheme(this._themeService.getColorTheme(), true);
|
|
475
873
|
return this._grammarFactory;
|
|
476
874
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
(new TMTokenizationSupportWithLineLimit(languageId, encodedLanguageId, tokenization, this._configurationService))
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
catch (err) {
|
|
509
|
-
if (err.message && err.message === missingTMGrammarErrorMessage) {
|
|
510
|
-
return null;
|
|
511
|
-
}
|
|
512
|
-
onUnexpectedError(err);
|
|
513
|
-
return null;
|
|
875
|
+
async createTokenizationSupport(languageId) {
|
|
876
|
+
if (!this._languageService.isRegisteredLanguageId(languageId)) {
|
|
877
|
+
return null;
|
|
878
|
+
}
|
|
879
|
+
if (!this._canCreateGrammarFactory()) {
|
|
880
|
+
return null;
|
|
881
|
+
}
|
|
882
|
+
try {
|
|
883
|
+
const grammarFactory = await this._getOrCreateGrammarFactory();
|
|
884
|
+
if (!grammarFactory.has(languageId)) {
|
|
885
|
+
return null;
|
|
886
|
+
}
|
|
887
|
+
const encodedLanguageId = this._languageService.languageIdCodec.encodeLanguageId(languageId);
|
|
888
|
+
const r = await grammarFactory.createGrammar(languageId, encodedLanguageId);
|
|
889
|
+
if (!r.grammar) {
|
|
890
|
+
return null;
|
|
891
|
+
}
|
|
892
|
+
const tokenization = ( (new TextMateTokenizationSupport(
|
|
893
|
+
r.grammar,
|
|
894
|
+
r.initialState,
|
|
895
|
+
r.containsEmbeddedLanguages,
|
|
896
|
+
(textModel, tokenStore) => this._workerHost.createBackgroundTokenizer(textModel, tokenStore)
|
|
897
|
+
)));
|
|
898
|
+
tokenization.onDidEncounterLanguage((encodedLanguageId) => {
|
|
899
|
+
if (!this._encounteredLanguages[encodedLanguageId]) {
|
|
900
|
+
const languageId = this._languageService.languageIdCodec.decodeLanguageId(encodedLanguageId);
|
|
901
|
+
this._encounteredLanguages[encodedLanguageId] = true;
|
|
902
|
+
this._onDidEncounterLanguage.fire(languageId);
|
|
514
903
|
}
|
|
904
|
+
});
|
|
905
|
+
return (
|
|
906
|
+
(new TokenizationSupportWithLineLimit(languageId, encodedLanguageId, tokenization, this._configurationService))
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
catch (err) {
|
|
910
|
+
if (err.message && err.message === missingTMGrammarErrorMessage) {
|
|
911
|
+
return null;
|
|
515
912
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
static _toColorMap(colorMap) {
|
|
519
|
-
const result = [null];
|
|
520
|
-
for (let i = 1, len = colorMap.length; i < len; i++) {
|
|
521
|
-
result[i] = ( (Color.fromHex(colorMap[i])));
|
|
913
|
+
onUnexpectedError(err);
|
|
914
|
+
return null;
|
|
522
915
|
}
|
|
523
|
-
return result;
|
|
524
916
|
}
|
|
525
|
-
_updateTheme(
|
|
526
|
-
if (!forceUpdate && this._currentTheme && this._currentTokenColorMap &&
|
|
917
|
+
_updateTheme(colorTheme, forceUpdate) {
|
|
918
|
+
if (!forceUpdate && this._currentTheme && this._currentTokenColorMap && equalsTokenRules(this._currentTheme.settings, colorTheme.tokenColors)
|
|
919
|
+
&& equals(this._currentTokenColorMap, colorTheme.tokenColorMap)) {
|
|
527
920
|
return;
|
|
528
921
|
}
|
|
529
922
|
this._currentTheme = { name: colorTheme.label, settings: colorTheme.tokenColors };
|
|
530
923
|
this._currentTokenColorMap = colorTheme.tokenColorMap;
|
|
531
|
-
this.
|
|
532
|
-
|
|
533
|
-
_doUpdateTheme(grammarFactory, theme, tokenColorMap) {
|
|
534
|
-
grammarFactory?.setTheme(theme, tokenColorMap);
|
|
535
|
-
const colorMap = AbstractTextMateService._toColorMap(tokenColorMap);
|
|
924
|
+
this._grammarFactory?.setTheme(this._currentTheme, this._currentTokenColorMap);
|
|
925
|
+
const colorMap = toColorMap(this._currentTokenColorMap);
|
|
536
926
|
const cssRules = generateTokensCSSForColorMap(colorMap);
|
|
537
927
|
this._styleElement.textContent = cssRules;
|
|
538
928
|
TokenizationRegistry.setColorMap(colorMap);
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
if (!b || !a || b.length !== a.length) {
|
|
542
|
-
return false;
|
|
543
|
-
}
|
|
544
|
-
for (let i = b.length - 1; i >= 0; i--) {
|
|
545
|
-
const r1 = b[i];
|
|
546
|
-
const r2 = a[i];
|
|
547
|
-
if (r1.scope !== r2.scope) {
|
|
548
|
-
return false;
|
|
549
|
-
}
|
|
550
|
-
const s1 = r1.settings;
|
|
551
|
-
const s2 = r2.settings;
|
|
552
|
-
if (s1 && s2) {
|
|
553
|
-
if (s1.fontStyle !== s2.fontStyle || s1.foreground !== s2.foreground || s1.background !== s2.background) {
|
|
554
|
-
return false;
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
else if (!s1 || !s2) {
|
|
558
|
-
return false;
|
|
559
|
-
}
|
|
560
|
-
}
|
|
561
|
-
return true;
|
|
562
|
-
}
|
|
563
|
-
_validateGrammarExtensionPoint(extensionLocation, syntax, collector) {
|
|
564
|
-
if (syntax.language && ((typeof syntax.language !== 'string') || !this._languageService.isRegisteredLanguageId(syntax.language))) {
|
|
565
|
-
collector.error(( (localize(
|
|
566
|
-
'invalid.language',
|
|
567
|
-
"Unknown language in `contributes.{0}.language`. Provided value: {1}",
|
|
568
|
-
grammarsExtPoint.name,
|
|
569
|
-
String(syntax.language)
|
|
570
|
-
))));
|
|
571
|
-
return false;
|
|
572
|
-
}
|
|
573
|
-
if (!syntax.scopeName || (typeof syntax.scopeName !== 'string')) {
|
|
574
|
-
collector.error(( (localize(
|
|
575
|
-
'invalid.scopeName',
|
|
576
|
-
"Expected string in `contributes.{0}.scopeName`. Provided value: {1}",
|
|
577
|
-
grammarsExtPoint.name,
|
|
578
|
-
String(syntax.scopeName)
|
|
579
|
-
))));
|
|
580
|
-
return false;
|
|
581
|
-
}
|
|
582
|
-
if (!syntax.path || (typeof syntax.path !== 'string')) {
|
|
583
|
-
collector.error(( (localize(
|
|
584
|
-
'invalid.path.0',
|
|
585
|
-
"Expected string in `contributes.{0}.path`. Provided value: {1}",
|
|
586
|
-
grammarsExtPoint.name,
|
|
587
|
-
String(syntax.path)
|
|
588
|
-
))));
|
|
589
|
-
return false;
|
|
590
|
-
}
|
|
591
|
-
if (syntax.injectTo && (!Array.isArray(syntax.injectTo) || syntax.injectTo.some(scope => typeof scope !== 'string'))) {
|
|
592
|
-
collector.error(( (localize(
|
|
593
|
-
'invalid.injectTo',
|
|
594
|
-
"Invalid value in `contributes.{0}.injectTo`. Must be an array of language scope names. Provided value: {1}",
|
|
595
|
-
grammarsExtPoint.name,
|
|
596
|
-
JSON.stringify(syntax.injectTo)
|
|
597
|
-
))));
|
|
598
|
-
return false;
|
|
599
|
-
}
|
|
600
|
-
if (syntax.embeddedLanguages && !isObject(syntax.embeddedLanguages)) {
|
|
601
|
-
collector.error(( (localize(
|
|
602
|
-
'invalid.embeddedLanguages',
|
|
603
|
-
"Invalid value in `contributes.{0}.embeddedLanguages`. Must be an object map from scope name to language. Provided value: {1}",
|
|
604
|
-
grammarsExtPoint.name,
|
|
605
|
-
JSON.stringify(syntax.embeddedLanguages)
|
|
606
|
-
))));
|
|
607
|
-
return false;
|
|
608
|
-
}
|
|
609
|
-
if (syntax.tokenTypes && !isObject(syntax.tokenTypes)) {
|
|
610
|
-
collector.error(( (localize(
|
|
611
|
-
'invalid.tokenTypes',
|
|
612
|
-
"Invalid value in `contributes.{0}.tokenTypes`. Must be an object map from scope name to token type. Provided value: {1}",
|
|
613
|
-
grammarsExtPoint.name,
|
|
614
|
-
JSON.stringify(syntax.tokenTypes)
|
|
615
|
-
))));
|
|
616
|
-
return false;
|
|
617
|
-
}
|
|
618
|
-
const grammarLocation = joinPath(extensionLocation, syntax.path);
|
|
619
|
-
if (!isEqualOrParent(grammarLocation, extensionLocation)) {
|
|
620
|
-
collector.warn(( (localize(
|
|
621
|
-
'invalid.path.1',
|
|
622
|
-
"Expected `contributes.{0}.path` ({1}) to be included inside extension's folder ({2}). This might make the extension non-portable.",
|
|
623
|
-
grammarsExtPoint.name,
|
|
624
|
-
grammarLocation.path,
|
|
625
|
-
extensionLocation.path
|
|
626
|
-
))));
|
|
929
|
+
if (this._currentTheme && this._currentTokenColorMap) {
|
|
930
|
+
this._workerHost.acceptTheme(this._currentTheme, this._currentTokenColorMap);
|
|
627
931
|
}
|
|
628
|
-
return true;
|
|
629
932
|
}
|
|
630
933
|
async createGrammar(languageId) {
|
|
631
934
|
if (!this._languageService.isRegisteredLanguageId(languageId)) {
|
|
@@ -639,82 +942,151 @@ let AbstractTextMateService = class AbstractTextMateService extends Disposable {
|
|
|
639
942
|
const { grammar } = await grammarFactory.createGrammar(languageId, encodedLanguageId);
|
|
640
943
|
return grammar;
|
|
641
944
|
}
|
|
642
|
-
_onDidCreateGrammarFactory(grammarDefinitions) {
|
|
643
|
-
}
|
|
644
|
-
_onDidDisposeGrammarFactory() {
|
|
645
|
-
}
|
|
646
945
|
_getVSCodeOniguruma() {
|
|
647
946
|
if (!this._vscodeOniguruma) {
|
|
648
|
-
this._vscodeOniguruma =
|
|
947
|
+
this._vscodeOniguruma = (async () => {
|
|
948
|
+
const [vscodeOniguruma, wasm] = await Promise.all([import('vscode-oniguruma').then(module => module.default ?? module), this._loadVSCodeOnigurumaWASM()]);
|
|
949
|
+
await vscodeOniguruma.loadWASM({
|
|
950
|
+
data: wasm,
|
|
951
|
+
print: (str) => {
|
|
952
|
+
this._debugModePrintFunc(str);
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
return vscodeOniguruma;
|
|
956
|
+
})();
|
|
649
957
|
}
|
|
650
958
|
return this._vscodeOniguruma;
|
|
651
959
|
}
|
|
652
|
-
async
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
960
|
+
async _loadVSCodeOnigurumaWASM() {
|
|
961
|
+
if (isWeb) {
|
|
962
|
+
const response = await fetch(( (FileAccess.asBrowserUri('vscode-oniguruma/../onig.wasm').toString(true))));
|
|
963
|
+
return await response.arrayBuffer();
|
|
964
|
+
}
|
|
965
|
+
else {
|
|
966
|
+
const response = await fetch(this._environmentService.isBuilt
|
|
967
|
+
? ( (FileAccess.asBrowserUri(`${nodeModulesAsarUnpackedPath}/vscode-oniguruma/release/onig.wasm`).toString(true)))
|
|
968
|
+
: ( (FileAccess.asBrowserUri(`${nodeModulesPath}/vscode-oniguruma/release/onig.wasm`).toString(true))));
|
|
969
|
+
return response;
|
|
970
|
+
}
|
|
662
971
|
}
|
|
663
972
|
};
|
|
664
|
-
|
|
973
|
+
TextMateTokenizationFeature = ( (__decorate([
|
|
665
974
|
( (__param(0, ILanguageService))),
|
|
666
975
|
( (__param(1, IWorkbenchThemeService))),
|
|
667
976
|
( (__param(2, IExtensionResourceLoaderService))),
|
|
668
977
|
( (__param(3, INotificationService))),
|
|
669
978
|
( (__param(4, ILogService))),
|
|
670
979
|
( (__param(5, IConfigurationService))),
|
|
671
|
-
( (__param(6, IProgressService)))
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
980
|
+
( (__param(6, IProgressService))),
|
|
981
|
+
( (__param(7, IWorkbenchEnvironmentService))),
|
|
982
|
+
( (__param(8, IInstantiationService)))
|
|
983
|
+
], TextMateTokenizationFeature)));
|
|
984
|
+
function toColorMap(colorMap) {
|
|
985
|
+
const result = [null];
|
|
986
|
+
for (let i = 1, len = colorMap.length; i < len; i++) {
|
|
987
|
+
result[i] = ( (Color.fromHex(colorMap[i])));
|
|
988
|
+
}
|
|
989
|
+
return result;
|
|
990
|
+
}
|
|
991
|
+
function equalsTokenRules(a, b) {
|
|
992
|
+
if (!b || !a || b.length !== a.length) {
|
|
993
|
+
return false;
|
|
994
|
+
}
|
|
995
|
+
for (let i = b.length - 1; i >= 0; i--) {
|
|
996
|
+
const r1 = b[i];
|
|
997
|
+
const r2 = a[i];
|
|
998
|
+
if (r1.scope !== r2.scope) {
|
|
999
|
+
return false;
|
|
1000
|
+
}
|
|
1001
|
+
const s1 = r1.settings;
|
|
1002
|
+
const s2 = r2.settings;
|
|
1003
|
+
if (s1 && s2) {
|
|
1004
|
+
if (s1.fontStyle !== s2.fontStyle || s1.foreground !== s2.foreground || s1.background !== s2.background) {
|
|
1005
|
+
return false;
|
|
687
1006
|
}
|
|
688
|
-
}
|
|
1007
|
+
}
|
|
1008
|
+
else if (!s1 || !s2) {
|
|
1009
|
+
return false;
|
|
1010
|
+
}
|
|
689
1011
|
}
|
|
690
|
-
|
|
691
|
-
|
|
1012
|
+
return true;
|
|
1013
|
+
}
|
|
1014
|
+
function validateGrammarExtensionPoint(extensionLocation, syntax, collector, _languageService) {
|
|
1015
|
+
if (syntax.language && ((typeof syntax.language !== 'string') || !_languageService.isRegisteredLanguageId(syntax.language))) {
|
|
1016
|
+
collector.error(( (localize(
|
|
1017
|
+
'invalid.language',
|
|
1018
|
+
"Unknown language in `contributes.{0}.language`. Provided value: {1}",
|
|
1019
|
+
grammarsExtPoint.name,
|
|
1020
|
+
String(syntax.language)
|
|
1021
|
+
))));
|
|
1022
|
+
return false;
|
|
692
1023
|
}
|
|
693
|
-
|
|
694
|
-
|
|
1024
|
+
if (!syntax.scopeName || (typeof syntax.scopeName !== 'string')) {
|
|
1025
|
+
collector.error(( (localize(
|
|
1026
|
+
'invalid.scopeName',
|
|
1027
|
+
"Expected string in `contributes.{0}.scopeName`. Provided value: {1}",
|
|
1028
|
+
grammarsExtPoint.name,
|
|
1029
|
+
String(syntax.scopeName)
|
|
1030
|
+
))));
|
|
1031
|
+
return false;
|
|
695
1032
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
1033
|
+
if (!syntax.path || (typeof syntax.path !== 'string')) {
|
|
1034
|
+
collector.error(( (localize(
|
|
1035
|
+
'invalid.path.0',
|
|
1036
|
+
"Expected string in `contributes.{0}.path`. Provided value: {1}",
|
|
1037
|
+
grammarsExtPoint.name,
|
|
1038
|
+
String(syntax.path)
|
|
1039
|
+
))));
|
|
1040
|
+
return false;
|
|
701
1041
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
1042
|
+
if (syntax.injectTo && (!Array.isArray(syntax.injectTo) || syntax.injectTo.some(scope => typeof scope !== 'string'))) {
|
|
1043
|
+
collector.error(( (localize(
|
|
1044
|
+
'invalid.injectTo',
|
|
1045
|
+
"Invalid value in `contributes.{0}.injectTo`. Must be an array of language scope names. Provided value: {1}",
|
|
1046
|
+
grammarsExtPoint.name,
|
|
1047
|
+
JSON.stringify(syntax.injectTo)
|
|
1048
|
+
))));
|
|
1049
|
+
return false;
|
|
1050
|
+
}
|
|
1051
|
+
if (syntax.embeddedLanguages && !isObject(syntax.embeddedLanguages)) {
|
|
1052
|
+
collector.error(( (localize(
|
|
1053
|
+
'invalid.embeddedLanguages',
|
|
1054
|
+
"Invalid value in `contributes.{0}.embeddedLanguages`. Must be an object map from scope name to language. Provided value: {1}",
|
|
1055
|
+
grammarsExtPoint.name,
|
|
1056
|
+
JSON.stringify(syntax.embeddedLanguages)
|
|
1057
|
+
))));
|
|
1058
|
+
return false;
|
|
710
1059
|
}
|
|
711
|
-
|
|
712
|
-
|
|
1060
|
+
if (syntax.tokenTypes && !isObject(syntax.tokenTypes)) {
|
|
1061
|
+
collector.error(( (localize(
|
|
1062
|
+
'invalid.tokenTypes',
|
|
1063
|
+
"Invalid value in `contributes.{0}.tokenTypes`. Must be an object map from scope name to token type. Provided value: {1}",
|
|
1064
|
+
grammarsExtPoint.name,
|
|
1065
|
+
JSON.stringify(syntax.tokenTypes)
|
|
1066
|
+
))));
|
|
1067
|
+
return false;
|
|
1068
|
+
}
|
|
1069
|
+
const grammarLocation = joinPath(extensionLocation, syntax.path);
|
|
1070
|
+
if (!isEqualOrParent(grammarLocation, extensionLocation)) {
|
|
1071
|
+
collector.warn(( (localize(
|
|
1072
|
+
'invalid.path.1',
|
|
1073
|
+
"Expected `contributes.{0}.path` ({1}) to be included inside extension's folder ({2}). This might make the extension non-portable.",
|
|
1074
|
+
grammarsExtPoint.name,
|
|
1075
|
+
grammarLocation.path,
|
|
1076
|
+
extensionLocation.path
|
|
1077
|
+
))));
|
|
1078
|
+
}
|
|
1079
|
+
return true;
|
|
1080
|
+
}
|
|
1081
|
+
let _TextMateTokenizationFeature = class _TextMateTokenizationFeature extends createInjectedClass(TextMateTokenizationFeature) {
|
|
1082
|
+
constructor(loadVSCodeOnigurumaWASM, instantiationService) {
|
|
1083
|
+
super(instantiationService);
|
|
1084
|
+
this['_loadVSCodeOnigurumaWASM'] = loadVSCodeOnigurumaWASM;
|
|
713
1085
|
}
|
|
714
1086
|
};
|
|
715
|
-
|
|
1087
|
+
_TextMateTokenizationFeature = ( __decorate([
|
|
716
1088
|
( __param(1, IInstantiationService))
|
|
717
|
-
],
|
|
1089
|
+
], _TextMateTokenizationFeature));
|
|
718
1090
|
const extensionPoint = getExtensionPoint('grammars');
|
|
719
1091
|
function setGrammars(grammars, getContent, extension = Services.get().extension ?? DEFAULT_EXTENSION) {
|
|
720
1092
|
extensionPoint.acceptUsers([{
|
|
@@ -727,13 +1099,13 @@ function setGrammars(grammars, getContent, extension = Services.get().extension
|
|
|
727
1099
|
}
|
|
728
1100
|
}
|
|
729
1101
|
function initialize(instantiationService) {
|
|
730
|
-
instantiationService.invokeFunction((accessor) => accessor.get(
|
|
1102
|
+
instantiationService.invokeFunction((accessor) => accessor.get(ITextMateTokenizationService));
|
|
731
1103
|
}
|
|
732
1104
|
function getServiceOverride(getOnigLib) {
|
|
733
1105
|
onServicesInitialized(initialize);
|
|
734
1106
|
return {
|
|
735
1107
|
...getServiceOverride$1(),
|
|
736
|
-
[(
|
|
1108
|
+
[( ITextMateTokenizationService.toString())]: new SyncDescriptor(_TextMateTokenizationFeature, [getOnigLib])
|
|
737
1109
|
};
|
|
738
1110
|
}
|
|
739
|
-
export {
|
|
1111
|
+
export { ITextMateTokenizationService, getServiceOverride as default, setGrammars };
|