@codingame/monaco-vscode-textmate-service-override 1.82.4 → 1.82.5-next.1

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.
Files changed (21) hide show
  1. package/external/tslib/tslib.es6.js +11 -0
  2. package/external/vscode-textmate/release/main.d.ts +64 -0
  3. package/index.d.ts +2 -2
  4. package/index.js +2 -2
  5. package/package.json +2 -2
  6. package/textmate.d.ts +5 -0
  7. package/textmate.js +43 -0
  8. package/vscode/src/vs/workbench/services/textMate/browser/arrayOperation.js +64 -0
  9. package/vscode/src/vs/workbench/services/textMate/browser/backgroundTokenization/textMateWorkerTokenizerController.js +159 -0
  10. package/vscode/src/vs/workbench/services/textMate/browser/backgroundTokenization/threadedBackgroundTokenizerFactory.js +202 -0
  11. package/vscode/src/vs/workbench/services/textMate/browser/backgroundTokenization/worker/textMateTokenizationWorker.worker.js +89 -0
  12. package/vscode/src/vs/workbench/services/textMate/browser/backgroundTokenization/worker/textMateWorkerTokenizer.js +142 -0
  13. package/vscode/src/vs/workbench/services/textMate/browser/textMateTokenizationFeature.d.ts +11 -0
  14. package/vscode/src/vs/workbench/services/textMate/browser/textMateTokenizationFeatureImpl.js +461 -0
  15. package/vscode/src/vs/workbench/services/textMate/browser/tokenizationSupport/textMateTokenizationSupport.js +74 -0
  16. package/vscode/src/vs/workbench/services/textMate/browser/tokenizationSupport/tokenizationSupportWithLineLimit.js +38 -0
  17. package/vscode/src/vs/workbench/services/textMate/common/TMGrammarFactory.js +120 -0
  18. package/vscode/src/vs/workbench/services/textMate/common/TMGrammars.js +95 -0
  19. package/vscode/src/vs/workbench/services/textMate/common/TMScopeRegistry.js +26 -0
  20. package/worker.js +1 -1
  21. package/workers/textmate.worker.js +4 -0
