@codingame/monaco-vscode-api 1.68.7 → 1.69.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +102 -7
- package/dist/api.js +481 -9583
- package/dist/configuration.d.ts +488 -0
- package/dist/configuration.js +409 -0
- package/dist/extHost.js +14880 -0
- package/dist/files.js +1325 -0
- package/dist/injection.js +15 -0
- package/dist/jsonErrorMessages.js +17 -0
- package/dist/keybindings.d.ts +502 -0
- package/dist/keybindings.js +2352 -0
- package/dist/languageConfiguration.d.ts +158 -0
- package/dist/languageConfiguration.js +929 -0
- package/dist/languageService.js +340 -0
- package/dist/languages.d.ts +477 -0
- package/dist/languages.js +21 -0
- package/dist/layoutService.js +4 -0
- package/dist/messages.d.ts +7 -0
- package/dist/messages.js +3624 -0
- package/dist/missing-services.js +7293 -0
- package/dist/modelEditor.d.ts +164 -0
- package/dist/modelEditor.js +739 -0
- package/dist/monaco.d.ts +4795 -0
- package/dist/monaco.js +243 -0
- package/dist/services.d.ts +14806 -2098
- package/dist/services.js +22 -25
- package/dist/services2.js +423 -0
- package/dist/snippets.d.ts +466 -0
- package/dist/snippets.js +903 -0
- package/dist/textmate.d.ts +682 -0
- package/dist/textmate.js +740 -0
- package/dist/theme.d.ts +22 -0
- package/dist/theme.js +4167 -0
- package/dist/tokenClassification.d.ts +479 -0
- package/dist/tokenClassification.js +304 -0
- package/dist/tokenClassificationRegistry.js +472 -0
- package/dist/tools.js +17 -0
- package/dist/tslib.es6.js +21 -0
- package/dist/workbenchThemeService.js +46 -0
- package/package.json +107 -24
package/dist/textmate.js
ADDED
|
@@ -0,0 +1,740 @@
|
|
|
1
|
+
import { _ as __decorate, a as __param } from './tslib.es6.js';
|
|
2
|
+
import { M as ExtensionsRegistry, O as ExtensionMessageCollector, Q as ITextMateService, E as Emitter } from './missing-services.js';
|
|
3
|
+
export { Q as ITextMateService } from './missing-services.js';
|
|
4
|
+
import { l as languagesExtPoint } from './languageService.js';
|
|
5
|
+
import { localize } from 'monaco-editor/esm/vs/nls.js';
|
|
6
|
+
import { I as IWorkbenchThemeService } from './workbenchThemeService.js';
|
|
7
|
+
import { Disposable, dispose } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
|
|
8
|
+
import { joinPath, isEqualOrParent, isEqual } from 'monaco-editor/esm/vs/base/common/resources.js';
|
|
9
|
+
import { I as IExtensionResourceLoaderService, r as registerExtensionFile, g as getServiceOverride$1 } from './files.js';
|
|
10
|
+
import { TokenizationRegistry, EncodedTokenizationResult } from 'monaco-editor/esm/vs/editor/common/languages.js';
|
|
11
|
+
import { TokenMetadata } from 'monaco-editor/esm/vs/editor/common/encodedTokenAttributes.js';
|
|
12
|
+
import { createStyleSheet } from 'monaco-editor/esm/vs/base/browser/dom.js';
|
|
13
|
+
import { onUnexpectedError } from 'monaco-editor/esm/vs/base/common/errors.js';
|
|
14
|
+
import { Color } from 'monaco-editor/esm/vs/base/common/color.js';
|
|
15
|
+
import { equals } from 'monaco-editor/esm/vs/base/common/arrays.js';
|
|
16
|
+
import { generateTokensCSSForColorMap } from 'monaco-editor/esm/vs/editor/common/languages/supports/tokenization.js';
|
|
17
|
+
import { isObject } from 'monaco-editor/esm/vs/base/common/types.js';
|
|
18
|
+
import { ILanguageService } from 'monaco-editor/esm/vs/editor/common/languages/language.js';
|
|
19
|
+
import { INotificationService } from 'monaco-editor/esm/vs/platform/notification/common/notification.js';
|
|
20
|
+
import { ILogService } from 'monaco-editor/esm/vs/platform/log/common/log.js';
|
|
21
|
+
import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
|
|
22
|
+
import { IProgressService } from 'monaco-editor/esm/vs/platform/progress/common/progress.js';
|
|
23
|
+
import { nullTokenizeEncoded } from 'monaco-editor/esm/vs/editor/common/languages/nullTokenize.js';
|
|
24
|
+
import { g as getExtensionPoint, c as consoleExtensionMessageHandler } from './tools.js';
|
|
25
|
+
import { S as Services } from './services2.js';
|
|
26
|
+
import { bd as DEFAULT_EXTENSION } from './extHost.js';
|
|
27
|
+
import { c as createInjectedClass } from './injection.js';
|
|
28
|
+
import { SyncDescriptor } from 'monaco-editor/esm/vs/platform/instantiation/common/descriptors.js';
|
|
29
|
+
import { IInstantiationService } from 'monaco-editor/esm/vs/platform/instantiation/common/instantiation.js';
|
|
30
|
+
import { StandaloneServices } from 'monaco-editor/esm/vs/editor/standalone/browser/standaloneServices.js';
|
|
31
|
+
const grammarsExtPoint = ( (ExtensionsRegistry.registerExtensionPoint({
|
|
32
|
+
extensionPoint: 'grammars',
|
|
33
|
+
deps: [languagesExtPoint],
|
|
34
|
+
jsonSchema: {
|
|
35
|
+
description: ( (localize(
|
|
36
|
+
'vscode.extension.contributes.grammars',
|
|
37
|
+
'Contributes textmate tokenizers.'
|
|
38
|
+
))),
|
|
39
|
+
type: 'array',
|
|
40
|
+
defaultSnippets: [{ body: [{ language: '${1:id}', scopeName: 'source.${2:id}', path: './syntaxes/${3:id}.tmLanguage.' }] }],
|
|
41
|
+
items: {
|
|
42
|
+
type: 'object',
|
|
43
|
+
defaultSnippets: [{ body: { language: '${1:id}', scopeName: 'source.${2:id}', path: './syntaxes/${3:id}.tmLanguage.' } }],
|
|
44
|
+
properties: {
|
|
45
|
+
language: {
|
|
46
|
+
description: ( (localize(
|
|
47
|
+
'vscode.extension.contributes.grammars.language',
|
|
48
|
+
'Language identifier for which this syntax is contributed to.'
|
|
49
|
+
))),
|
|
50
|
+
type: 'string'
|
|
51
|
+
},
|
|
52
|
+
scopeName: {
|
|
53
|
+
description: ( (localize(
|
|
54
|
+
'vscode.extension.contributes.grammars.scopeName',
|
|
55
|
+
'Textmate scope name used by the tmLanguage file.'
|
|
56
|
+
))),
|
|
57
|
+
type: 'string'
|
|
58
|
+
},
|
|
59
|
+
path: {
|
|
60
|
+
description: ( (localize(
|
|
61
|
+
'vscode.extension.contributes.grammars.path',
|
|
62
|
+
'Path of the tmLanguage file. The path is relative to the extension folder and typically starts with \'./syntaxes/\'.'
|
|
63
|
+
))),
|
|
64
|
+
type: 'string'
|
|
65
|
+
},
|
|
66
|
+
embeddedLanguages: {
|
|
67
|
+
description: ( (localize(
|
|
68
|
+
'vscode.extension.contributes.grammars.embeddedLanguages',
|
|
69
|
+
'A map of scope name to language id if this grammar contains embedded languages.'
|
|
70
|
+
))),
|
|
71
|
+
type: 'object'
|
|
72
|
+
},
|
|
73
|
+
tokenTypes: {
|
|
74
|
+
description: ( (localize(
|
|
75
|
+
'vscode.extension.contributes.grammars.tokenTypes',
|
|
76
|
+
'A map of scope name to token types.'
|
|
77
|
+
))),
|
|
78
|
+
type: 'object',
|
|
79
|
+
additionalProperties: {
|
|
80
|
+
enum: ['string', 'comment', 'other']
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
injectTo: {
|
|
84
|
+
description: ( (localize(
|
|
85
|
+
'vscode.extension.contributes.grammars.injectTo',
|
|
86
|
+
'List of language scope names to which this grammar is injected to.'
|
|
87
|
+
))),
|
|
88
|
+
type: 'array',
|
|
89
|
+
items: {
|
|
90
|
+
type: 'string'
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
balancedBracketScopes: {
|
|
94
|
+
description: ( (localize(
|
|
95
|
+
'vscode.extension.contributes.grammars.balancedBracketScopes',
|
|
96
|
+
'Defines which scope names contain balanced brackets.'
|
|
97
|
+
))),
|
|
98
|
+
type: 'array',
|
|
99
|
+
items: {
|
|
100
|
+
type: 'string'
|
|
101
|
+
},
|
|
102
|
+
default: ['*'],
|
|
103
|
+
},
|
|
104
|
+
unbalancedBracketScopes: {
|
|
105
|
+
description: ( (localize(
|
|
106
|
+
'vscode.extension.contributes.grammars.unbalancedBracketScopes',
|
|
107
|
+
'Defines which scope names do not contain balanced brackets.'
|
|
108
|
+
))),
|
|
109
|
+
type: 'array',
|
|
110
|
+
items: {
|
|
111
|
+
type: 'string'
|
|
112
|
+
},
|
|
113
|
+
default: [],
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
required: ['scopeName', 'path']
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
})));
|
|
120
|
+
class TMScopeRegistry extends Disposable {
|
|
121
|
+
constructor() {
|
|
122
|
+
super();
|
|
123
|
+
this._scopeNameToLanguageRegistration = Object.create(null);
|
|
124
|
+
}
|
|
125
|
+
reset() {
|
|
126
|
+
this._scopeNameToLanguageRegistration = Object.create(null);
|
|
127
|
+
}
|
|
128
|
+
register(def) {
|
|
129
|
+
if (this._scopeNameToLanguageRegistration[def.scopeName]) {
|
|
130
|
+
const existingRegistration = this._scopeNameToLanguageRegistration[def.scopeName];
|
|
131
|
+
if (!isEqual(existingRegistration.location, def.location)) {
|
|
132
|
+
console.warn(`Overwriting grammar scope name to file mapping for scope ${def.scopeName}.\n` +
|
|
133
|
+
`Old grammar file: ${( ( existingRegistration.location.toString()))}.\n` +
|
|
134
|
+
`New grammar file: ${( ( def.location.toString()))}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
this._scopeNameToLanguageRegistration[def.scopeName] = def;
|
|
138
|
+
}
|
|
139
|
+
getGrammarDefinition(scopeName) {
|
|
140
|
+
return this._scopeNameToLanguageRegistration[scopeName] || null;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const missingTMGrammarErrorMessage = 'No TM Grammar registered for this language.';
|
|
144
|
+
class TMGrammarFactory extends Disposable {
|
|
145
|
+
constructor(host, grammarDefinitions, vscodeTextmate, onigLib) {
|
|
146
|
+
super();
|
|
147
|
+
this._host = host;
|
|
148
|
+
this._initialState = vscodeTextmate.INITIAL;
|
|
149
|
+
this._scopeRegistry = this._register(( (new TMScopeRegistry())));
|
|
150
|
+
this._injections = {};
|
|
151
|
+
this._injectedEmbeddedLanguages = {};
|
|
152
|
+
this._languageToScope = ( (new Map()));
|
|
153
|
+
this._grammarRegistry = this._register(new vscodeTextmate.Registry({
|
|
154
|
+
onigLib: onigLib,
|
|
155
|
+
loadGrammar: async (scopeName) => {
|
|
156
|
+
const grammarDefinition = this._scopeRegistry.getGrammarDefinition(scopeName);
|
|
157
|
+
if (!grammarDefinition) {
|
|
158
|
+
this._host.logTrace(`No grammar found for scope ${scopeName}`);
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
const location = grammarDefinition.location;
|
|
162
|
+
try {
|
|
163
|
+
const content = await this._host.readFile(location);
|
|
164
|
+
return vscodeTextmate.parseRawGrammar(content, location.path);
|
|
165
|
+
}
|
|
166
|
+
catch (e) {
|
|
167
|
+
this._host.logError(`Unable to load and parse grammar for scope ${scopeName} from ${location}`, e);
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
getInjections: (scopeName) => {
|
|
172
|
+
const scopeParts = scopeName.split('.');
|
|
173
|
+
let injections = [];
|
|
174
|
+
for (let i = 1; i <= scopeParts.length; i++) {
|
|
175
|
+
const subScopeName = scopeParts.slice(0, i).join('.');
|
|
176
|
+
injections = [...injections, ...(this._injections[subScopeName] || [])];
|
|
177
|
+
}
|
|
178
|
+
return injections;
|
|
179
|
+
}
|
|
180
|
+
}));
|
|
181
|
+
for (const validGrammar of grammarDefinitions) {
|
|
182
|
+
this._scopeRegistry.register(validGrammar);
|
|
183
|
+
if (validGrammar.injectTo) {
|
|
184
|
+
for (const injectScope of validGrammar.injectTo) {
|
|
185
|
+
let injections = this._injections[injectScope];
|
|
186
|
+
if (!injections) {
|
|
187
|
+
this._injections[injectScope] = injections = [];
|
|
188
|
+
}
|
|
189
|
+
injections.push(validGrammar.scopeName);
|
|
190
|
+
}
|
|
191
|
+
if (validGrammar.embeddedLanguages) {
|
|
192
|
+
for (const injectScope of validGrammar.injectTo) {
|
|
193
|
+
let injectedEmbeddedLanguages = this._injectedEmbeddedLanguages[injectScope];
|
|
194
|
+
if (!injectedEmbeddedLanguages) {
|
|
195
|
+
this._injectedEmbeddedLanguages[injectScope] = injectedEmbeddedLanguages = [];
|
|
196
|
+
}
|
|
197
|
+
injectedEmbeddedLanguages.push(validGrammar.embeddedLanguages);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (validGrammar.language) {
|
|
202
|
+
this._languageToScope.set(validGrammar.language, validGrammar.scopeName);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
has(languageId) {
|
|
207
|
+
return this._languageToScope.has(languageId);
|
|
208
|
+
}
|
|
209
|
+
setTheme(theme, colorMap) {
|
|
210
|
+
this._grammarRegistry.setTheme(theme, colorMap);
|
|
211
|
+
}
|
|
212
|
+
getColorMap() {
|
|
213
|
+
return this._grammarRegistry.getColorMap();
|
|
214
|
+
}
|
|
215
|
+
async createGrammar(languageId, encodedLanguageId) {
|
|
216
|
+
const scopeName = this._languageToScope.get(languageId);
|
|
217
|
+
if (typeof scopeName !== 'string') {
|
|
218
|
+
throw new Error(missingTMGrammarErrorMessage);
|
|
219
|
+
}
|
|
220
|
+
const grammarDefinition = this._scopeRegistry.getGrammarDefinition(scopeName);
|
|
221
|
+
if (!grammarDefinition) {
|
|
222
|
+
throw new Error(missingTMGrammarErrorMessage);
|
|
223
|
+
}
|
|
224
|
+
const embeddedLanguages = grammarDefinition.embeddedLanguages;
|
|
225
|
+
if (this._injectedEmbeddedLanguages[scopeName]) {
|
|
226
|
+
const injectedEmbeddedLanguages = this._injectedEmbeddedLanguages[scopeName];
|
|
227
|
+
for (const injected of injectedEmbeddedLanguages) {
|
|
228
|
+
for (const scope of ( (Object.keys(injected)))) {
|
|
229
|
+
embeddedLanguages[scope] = injected[scope];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const containsEmbeddedLanguages = (( (Object.keys(embeddedLanguages))).length > 0);
|
|
234
|
+
let grammar;
|
|
235
|
+
try {
|
|
236
|
+
grammar = await this._grammarRegistry.loadGrammarWithConfiguration(scopeName, encodedLanguageId, {
|
|
237
|
+
embeddedLanguages,
|
|
238
|
+
tokenTypes: grammarDefinition.tokenTypes,
|
|
239
|
+
balancedBracketSelectors: grammarDefinition.balancedBracketSelectors,
|
|
240
|
+
unbalancedBracketSelectors: grammarDefinition.unbalancedBracketSelectors,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
catch (err) {
|
|
244
|
+
if (err.message && err.message.startsWith('No grammar provided for')) {
|
|
245
|
+
throw new Error(missingTMGrammarErrorMessage);
|
|
246
|
+
}
|
|
247
|
+
throw err;
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
languageId: languageId,
|
|
251
|
+
grammar: grammar,
|
|
252
|
+
initialState: this._initialState,
|
|
253
|
+
containsEmbeddedLanguages: containsEmbeddedLanguages
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
class TMTokenization extends Disposable {
|
|
258
|
+
constructor(grammar, initialState, containsEmbeddedLanguages) {
|
|
259
|
+
super();
|
|
260
|
+
this._onDidEncounterLanguage = this._register(( (new Emitter())));
|
|
261
|
+
this.onDidEncounterLanguage = this._onDidEncounterLanguage.event;
|
|
262
|
+
this._grammar = grammar;
|
|
263
|
+
this._initialState = initialState;
|
|
264
|
+
this._containsEmbeddedLanguages = containsEmbeddedLanguages;
|
|
265
|
+
this._seenLanguages = [];
|
|
266
|
+
}
|
|
267
|
+
getInitialState() {
|
|
268
|
+
return this._initialState;
|
|
269
|
+
}
|
|
270
|
+
tokenize(line, hasEOL, state) {
|
|
271
|
+
throw new Error('Not supported!');
|
|
272
|
+
}
|
|
273
|
+
tokenizeEncoded(line, hasEOL, state) {
|
|
274
|
+
const textMateResult = this._grammar.tokenizeLine2(line, state, 500);
|
|
275
|
+
if (textMateResult.stoppedEarly) {
|
|
276
|
+
console.warn(`Time limit reached when tokenizing line: ${line.substring(0, 100)}`);
|
|
277
|
+
return (
|
|
278
|
+
(new EncodedTokenizationResult(textMateResult.tokens, state))
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
if (this._containsEmbeddedLanguages) {
|
|
282
|
+
const seenLanguages = this._seenLanguages;
|
|
283
|
+
const tokens = textMateResult.tokens;
|
|
284
|
+
for (let i = 0, len = (tokens.length >>> 1); i < len; i++) {
|
|
285
|
+
const metadata = tokens[(i << 1) + 1];
|
|
286
|
+
const languageId = TokenMetadata.getLanguageId(metadata);
|
|
287
|
+
if (!seenLanguages[languageId]) {
|
|
288
|
+
seenLanguages[languageId] = true;
|
|
289
|
+
this._onDidEncounterLanguage.fire(languageId);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
let endState;
|
|
294
|
+
if (state.equals(textMateResult.ruleStack)) {
|
|
295
|
+
endState = state;
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
endState = textMateResult.ruleStack;
|
|
299
|
+
}
|
|
300
|
+
return (
|
|
301
|
+
(new EncodedTokenizationResult(textMateResult.tokens, endState))
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
let AbstractTextMateService = class AbstractTextMateService extends Disposable {
|
|
306
|
+
constructor(_languageService, _themeService, _extensionResourceLoaderService, _notificationService, _logService, _configurationService, _progressService) {
|
|
307
|
+
super();
|
|
308
|
+
this._languageService = _languageService;
|
|
309
|
+
this._themeService = _themeService;
|
|
310
|
+
this._extensionResourceLoaderService = _extensionResourceLoaderService;
|
|
311
|
+
this._notificationService = _notificationService;
|
|
312
|
+
this._logService = _logService;
|
|
313
|
+
this._configurationService = _configurationService;
|
|
314
|
+
this._progressService = _progressService;
|
|
315
|
+
this._onDidEncounterLanguage = this._register(( (new Emitter())));
|
|
316
|
+
this.onDidEncounterLanguage = this._onDidEncounterLanguage.event;
|
|
317
|
+
this._vscodeOniguruma = null;
|
|
318
|
+
this._styleElement = createStyleSheet();
|
|
319
|
+
this._styleElement.className = 'vscode-tokens-styles';
|
|
320
|
+
this._createdModes = [];
|
|
321
|
+
this._encounteredLanguages = [];
|
|
322
|
+
this._debugMode = false;
|
|
323
|
+
this._debugModePrintFunc = () => { };
|
|
324
|
+
this._grammarDefinitions = null;
|
|
325
|
+
this._grammarFactory = null;
|
|
326
|
+
this._tokenizersRegistrations = [];
|
|
327
|
+
this._currentTheme = null;
|
|
328
|
+
this._currentTokenColorMap = null;
|
|
329
|
+
grammarsExtPoint.setHandler((extensions) => {
|
|
330
|
+
this._grammarDefinitions = null;
|
|
331
|
+
if (this._grammarFactory) {
|
|
332
|
+
this._grammarFactory.dispose();
|
|
333
|
+
this._grammarFactory = null;
|
|
334
|
+
this._onDidDisposeGrammarFactory();
|
|
335
|
+
}
|
|
336
|
+
this._tokenizersRegistrations = dispose(this._tokenizersRegistrations);
|
|
337
|
+
this._grammarDefinitions = [];
|
|
338
|
+
for (const extension of extensions) {
|
|
339
|
+
const grammars = extension.value;
|
|
340
|
+
for (const grammar of grammars) {
|
|
341
|
+
if (!this._validateGrammarExtensionPoint(extension.description.extensionLocation, grammar, extension.collector)) {
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
const grammarLocation = joinPath(extension.description.extensionLocation, grammar.path);
|
|
345
|
+
const embeddedLanguages = Object.create(null);
|
|
346
|
+
if (grammar.embeddedLanguages) {
|
|
347
|
+
const scopes = ( (Object.keys(grammar.embeddedLanguages)));
|
|
348
|
+
for (let i = 0, len = scopes.length; i < len; i++) {
|
|
349
|
+
const scope = scopes[i];
|
|
350
|
+
const language = grammar.embeddedLanguages[scope];
|
|
351
|
+
if (typeof language !== 'string') {
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (this._languageService.isRegisteredLanguageId(language)) {
|
|
355
|
+
embeddedLanguages[scope] = this._languageService.languageIdCodec.encodeLanguageId(language);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
const tokenTypes = Object.create(null);
|
|
360
|
+
if (grammar.tokenTypes) {
|
|
361
|
+
const scopes = ( (Object.keys(grammar.tokenTypes)));
|
|
362
|
+
for (const scope of scopes) {
|
|
363
|
+
const tokenType = grammar.tokenTypes[scope];
|
|
364
|
+
switch (tokenType) {
|
|
365
|
+
case 'string':
|
|
366
|
+
tokenTypes[scope] = 2 ;
|
|
367
|
+
break;
|
|
368
|
+
case 'other':
|
|
369
|
+
tokenTypes[scope] = 0 ;
|
|
370
|
+
break;
|
|
371
|
+
case 'comment':
|
|
372
|
+
tokenTypes[scope] = 1 ;
|
|
373
|
+
break;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
let validLanguageId = null;
|
|
378
|
+
if (grammar.language && this._languageService.isRegisteredLanguageId(grammar.language)) {
|
|
379
|
+
validLanguageId = grammar.language;
|
|
380
|
+
}
|
|
381
|
+
function asStringArray(array, defaultValue) {
|
|
382
|
+
if (!Array.isArray(array)) {
|
|
383
|
+
return defaultValue;
|
|
384
|
+
}
|
|
385
|
+
if (!array.every(e => typeof e === 'string')) {
|
|
386
|
+
return defaultValue;
|
|
387
|
+
}
|
|
388
|
+
return array;
|
|
389
|
+
}
|
|
390
|
+
this._grammarDefinitions.push({
|
|
391
|
+
location: grammarLocation,
|
|
392
|
+
language: validLanguageId ? validLanguageId : undefined,
|
|
393
|
+
scopeName: grammar.scopeName,
|
|
394
|
+
embeddedLanguages: embeddedLanguages,
|
|
395
|
+
tokenTypes: tokenTypes,
|
|
396
|
+
injectTo: grammar.injectTo,
|
|
397
|
+
balancedBracketSelectors: asStringArray(grammar.balancedBracketScopes, ['*']),
|
|
398
|
+
unbalancedBracketSelectors: asStringArray(grammar.unbalancedBracketScopes, []),
|
|
399
|
+
});
|
|
400
|
+
if (validLanguageId) {
|
|
401
|
+
this._tokenizersRegistrations.push(TokenizationRegistry.registerFactory(validLanguageId, this._createFactory(validLanguageId)));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
for (const createMode of this._createdModes) {
|
|
406
|
+
TokenizationRegistry.getOrCreate(createMode);
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
this._updateTheme(this._grammarFactory, this._themeService.getColorTheme(), true);
|
|
410
|
+
this._register(this._themeService.onDidColorThemeChange(() => {
|
|
411
|
+
this._updateTheme(this._grammarFactory, this._themeService.getColorTheme(), false);
|
|
412
|
+
}));
|
|
413
|
+
this._languageService.onDidEncounterLanguage((languageId) => {
|
|
414
|
+
this._createdModes.push(languageId);
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
startDebugMode(printFn, onStop) {
|
|
418
|
+
if (this._debugMode) {
|
|
419
|
+
this._notificationService.error(( (localize('alreadyDebugging', "Already Logging."))));
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
this._debugModePrintFunc = printFn;
|
|
423
|
+
this._debugMode = true;
|
|
424
|
+
if (this._debugMode) {
|
|
425
|
+
this._progressService.withProgress({
|
|
426
|
+
location: 15 ,
|
|
427
|
+
buttons: [( (localize('stop', "Stop")))]
|
|
428
|
+
}, (progress) => {
|
|
429
|
+
progress.report({
|
|
430
|
+
message: ( (localize(
|
|
431
|
+
'progress1',
|
|
432
|
+
"Preparing to log TM Grammar parsing. Press Stop when finished."
|
|
433
|
+
)))
|
|
434
|
+
});
|
|
435
|
+
return this._getVSCodeOniguruma().then((vscodeOniguruma) => {
|
|
436
|
+
vscodeOniguruma.setDefaultDebugCall(true);
|
|
437
|
+
progress.report({
|
|
438
|
+
message: ( (localize('progress2', "Now logging TM Grammar parsing. Press Stop when finished.")))
|
|
439
|
+
});
|
|
440
|
+
return (
|
|
441
|
+
(new Promise((resolve, reject) => { }))
|
|
442
|
+
);
|
|
443
|
+
});
|
|
444
|
+
}, (choice) => {
|
|
445
|
+
this._getVSCodeOniguruma().then((vscodeOniguruma) => {
|
|
446
|
+
this._debugModePrintFunc = () => { };
|
|
447
|
+
this._debugMode = false;
|
|
448
|
+
vscodeOniguruma.setDefaultDebugCall(false);
|
|
449
|
+
onStop();
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
_canCreateGrammarFactory() {
|
|
455
|
+
return (this._grammarDefinitions ? true : false);
|
|
456
|
+
}
|
|
457
|
+
async _getOrCreateGrammarFactory() {
|
|
458
|
+
if (this._grammarFactory) {
|
|
459
|
+
return this._grammarFactory;
|
|
460
|
+
}
|
|
461
|
+
const [vscodeTextmate, vscodeOniguruma] = await Promise.all([import('vscode-textmate'), this._getVSCodeOniguruma()]);
|
|
462
|
+
const onigLib = Promise.resolve({
|
|
463
|
+
createOnigScanner: (sources) => vscodeOniguruma.createOnigScanner(sources),
|
|
464
|
+
createOnigString: (str) => vscodeOniguruma.createOnigString(str)
|
|
465
|
+
});
|
|
466
|
+
if (this._grammarFactory) {
|
|
467
|
+
return this._grammarFactory;
|
|
468
|
+
}
|
|
469
|
+
this._grammarFactory = ( (new TMGrammarFactory({
|
|
470
|
+
logTrace: (msg) => this._logService.trace(msg),
|
|
471
|
+
logError: (msg, err) => this._logService.error(msg, err),
|
|
472
|
+
readFile: (resource) => this._extensionResourceLoaderService.readExtensionResource(resource)
|
|
473
|
+
}, this._grammarDefinitions || [], vscodeTextmate, onigLib)));
|
|
474
|
+
this._onDidCreateGrammarFactory(this._grammarDefinitions || []);
|
|
475
|
+
this._updateTheme(this._grammarFactory, this._themeService.getColorTheme(), true);
|
|
476
|
+
return this._grammarFactory;
|
|
477
|
+
}
|
|
478
|
+
_createFactory(languageId) {
|
|
479
|
+
return {
|
|
480
|
+
createTokenizationSupport: async () => {
|
|
481
|
+
if (!this._languageService.isRegisteredLanguageId(languageId)) {
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
if (!this._canCreateGrammarFactory()) {
|
|
485
|
+
return null;
|
|
486
|
+
}
|
|
487
|
+
const encodedLanguageId = this._languageService.languageIdCodec.encodeLanguageId(languageId);
|
|
488
|
+
try {
|
|
489
|
+
const grammarFactory = await this._getOrCreateGrammarFactory();
|
|
490
|
+
if (!grammarFactory.has(languageId)) {
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
const r = await grammarFactory.createGrammar(languageId, encodedLanguageId);
|
|
494
|
+
if (!r.grammar) {
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
const tokenization = ( (new TMTokenization(r.grammar, r.initialState, r.containsEmbeddedLanguages)));
|
|
498
|
+
tokenization.onDidEncounterLanguage((encodedLanguageId) => {
|
|
499
|
+
if (!this._encounteredLanguages[encodedLanguageId]) {
|
|
500
|
+
const languageId = this._languageService.languageIdCodec.decodeLanguageId(encodedLanguageId);
|
|
501
|
+
this._encounteredLanguages[encodedLanguageId] = true;
|
|
502
|
+
this._onDidEncounterLanguage.fire(languageId);
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
return (
|
|
506
|
+
(new TMTokenizationSupportWithLineLimit(languageId, encodedLanguageId, tokenization, this._configurationService))
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
catch (err) {
|
|
510
|
+
if (err.message && err.message === missingTMGrammarErrorMessage) {
|
|
511
|
+
return null;
|
|
512
|
+
}
|
|
513
|
+
onUnexpectedError(err);
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
static _toColorMap(colorMap) {
|
|
520
|
+
const result = [null];
|
|
521
|
+
for (let i = 1, len = colorMap.length; i < len; i++) {
|
|
522
|
+
result[i] = ( (Color.fromHex(colorMap[i])));
|
|
523
|
+
}
|
|
524
|
+
return result;
|
|
525
|
+
}
|
|
526
|
+
_updateTheme(grammarFactory, colorTheme, forceUpdate) {
|
|
527
|
+
if (!forceUpdate && this._currentTheme && this._currentTokenColorMap && AbstractTextMateService.equalsTokenRules(this._currentTheme.settings, colorTheme.tokenColors) && equals(this._currentTokenColorMap, colorTheme.tokenColorMap)) {
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
this._currentTheme = { name: colorTheme.label, settings: colorTheme.tokenColors };
|
|
531
|
+
this._currentTokenColorMap = colorTheme.tokenColorMap;
|
|
532
|
+
this._doUpdateTheme(grammarFactory, this._currentTheme, this._currentTokenColorMap);
|
|
533
|
+
}
|
|
534
|
+
_doUpdateTheme(grammarFactory, theme, tokenColorMap) {
|
|
535
|
+
grammarFactory?.setTheme(theme, tokenColorMap);
|
|
536
|
+
const colorMap = AbstractTextMateService._toColorMap(tokenColorMap);
|
|
537
|
+
const cssRules = generateTokensCSSForColorMap(colorMap);
|
|
538
|
+
this._styleElement.textContent = cssRules;
|
|
539
|
+
TokenizationRegistry.setColorMap(colorMap);
|
|
540
|
+
}
|
|
541
|
+
static equalsTokenRules(a, b) {
|
|
542
|
+
if (!b || !a || b.length !== a.length) {
|
|
543
|
+
return false;
|
|
544
|
+
}
|
|
545
|
+
for (let i = b.length - 1; i >= 0; i--) {
|
|
546
|
+
const r1 = b[i];
|
|
547
|
+
const r2 = a[i];
|
|
548
|
+
if (r1.scope !== r2.scope) {
|
|
549
|
+
return false;
|
|
550
|
+
}
|
|
551
|
+
const s1 = r1.settings;
|
|
552
|
+
const s2 = r2.settings;
|
|
553
|
+
if (s1 && s2) {
|
|
554
|
+
if (s1.fontStyle !== s2.fontStyle || s1.foreground !== s2.foreground || s1.background !== s2.background) {
|
|
555
|
+
return false;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
else if (!s1 || !s2) {
|
|
559
|
+
return false;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return true;
|
|
563
|
+
}
|
|
564
|
+
_validateGrammarExtensionPoint(extensionLocation, syntax, collector) {
|
|
565
|
+
if (syntax.language && ((typeof syntax.language !== 'string') || !this._languageService.isRegisteredLanguageId(syntax.language))) {
|
|
566
|
+
collector.error(( (localize(
|
|
567
|
+
'invalid.language',
|
|
568
|
+
"Unknown language in `contributes.{0}.language`. Provided value: {1}",
|
|
569
|
+
grammarsExtPoint.name,
|
|
570
|
+
String(syntax.language)
|
|
571
|
+
))));
|
|
572
|
+
return false;
|
|
573
|
+
}
|
|
574
|
+
if (!syntax.scopeName || (typeof syntax.scopeName !== 'string')) {
|
|
575
|
+
collector.error(( (localize(
|
|
576
|
+
'invalid.scopeName',
|
|
577
|
+
"Expected string in `contributes.{0}.scopeName`. Provided value: {1}",
|
|
578
|
+
grammarsExtPoint.name,
|
|
579
|
+
String(syntax.scopeName)
|
|
580
|
+
))));
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
if (!syntax.path || (typeof syntax.path !== 'string')) {
|
|
584
|
+
collector.error(( (localize(
|
|
585
|
+
'invalid.path.0',
|
|
586
|
+
"Expected string in `contributes.{0}.path`. Provided value: {1}",
|
|
587
|
+
grammarsExtPoint.name,
|
|
588
|
+
String(syntax.path)
|
|
589
|
+
))));
|
|
590
|
+
return false;
|
|
591
|
+
}
|
|
592
|
+
if (syntax.injectTo && (!Array.isArray(syntax.injectTo) || syntax.injectTo.some(scope => typeof scope !== 'string'))) {
|
|
593
|
+
collector.error(( (localize(
|
|
594
|
+
'invalid.injectTo',
|
|
595
|
+
"Invalid value in `contributes.{0}.injectTo`. Must be an array of language scope names. Provided value: {1}",
|
|
596
|
+
grammarsExtPoint.name,
|
|
597
|
+
JSON.stringify(syntax.injectTo)
|
|
598
|
+
))));
|
|
599
|
+
return false;
|
|
600
|
+
}
|
|
601
|
+
if (syntax.embeddedLanguages && !isObject(syntax.embeddedLanguages)) {
|
|
602
|
+
collector.error(( (localize(
|
|
603
|
+
'invalid.embeddedLanguages',
|
|
604
|
+
"Invalid value in `contributes.{0}.embeddedLanguages`. Must be an object map from scope name to language. Provided value: {1}",
|
|
605
|
+
grammarsExtPoint.name,
|
|
606
|
+
JSON.stringify(syntax.embeddedLanguages)
|
|
607
|
+
))));
|
|
608
|
+
return false;
|
|
609
|
+
}
|
|
610
|
+
if (syntax.tokenTypes && !isObject(syntax.tokenTypes)) {
|
|
611
|
+
collector.error(( (localize(
|
|
612
|
+
'invalid.tokenTypes',
|
|
613
|
+
"Invalid value in `contributes.{0}.tokenTypes`. Must be an object map from scope name to token type. Provided value: {1}",
|
|
614
|
+
grammarsExtPoint.name,
|
|
615
|
+
JSON.stringify(syntax.tokenTypes)
|
|
616
|
+
))));
|
|
617
|
+
return false;
|
|
618
|
+
}
|
|
619
|
+
const grammarLocation = joinPath(extensionLocation, syntax.path);
|
|
620
|
+
if (!isEqualOrParent(grammarLocation, extensionLocation)) {
|
|
621
|
+
collector.warn(( (localize(
|
|
622
|
+
'invalid.path.1',
|
|
623
|
+
"Expected `contributes.{0}.path` ({1}) to be included inside extension's folder ({2}). This might make the extension non-portable.",
|
|
624
|
+
grammarsExtPoint.name,
|
|
625
|
+
grammarLocation.path,
|
|
626
|
+
extensionLocation.path
|
|
627
|
+
))));
|
|
628
|
+
}
|
|
629
|
+
return true;
|
|
630
|
+
}
|
|
631
|
+
async createGrammar(languageId) {
|
|
632
|
+
if (!this._languageService.isRegisteredLanguageId(languageId)) {
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
const grammarFactory = await this._getOrCreateGrammarFactory();
|
|
636
|
+
if (!grammarFactory.has(languageId)) {
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
const encodedLanguageId = this._languageService.languageIdCodec.encodeLanguageId(languageId);
|
|
640
|
+
const { grammar } = await grammarFactory.createGrammar(languageId, encodedLanguageId);
|
|
641
|
+
return grammar;
|
|
642
|
+
}
|
|
643
|
+
_onDidCreateGrammarFactory(grammarDefinitions) {
|
|
644
|
+
}
|
|
645
|
+
_onDidDisposeGrammarFactory() {
|
|
646
|
+
}
|
|
647
|
+
_getVSCodeOniguruma() {
|
|
648
|
+
if (!this._vscodeOniguruma) {
|
|
649
|
+
this._vscodeOniguruma = this._doGetVSCodeOniguruma();
|
|
650
|
+
}
|
|
651
|
+
return this._vscodeOniguruma;
|
|
652
|
+
}
|
|
653
|
+
async _doGetVSCodeOniguruma() {
|
|
654
|
+
const [vscodeOniguruma, wasm] = await Promise.all([import('vscode-oniguruma'), this._loadVSCodeOnigurumWASM()]);
|
|
655
|
+
const options = {
|
|
656
|
+
data: wasm,
|
|
657
|
+
print: (str) => {
|
|
658
|
+
this._debugModePrintFunc(str);
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
await vscodeOniguruma.loadWASM(options);
|
|
662
|
+
return vscodeOniguruma;
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
AbstractTextMateService = ( (__decorate([
|
|
666
|
+
( (__param(0, ILanguageService))),
|
|
667
|
+
( (__param(1, IWorkbenchThemeService))),
|
|
668
|
+
( (__param(2, IExtensionResourceLoaderService))),
|
|
669
|
+
( (__param(3, INotificationService))),
|
|
670
|
+
( (__param(4, ILogService))),
|
|
671
|
+
( (__param(5, IConfigurationService))),
|
|
672
|
+
( (__param(6, IProgressService)))
|
|
673
|
+
], AbstractTextMateService)));
|
|
674
|
+
let TMTokenizationSupportWithLineLimit = class TMTokenizationSupportWithLineLimit {
|
|
675
|
+
constructor(languageId, encodedLanguageId, actual, _configurationService) {
|
|
676
|
+
this._configurationService = _configurationService;
|
|
677
|
+
this._languageId = languageId;
|
|
678
|
+
this._encodedLanguageId = encodedLanguageId;
|
|
679
|
+
this._actual = actual;
|
|
680
|
+
this._maxTokenizationLineLength = this._configurationService.getValue('editor.maxTokenizationLineLength', {
|
|
681
|
+
overrideIdentifier: this._languageId
|
|
682
|
+
});
|
|
683
|
+
this._configurationService.onDidChangeConfiguration(e => {
|
|
684
|
+
if (e.affectsConfiguration('editor.maxTokenizationLineLength')) {
|
|
685
|
+
this._maxTokenizationLineLength = this._configurationService.getValue('editor.maxTokenizationLineLength', {
|
|
686
|
+
overrideIdentifier: this._languageId
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
getInitialState() {
|
|
692
|
+
return this._actual.getInitialState();
|
|
693
|
+
}
|
|
694
|
+
tokenize(line, hasEOL, state) {
|
|
695
|
+
throw new Error('Not supported!');
|
|
696
|
+
}
|
|
697
|
+
tokenizeEncoded(line, hasEOL, state) {
|
|
698
|
+
if (line.length >= this._maxTokenizationLineLength) {
|
|
699
|
+
return nullTokenizeEncoded(this._encodedLanguageId, state);
|
|
700
|
+
}
|
|
701
|
+
return this._actual.tokenizeEncoded(line, hasEOL, state);
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
TMTokenizationSupportWithLineLimit = ( (__decorate([
|
|
705
|
+
( (__param(3, IConfigurationService)))
|
|
706
|
+
], TMTokenizationSupportWithLineLimit)));
|
|
707
|
+
let TextMateService = class TextMateService extends createInjectedClass(AbstractTextMateService) {
|
|
708
|
+
constructor(loadVSCodeOnigurumWASM, instantiationService) {
|
|
709
|
+
super(instantiationService);
|
|
710
|
+
this.loadVSCodeOnigurumWASM = loadVSCodeOnigurumWASM;
|
|
711
|
+
}
|
|
712
|
+
_loadVSCodeOnigurumWASM() {
|
|
713
|
+
return this.loadVSCodeOnigurumWASM();
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
TextMateService = ( __decorate([
|
|
717
|
+
( __param(1, IInstantiationService))
|
|
718
|
+
], TextMateService));
|
|
719
|
+
const extensionPoint = getExtensionPoint('grammars');
|
|
720
|
+
function setGrammars(grammars, getContent, extension = Services.get().extension ?? DEFAULT_EXTENSION) {
|
|
721
|
+
extensionPoint.acceptUsers([{
|
|
722
|
+
description: extension,
|
|
723
|
+
value: grammars,
|
|
724
|
+
collector: new ExtensionMessageCollector(consoleExtensionMessageHandler, extension, extensionPoint.name)
|
|
725
|
+
}]);
|
|
726
|
+
for (const grammar of grammars) {
|
|
727
|
+
registerExtensionFile(joinPath(extension.extensionLocation, grammar.path), () => getContent(grammar));
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
function initialize() {
|
|
731
|
+
StandaloneServices.get(ITextMateService);
|
|
732
|
+
}
|
|
733
|
+
function getServiceOverride(getOnigLib) {
|
|
734
|
+
setTimeout(initialize);
|
|
735
|
+
return {
|
|
736
|
+
...getServiceOverride$1(),
|
|
737
|
+
[( ITextMateService.toString())]: new SyncDescriptor(TextMateService, [getOnigLib])
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
export { getServiceOverride as default, setGrammars };
|