@@ -0,0 +1,120 @@
1
+ import { Disposable } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
2
+ import { TMScopeRegistry } from './TMScopeRegistry.js';
3
+
4
+ const missingTMGrammarErrorMessage = 'No TM Grammar registered for this language.';
5
+ class TMGrammarFactory extends Disposable {
6
+ constructor(host, grammarDefinitions, vscodeTextmate, onigLib) {
7
+ super();
8
+ this._host = host;
9
+ this._initialState = vscodeTextmate.INITIAL;
10
+ this._scopeRegistry = ( new TMScopeRegistry());
11
+ this._injections = {};
12
+ this._injectedEmbeddedLanguages = {};
13
+ this._languageToScope = ( new Map());
14
+ this._grammarRegistry = this._register(new vscodeTextmate.Registry({
15
+ onigLib: onigLib,
16
+ loadGrammar: async (scopeName) => {
17
+ const grammarDefinition = this._scopeRegistry.getGrammarDefinition(scopeName);
18
+ if (!grammarDefinition) {
19
+ this._host.logTrace(`No grammar found for scope ${scopeName}`);
20
+ return null;
21
+ }
22
+ const location = grammarDefinition.location;
23
+ try {
24
+ const content = await this._host.readFile(location);
25
+ return vscodeTextmate.parseRawGrammar(content, location.path);
26
+ }
27
+ catch (e) {
28
+ this._host.logError(`Unable to load and parse grammar for scope ${scopeName} from ${location}`, e);
29
+ return null;
30
+ }
31
+ },
32
+ getInjections: (scopeName) => {
33
+ const scopeParts = scopeName.split('.');
34
+ let injections = [];
35
+ for (let i = 1; i <= scopeParts.length; i++) {
36
+ const subScopeName = scopeParts.slice(0, i).join('.');
37
+ injections = [...injections, ...(this._injections[subScopeName] || [])];
38
+ }
39
+ return injections;
40
+ }
41
+ }));
42
+ for (const validGrammar of grammarDefinitions) {
43
+ this._scopeRegistry.register(validGrammar);
44
+ if (validGrammar.injectTo) {
45
+ for (const injectScope of validGrammar.injectTo) {
46
+ let injections = this._injections[injectScope];
47
+ if (!injections) {
48
+ this._injections[injectScope] = injections = [];
49
+ }
50
+ injections.push(validGrammar.scopeName);
51
+ }
52
+ if (validGrammar.embeddedLanguages) {
53
+ for (const injectScope of validGrammar.injectTo) {
54
+ let injectedEmbeddedLanguages = this._injectedEmbeddedLanguages[injectScope];
55
+ if (!injectedEmbeddedLanguages) {
56
+ this._injectedEmbeddedLanguages[injectScope] = injectedEmbeddedLanguages = [];
57
+ }
58
+ injectedEmbeddedLanguages.push(validGrammar.embeddedLanguages);
59
+ }
60
+ }
61
+ }
62
+ if (validGrammar.language) {
63
+ this._languageToScope.set(validGrammar.language, validGrammar.scopeName);
64
+ }
65
+ }
66
+ }
67
+ has(languageId) {
68
+ return ( this._languageToScope.has(languageId));
69
+ }
70
+ setTheme(theme, colorMap) {
71
+ this._grammarRegistry.setTheme(theme, colorMap);
72
+ }
73
+ getColorMap() {
74
+ return this._grammarRegistry.getColorMap();
75
+ }
76
+ async createGrammar(languageId, encodedLanguageId) {
77
+ const scopeName = this._languageToScope.get(languageId);
78
+ if (typeof scopeName !== 'string') {
79
+ throw new Error(missingTMGrammarErrorMessage);
80
+ }
81
+ const grammarDefinition = this._scopeRegistry.getGrammarDefinition(scopeName);
82
+ if (!grammarDefinition) {
83
+ throw new Error(missingTMGrammarErrorMessage);
84
+ }
85
+ const embeddedLanguages = grammarDefinition.embeddedLanguages;
86
+ if (this._injectedEmbeddedLanguages[scopeName]) {
87
+ const injectedEmbeddedLanguages = this._injectedEmbeddedLanguages[scopeName];
88
+ for (const injected of injectedEmbeddedLanguages) {
89
+ for (const scope of ( Object.keys(injected))) {
90
+ embeddedLanguages[scope] = injected[scope];
91
+ }
92
+ }
93
+ }
94
+ const containsEmbeddedLanguages = (( Object.keys(embeddedLanguages)).length > 0);
95
+ let grammar;
96
+ try {
97
+ grammar = await this._grammarRegistry.loadGrammarWithConfiguration(scopeName, encodedLanguageId, {
98
+ embeddedLanguages,
99
+ tokenTypes: grammarDefinition.tokenTypes,
100
+ balancedBracketSelectors: grammarDefinition.balancedBracketSelectors,
101
+ unbalancedBracketSelectors: grammarDefinition.unbalancedBracketSelectors,
102
+ });
103
+ }
104
+ catch (err) {
105
+ if (err.message && err.message.startsWith('No grammar provided for')) {
106
+ throw new Error(missingTMGrammarErrorMessage);
107
+ }
108
+ throw err;
109
+ }
110
+ return {
111
+ languageId: languageId,
112
+ grammar: grammar,
113
+ initialState: this._initialState,
114
+ containsEmbeddedLanguages: containsEmbeddedLanguages,
115
+ sourceExtensionId: grammarDefinition.sourceExtensionId,
116
+ };
117
+ }
118
+ }
119
+
120
+ export { TMGrammarFactory, missingTMGrammarErrorMessage };
@@ -0,0 +1,95 @@
1
+ import * as nls from 'monaco-editor/esm/vs/nls.js';
2
+ import { ExtensionsRegistry } from 'vscode/vscode/vs/workbench/services/extensions/common/extensionsRegistry';
3
+ import { languagesExtPoint } from 'vscode/vscode/vs/workbench/services/language/common/languageService';
4
+
5
+ const grammarsExtPoint = ( ExtensionsRegistry.registerExtensionPoint({
6
+ extensionPoint: 'grammars',
7
+ deps: [languagesExtPoint],
8
+ jsonSchema: {
9
+ description: ( nls.localize(
10
+ 'vscode.extension.contributes.grammars',
11
+ 'Contributes textmate tokenizers.'
12
+ )),
13
+ type: 'array',
14
+ defaultSnippets: [{ body: [{ language: '${1:id}', scopeName: 'source.${2:id}', path: './syntaxes/${3:id}.tmLanguage.' }] }],
15
+ items: {
16
+ type: 'object',
17
+ defaultSnippets: [{ body: { language: '${1:id}', scopeName: 'source.${2:id}', path: './syntaxes/${3:id}.tmLanguage.' } }],
18
+ properties: {
19
+ language: {
20
+ description: ( nls.localize(
21
+ 'vscode.extension.contributes.grammars.language',
22
+ 'Language identifier for which this syntax is contributed to.'
23
+ )),
24
+ type: 'string'
25
+ },
26
+ scopeName: {
27
+ description: ( nls.localize(
28
+ 'vscode.extension.contributes.grammars.scopeName',
29
+ 'Textmate scope name used by the tmLanguage file.'
30
+ )),
31
+ type: 'string'
32
+ },
33
+ path: {
34
+ description: ( nls.localize(
35
+ 'vscode.extension.contributes.grammars.path',
36
+ 'Path of the tmLanguage file. The path is relative to the extension folder and typically starts with \'./syntaxes/\'.'
37
+ )),
38
+ type: 'string'
39
+ },
40
+ embeddedLanguages: {
41
+ description: ( nls.localize(
42
+ 'vscode.extension.contributes.grammars.embeddedLanguages',
43
+ 'A map of scope name to language id if this grammar contains embedded languages.'
44
+ )),
45
+ type: 'object'
46
+ },
47
+ tokenTypes: {
48
+ description: ( nls.localize(
49
+ 'vscode.extension.contributes.grammars.tokenTypes',
50
+ 'A map of scope name to token types.'
51
+ )),
52
+ type: 'object',
53
+ additionalProperties: {
54
+ enum: ['string', 'comment', 'other']
55
+ }
56
+ },
57
+ injectTo: {
58
+ description: ( nls.localize(
59
+ 'vscode.extension.contributes.grammars.injectTo',
60
+ 'List of language scope names to which this grammar is injected to.'
61
+ )),
62
+ type: 'array',
63
+ items: {
64
+ type: 'string'
65
+ }
66
+ },
67
+ balancedBracketScopes: {
68
+ description: ( nls.localize(
69
+ 'vscode.extension.contributes.grammars.balancedBracketScopes',
70
+ 'Defines which scope names contain balanced brackets.'
71
+ )),
72
+ type: 'array',
73
+ items: {
74
+ type: 'string'
75
+ },
76
+ default: ['*'],
77
+ },
78
+ unbalancedBracketScopes: {
79
+ description: ( nls.localize(
80
+ 'vscode.extension.contributes.grammars.unbalancedBracketScopes',
81
+ 'Defines which scope names do not contain balanced brackets.'
82
+ )),
83
+ type: 'array',
84
+ items: {
85
+ type: 'string'
86
+ },
87
+ default: [],
88
+ },
89
+ },
90
+ required: ['scopeName', 'path']
91
+ }
92
+ }
93
+ }));
94
+
95
+ export { grammarsExtPoint };
@@ -0,0 +1,26 @@
1
+ import * as resources from 'monaco-editor/esm/vs/base/common/resources.js';
2
+
3
+ class TMScopeRegistry {
4
+ constructor() {
5
+ this._scopeNameToLanguageRegistration = Object.create(null);
6
+ }
7
+ reset() {
8
+ this._scopeNameToLanguageRegistration = Object.create(null);
9
+ }
10
+ register(def) {
11
+ if (this._scopeNameToLanguageRegistration[def.scopeName]) {
12
+ const existingRegistration = this._scopeNameToLanguageRegistration[def.scopeName];
13
+ if (!resources.isEqual(existingRegistration.location, def.location)) {
14
+ console.warn(`Overwriting grammar scope name to file mapping for scope ${def.scopeName}.\n` +
15
+ `Old grammar file: ${( ( existingRegistration.location.toString()))}.\n` +
16
+ `New grammar file: ${( ( def.location.toString()))}`);
17
+ }
18
+ }
19
+ this._scopeNameToLanguageRegistration[def.scopeName] = def;
20
+ }
21
+ getGrammarDefinition(scopeName) {
22
+ return this._scopeNameToLanguageRegistration[scopeName] || null;
23
+ }
24
+ }
25
+
26
+ export { TMScopeRegistry };
package/worker.js CHANGED
@@ -1 +1 @@
1
- import 'vscode/workers/textmate.worker'
1
+ import './workers/textmate.worker.js';
@@ -0,0 +1,4 @@
1
+ import { TextMateTokenizationWorker } from '../vscode/src/vs/workbench/services/textMate/browser/backgroundTokenization/worker/textMateTokenizationWorker.worker.js';
2
+ import { initialize } from 'monaco-editor/esm/vs/editor/editor.worker.js';
3
+
4
+ initialize((ctx, createData) => new TextMateTokenizationWorker(ctx, createData));