monaco-editor11 1.0.7 → 1.0.9
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/dist/assets/css.worker-C7FogG4G.js +93 -0
- package/dist/assets/editor.worker-iXcRX1Tq.js +26 -0
- package/dist/assets/html.worker-C8VxctEJ.js +470 -0
- package/dist/assets/json.worker-CMC9kgPL.js +58 -0
- package/dist/assets/ts.worker-CtTJ3hNN.js +67731 -0
- package/dist/index.d.ts +0 -6
- package/dist/monaco-editor11.es.js +49 -78
- package/dist/monaco-editor11.umd.js +1 -50
- package/dist/monaco.d.ts +8 -0
- package/dist/workers/common/initialize.js +16 -0
- package/dist/workers/common/workers.js +141 -0
- package/dist/workers/editor/common/abstractSyntaxTokenBackend.js +128 -0
- package/dist/workers/editor/common/abstractText.js +89 -0
- package/dist/workers/editor/common/ast.js +485 -0
- package/dist/workers/editor/common/autoIndent.js +390 -0
- package/dist/workers/editor/common/beforeEditPositionMapper.js +110 -0
- package/dist/workers/editor/common/bracketPairsImpl.js +717 -0
- package/dist/workers/editor/common/bracketPairsTree.js +343 -0
- package/dist/workers/editor/common/brackets.js +108 -0
- package/dist/workers/editor/common/characterClassifier.js +59 -0
- package/dist/workers/editor/common/characterPair.js +40 -0
- package/dist/workers/editor/common/colorizedBracketPairsDecorationProvider.js +97 -0
- package/dist/workers/editor/common/columnRange.js +35 -0
- package/dist/workers/editor/common/combineTextEditInfos.js +124 -0
- package/dist/workers/editor/common/common.js +20 -0
- package/dist/workers/editor/common/computeMovedLines.js +249 -0
- package/dist/workers/editor/common/concat23Trees.js +192 -0
- package/dist/workers/editor/common/contiguousMultilineTokens.js +32 -0
- package/dist/workers/editor/common/contiguousMultilineTokensBuilder.js +23 -0
- package/dist/workers/editor/common/contiguousTokensEditing.js +128 -0
- package/dist/workers/editor/common/contiguousTokensStore.js +207 -0
- package/dist/workers/editor/common/coordinatesConverter.js +51 -0
- package/dist/workers/editor/common/cursor.js +899 -0
- package/dist/workers/editor/common/cursorAtomicMoveOperations.js +145 -0
- package/dist/workers/editor/common/cursorCollection.js +194 -0
- package/dist/workers/editor/common/cursorColumnSelection.js +93 -0
- package/dist/workers/editor/common/cursorColumns.js +112 -0
- package/dist/workers/editor/common/cursorCommon.js +250 -0
- package/dist/workers/editor/common/cursorContext.js +15 -0
- package/dist/workers/editor/common/cursorDeleteOperations.js +231 -0
- package/dist/workers/editor/common/cursorMoveCommands.js +676 -0
- package/dist/workers/editor/common/cursorMoveOperations.js +290 -0
- package/dist/workers/editor/common/cursorTypeEditOperations.js +968 -0
- package/dist/workers/editor/common/cursorTypeOperations.js +173 -0
- package/dist/workers/editor/common/cursorUtils.js +75 -0
- package/dist/workers/editor/common/cursorWordOperations.js +720 -0
- package/dist/workers/editor/common/defaultDocumentColorsComputer.js +138 -0
- package/dist/workers/editor/common/defaultLinesDiffComputer.js +188 -0
- package/dist/workers/editor/common/diffAlgorithm.js +139 -0
- package/dist/workers/editor/common/diffEditor.js +38 -0
- package/dist/workers/editor/common/dynamicProgrammingDiffing.js +101 -0
- package/dist/workers/editor/common/edit.js +183 -0
- package/dist/workers/editor/common/editOperation.js +36 -0
- package/dist/workers/editor/common/editStack.js +363 -0
- package/dist/workers/editor/common/editorAction.js +26 -0
- package/dist/workers/editor/common/editorBaseApi.js +43 -0
- package/dist/workers/editor/common/editorColorRegistry.js +102 -0
- package/dist/workers/editor/common/editorCommon.js +13 -0
- package/dist/workers/editor/common/editorConfigurationSchema.js +338 -0
- package/dist/workers/editor/common/editorContextKeys.js +84 -0
- package/dist/workers/editor/common/editorFeatures.js +17 -0
- package/dist/workers/editor/common/editorOptions.js +3440 -0
- package/dist/workers/editor/common/editorTheme.js +23 -0
- package/dist/workers/editor/common/editorWebWorker.js +299 -0
- package/dist/workers/editor/common/editorWorker.js +9 -0
- package/dist/workers/editor/common/editorWorkerHost.js +15 -0
- package/dist/workers/editor/common/editorZoom.js +26 -0
- package/dist/workers/editor/common/electricCharacter.js +55 -0
- package/dist/workers/editor/common/encodedTokenAttributes.js +79 -0
- package/dist/workers/editor/common/enterAction.js +53 -0
- package/dist/workers/editor/common/eolCounter.js +44 -0
- package/dist/workers/editor/common/findSectionHeaders.js +128 -0
- package/dist/workers/editor/common/fixBrackets.js +67 -0
- package/dist/workers/editor/common/fixedArray.js +70 -0
- package/dist/workers/editor/common/fontInfo.js +172 -0
- package/dist/workers/editor/common/fontInfoFromSettings.js +29 -0
- package/dist/workers/editor/common/getIconClasses.js +106 -0
- package/dist/workers/editor/common/getPositionOffsetTransformerFromTextModel.js +24 -0
- package/dist/workers/editor/common/glyphLanesModel.js +61 -0
- package/dist/workers/editor/common/guidesTextModelPart.js +405 -0
- package/dist/workers/editor/common/heuristicSequenceOptimizations.js +374 -0
- package/dist/workers/editor/common/indentRules.js +63 -0
- package/dist/workers/editor/common/indentation.js +39 -0
- package/dist/workers/editor/common/indentationGuesser.js +178 -0
- package/dist/workers/editor/common/indentationLineProcessor.js +193 -0
- package/dist/workers/editor/common/inlineDecorations.js +26 -0
- package/dist/workers/editor/common/inplaceReplaceSupport.js +87 -0
- package/dist/workers/editor/common/inputMode.js +22 -0
- package/dist/workers/editor/common/intervalTree.js +1002 -0
- package/dist/workers/editor/common/language.js +9 -0
- package/dist/workers/editor/common/languageBracketsConfiguration.js +133 -0
- package/dist/workers/editor/common/languageConfiguration.js +138 -0
- package/dist/workers/editor/common/languageConfigurationRegistry.js +361 -0
- package/dist/workers/editor/common/languageFeatureDebounce.js +137 -0
- package/dist/workers/editor/common/languageFeatureRegistry.js +180 -0
- package/dist/workers/editor/common/languageFeatures.js +9 -0
- package/dist/workers/editor/common/languageFeaturesService.js +47 -0
- package/dist/workers/editor/common/languageSelector.js +112 -0
- package/dist/workers/editor/common/languageService.js +92 -0
- package/dist/workers/editor/common/languages.js +522 -0
- package/dist/workers/editor/common/languagesAssociations.js +193 -0
- package/dist/workers/editor/common/languagesRegistry.js +237 -0
- package/dist/workers/editor/common/legacyLinesDiffComputer.js +468 -0
- package/dist/workers/editor/common/length.js +129 -0
- package/dist/workers/editor/common/lineDecorations.js +208 -0
- package/dist/workers/editor/common/lineEdit.js +75 -0
- package/dist/workers/editor/common/lineHeights.js +370 -0
- package/dist/workers/editor/common/linePart.js +25 -0
- package/dist/workers/editor/common/lineRange.js +312 -0
- package/dist/workers/editor/common/lineSequence.js +36 -0
- package/dist/workers/editor/common/lineTokens.js +405 -0
- package/dist/workers/editor/common/linesDiffComputer.js +29 -0
- package/dist/workers/editor/common/linesDiffComputers.js +13 -0
- package/dist/workers/editor/common/linesLayout.js +765 -0
- package/dist/workers/editor/common/linesSliceCharSequence.js +205 -0
- package/dist/workers/editor/common/linkComputer.js +269 -0
- package/dist/workers/editor/common/markerDecorations.js +9 -0
- package/dist/workers/editor/common/markerDecorationsService.js +248 -0
- package/dist/workers/editor/common/minimapTokensColorTracker.js +58 -0
- package/dist/workers/editor/common/mirrorTextModel.js +117 -0
- package/dist/workers/editor/common/model.js +9 -0
- package/dist/workers/editor/common/modelLineProjection.js +350 -0
- package/dist/workers/editor/common/modelLineProjectionData.js +297 -0
- package/dist/workers/editor/common/modelService.js +413 -0
- package/dist/workers/editor/common/modesRegistry.js +75 -0
- package/dist/workers/editor/common/monospaceLineBreaksComputer.js +473 -0
- package/dist/workers/editor/common/myersDiffAlgorithm.js +159 -0
- package/dist/workers/editor/common/nodeReader.js +127 -0
- package/dist/workers/editor/common/nullTokenize.js +29 -0
- package/dist/workers/editor/common/offsetRange.js +225 -0
- package/dist/workers/editor/common/onEnter.js +109 -0
- package/dist/workers/editor/common/oneCursor.js +117 -0
- package/dist/workers/editor/common/overviewZoneManager.js +176 -0
- package/dist/workers/editor/common/parser.js +121 -0
- package/dist/workers/editor/common/pieceTreeBase.js +1473 -0
- package/dist/workers/editor/common/pieceTreeTextBuffer.js +461 -0
- package/dist/workers/editor/common/pieceTreeTextBufferBuilder.js +140 -0
- package/dist/workers/editor/common/point.js +50 -0
- package/dist/workers/editor/common/position.js +142 -0
- package/dist/workers/editor/common/positionToOffset.js +17 -0
- package/dist/workers/editor/common/positionToOffsetImpl.js +98 -0
- package/dist/workers/editor/common/prefixSumComputer.js +226 -0
- package/dist/workers/editor/common/range.js +421 -0
- package/dist/workers/editor/common/rangeMapping.js +229 -0
- package/dist/workers/editor/common/rangeSingleLine.js +17 -0
- package/dist/workers/editor/common/rbTreeBase.js +362 -0
- package/dist/workers/editor/common/rect.js +163 -0
- package/dist/workers/editor/common/replaceCommand.js +158 -0
- package/dist/workers/editor/common/resolverService.js +5 -0
- package/dist/workers/editor/common/rgba.js +35 -0
- package/dist/workers/editor/common/richEditBrackets.js +356 -0
- package/dist/workers/editor/common/selection.js +145 -0
- package/dist/workers/editor/common/semanticTokensDto.js +82 -0
- package/dist/workers/editor/common/semanticTokensProviderStyling.js +263 -0
- package/dist/workers/editor/common/semanticTokensStyling.js +9 -0
- package/dist/workers/editor/common/semanticTokensStylingService.js +47 -0
- package/dist/workers/editor/common/shiftCommand.js +241 -0
- package/dist/workers/editor/common/smallImmutableSet.js +108 -0
- package/dist/workers/editor/common/sparseMultilineTokens.js +548 -0
- package/dist/workers/editor/common/sparseTokensStore.js +210 -0
- package/dist/workers/editor/common/standaloneEnums.js +1017 -0
- package/dist/workers/editor/common/standaloneStrings.js +42 -0
- package/dist/workers/editor/common/stringBuilder.js +122 -0
- package/dist/workers/editor/common/stringEdit.js +165 -0
- package/dist/workers/editor/common/supports.js +58 -0
- package/dist/workers/editor/common/surroundSelectionCommand.js +44 -0
- package/dist/workers/editor/common/textChange.js +248 -0
- package/dist/workers/editor/common/textEdit.js +269 -0
- package/dist/workers/editor/common/textLength.js +87 -0
- package/dist/workers/editor/common/textModel.js +2031 -0
- package/dist/workers/editor/common/textModelBracketPairs.js +45 -0
- package/dist/workers/editor/common/textModelDefaults.js +18 -0
- package/dist/workers/editor/common/textModelEditSource.js +166 -0
- package/dist/workers/editor/common/textModelEvents.js +216 -0
- package/dist/workers/editor/common/textModelGuides.js +40 -0
- package/dist/workers/editor/common/textModelPart.js +23 -0
- package/dist/workers/editor/common/textModelSearch.js +455 -0
- package/dist/workers/editor/common/textModelStringEdit.js +11 -0
- package/dist/workers/editor/common/textModelSync.impl.js +307 -0
- package/dist/workers/editor/common/textModelText.js +26 -0
- package/dist/workers/editor/common/textModelTokens.js +436 -0
- package/dist/workers/editor/common/textResourceConfiguration.js +6 -0
- package/dist/workers/editor/common/textToHtmlTokenizer.js +139 -0
- package/dist/workers/editor/common/tokenStore.js +407 -0
- package/dist/workers/editor/common/tokenWithTextArray.js +73 -0
- package/dist/workers/editor/common/tokenization.js +287 -0
- package/dist/workers/editor/common/tokenizationRegistry.js +123 -0
- package/dist/workers/editor/common/tokenizationTextModelPart.js +275 -0
- package/dist/workers/editor/common/tokenizer.js +301 -0
- package/dist/workers/editor/common/tokenizerSyntaxTokenBackend.js +261 -0
- package/dist/workers/editor/common/treeSitterLibraryService.js +9 -0
- package/dist/workers/editor/common/treeSitterSyntaxTokenBackend.js +167 -0
- package/dist/workers/editor/common/treeSitterThemeService.js +9 -0
- package/dist/workers/editor/common/treeSitterTokenizationImpl.js +713 -0
- package/dist/workers/editor/common/treeSitterTree.js +395 -0
- package/dist/workers/editor/common/treeViewsDnd.js +24 -0
- package/dist/workers/editor/common/treeViewsDndService.js +12 -0
- package/dist/workers/editor/common/trimTrailingWhitespaceCommand.js +98 -0
- package/dist/workers/editor/common/unicodeTextModelHighlighter.js +188 -0
- package/dist/workers/editor/common/utils.js +62 -0
- package/dist/workers/editor/common/viewContext.js +22 -0
- package/dist/workers/editor/common/viewEventHandler.js +186 -0
- package/dist/workers/editor/common/viewEvents.js +180 -0
- package/dist/workers/editor/common/viewLayout.js +368 -0
- package/dist/workers/editor/common/viewLineRenderer.js +948 -0
- package/dist/workers/editor/common/viewLinesViewportData.js +30 -0
- package/dist/workers/editor/common/viewModel.js +98 -0
- package/dist/workers/editor/common/viewModelDecoration.js +55 -0
- package/dist/workers/editor/common/viewModelDecorations.js +132 -0
- package/dist/workers/editor/common/viewModelEventDispatcher.js +398 -0
- package/dist/workers/editor/common/viewModelImpl.js +1163 -0
- package/dist/workers/editor/common/viewModelLines.js +938 -0
- package/dist/workers/editor/common/wordCharacterClassifier.js +87 -0
- package/dist/workers/editor/common/wordHelper.js +127 -0
- package/dist/workers/editor/editor.worker.js +11 -0
- package/dist/workers/language/css.worker.js +8 -0
- package/dist/workers/language/cssMode.js +198 -0
- package/dist/workers/language/cssWorker.js +183 -0
- package/dist/workers/language/html.worker.js +8 -0
- package/dist/workers/language/htmlMode.js +213 -0
- package/dist/workers/language/htmlWorker.js +126 -0
- package/dist/workers/language/json.worker.js +8 -0
- package/dist/workers/language/jsonMode.js +224 -0
- package/dist/workers/language/jsonWorker.js +187 -0
- package/dist/workers/language/languageFeatures.js +1009 -0
- package/dist/workers/language/lib.index.js +103 -0
- package/dist/workers/language/lib.js +1107 -0
- package/dist/workers/language/lspLanguageFeatures.js +716 -0
- package/dist/workers/language/monaco.contribution.js +144 -0
- package/dist/workers/language/tokenization.js +189 -0
- package/dist/workers/language/ts.worker.js +14 -0
- package/dist/workers/language/tsMode.js +212 -0
- package/dist/workers/language/tsWorker.js +352 -0
- package/dist/workers/language/typescriptServices.js +210154 -0
- package/dist/workers/language/typescriptServicesMetadata.js +3 -0
- package/dist/workers/language/workerManager.js +65 -0
- package/package.json +3 -2
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { Color } from '../../../../base/common/color.js';
|
|
2
|
+
|
|
3
|
+
/*---------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
6
|
+
*--------------------------------------------------------------------------------------------*/
|
|
7
|
+
class ParsedTokenThemeRule {
|
|
8
|
+
constructor(token, index, fontStyle, foreground, background) {
|
|
9
|
+
this._parsedThemeRuleBrand = undefined;
|
|
10
|
+
this.token = token;
|
|
11
|
+
this.index = index;
|
|
12
|
+
this.fontStyle = fontStyle;
|
|
13
|
+
this.foreground = foreground;
|
|
14
|
+
this.background = background;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Parse a raw theme into rules.
|
|
19
|
+
*/
|
|
20
|
+
function parseTokenTheme(source) {
|
|
21
|
+
if (!source || !Array.isArray(source)) {
|
|
22
|
+
return [];
|
|
23
|
+
}
|
|
24
|
+
const result = [];
|
|
25
|
+
let resultLen = 0;
|
|
26
|
+
for (let i = 0, len = source.length; i < len; i++) {
|
|
27
|
+
const entry = source[i];
|
|
28
|
+
let fontStyle = -1 /* FontStyle.NotSet */;
|
|
29
|
+
if (typeof entry.fontStyle === 'string') {
|
|
30
|
+
fontStyle = 0 /* FontStyle.None */;
|
|
31
|
+
const segments = entry.fontStyle.split(' ');
|
|
32
|
+
for (let j = 0, lenJ = segments.length; j < lenJ; j++) {
|
|
33
|
+
const segment = segments[j];
|
|
34
|
+
switch (segment) {
|
|
35
|
+
case 'italic':
|
|
36
|
+
fontStyle = fontStyle | 1 /* FontStyle.Italic */;
|
|
37
|
+
break;
|
|
38
|
+
case 'bold':
|
|
39
|
+
fontStyle = fontStyle | 2 /* FontStyle.Bold */;
|
|
40
|
+
break;
|
|
41
|
+
case 'underline':
|
|
42
|
+
fontStyle = fontStyle | 4 /* FontStyle.Underline */;
|
|
43
|
+
break;
|
|
44
|
+
case 'strikethrough':
|
|
45
|
+
fontStyle = fontStyle | 8 /* FontStyle.Strikethrough */;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
let foreground = null;
|
|
51
|
+
if (typeof entry.foreground === 'string') {
|
|
52
|
+
foreground = entry.foreground;
|
|
53
|
+
}
|
|
54
|
+
let background = null;
|
|
55
|
+
if (typeof entry.background === 'string') {
|
|
56
|
+
background = entry.background;
|
|
57
|
+
}
|
|
58
|
+
result[resultLen++] = new ParsedTokenThemeRule(entry.token || '', i, fontStyle, foreground, background);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Resolve rules (i.e. inheritance).
|
|
64
|
+
*/
|
|
65
|
+
function resolveParsedTokenThemeRules(parsedThemeRules, customTokenColors) {
|
|
66
|
+
// Sort rules lexicographically, and then by index if necessary
|
|
67
|
+
parsedThemeRules.sort((a, b) => {
|
|
68
|
+
const r = strcmp(a.token, b.token);
|
|
69
|
+
if (r !== 0) {
|
|
70
|
+
return r;
|
|
71
|
+
}
|
|
72
|
+
return a.index - b.index;
|
|
73
|
+
});
|
|
74
|
+
// Determine defaults
|
|
75
|
+
let defaultFontStyle = 0 /* FontStyle.None */;
|
|
76
|
+
let defaultForeground = '000000';
|
|
77
|
+
let defaultBackground = 'ffffff';
|
|
78
|
+
while (parsedThemeRules.length >= 1 && parsedThemeRules[0].token === '') {
|
|
79
|
+
const incomingDefaults = parsedThemeRules.shift();
|
|
80
|
+
if (incomingDefaults.fontStyle !== -1 /* FontStyle.NotSet */) {
|
|
81
|
+
defaultFontStyle = incomingDefaults.fontStyle;
|
|
82
|
+
}
|
|
83
|
+
if (incomingDefaults.foreground !== null) {
|
|
84
|
+
defaultForeground = incomingDefaults.foreground;
|
|
85
|
+
}
|
|
86
|
+
if (incomingDefaults.background !== null) {
|
|
87
|
+
defaultBackground = incomingDefaults.background;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const colorMap = new ColorMap();
|
|
91
|
+
// start with token colors from custom token themes
|
|
92
|
+
for (const color of customTokenColors) {
|
|
93
|
+
colorMap.getId(color);
|
|
94
|
+
}
|
|
95
|
+
const foregroundColorId = colorMap.getId(defaultForeground);
|
|
96
|
+
const backgroundColorId = colorMap.getId(defaultBackground);
|
|
97
|
+
const defaults = new ThemeTrieElementRule(defaultFontStyle, foregroundColorId, backgroundColorId);
|
|
98
|
+
const root = new ThemeTrieElement(defaults);
|
|
99
|
+
for (let i = 0, len = parsedThemeRules.length; i < len; i++) {
|
|
100
|
+
const rule = parsedThemeRules[i];
|
|
101
|
+
root.insert(rule.token, rule.fontStyle, colorMap.getId(rule.foreground), colorMap.getId(rule.background));
|
|
102
|
+
}
|
|
103
|
+
return new TokenTheme(colorMap, root);
|
|
104
|
+
}
|
|
105
|
+
const colorRegExp = /^#?([0-9A-Fa-f]{6})([0-9A-Fa-f]{2})?$/;
|
|
106
|
+
class ColorMap {
|
|
107
|
+
constructor() {
|
|
108
|
+
this._lastColorId = 0;
|
|
109
|
+
this._id2color = [];
|
|
110
|
+
this._color2id = new Map();
|
|
111
|
+
}
|
|
112
|
+
getId(color) {
|
|
113
|
+
if (color === null) {
|
|
114
|
+
return 0;
|
|
115
|
+
}
|
|
116
|
+
const match = color.match(colorRegExp);
|
|
117
|
+
if (!match) {
|
|
118
|
+
throw new Error('Illegal value for token color: ' + color);
|
|
119
|
+
}
|
|
120
|
+
color = match[1].toUpperCase();
|
|
121
|
+
let value = this._color2id.get(color);
|
|
122
|
+
if (value) {
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
value = ++this._lastColorId;
|
|
126
|
+
this._color2id.set(color, value);
|
|
127
|
+
this._id2color[value] = Color.fromHex('#' + color);
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
getColorMap() {
|
|
131
|
+
return this._id2color.slice(0);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
class TokenTheme {
|
|
135
|
+
static createFromRawTokenTheme(source, customTokenColors) {
|
|
136
|
+
return this.createFromParsedTokenTheme(parseTokenTheme(source), customTokenColors);
|
|
137
|
+
}
|
|
138
|
+
static createFromParsedTokenTheme(source, customTokenColors) {
|
|
139
|
+
return resolveParsedTokenThemeRules(source, customTokenColors);
|
|
140
|
+
}
|
|
141
|
+
constructor(colorMap, root) {
|
|
142
|
+
this._colorMap = colorMap;
|
|
143
|
+
this._root = root;
|
|
144
|
+
this._cache = new Map();
|
|
145
|
+
}
|
|
146
|
+
getColorMap() {
|
|
147
|
+
return this._colorMap.getColorMap();
|
|
148
|
+
}
|
|
149
|
+
_match(token) {
|
|
150
|
+
return this._root.match(token);
|
|
151
|
+
}
|
|
152
|
+
match(languageId, token) {
|
|
153
|
+
// The cache contains the metadata without the language bits set.
|
|
154
|
+
let result = this._cache.get(token);
|
|
155
|
+
if (typeof result === 'undefined') {
|
|
156
|
+
const rule = this._match(token);
|
|
157
|
+
const standardToken = toStandardTokenType(token);
|
|
158
|
+
result = (rule.metadata
|
|
159
|
+
| (standardToken << 8 /* MetadataConsts.TOKEN_TYPE_OFFSET */)) >>> 0;
|
|
160
|
+
this._cache.set(token, result);
|
|
161
|
+
}
|
|
162
|
+
return (result
|
|
163
|
+
| (languageId << 0 /* MetadataConsts.LANGUAGEID_OFFSET */)) >>> 0;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const STANDARD_TOKEN_TYPE_REGEXP = /\b(comment|string|regex|regexp)\b/;
|
|
167
|
+
function toStandardTokenType(tokenType) {
|
|
168
|
+
const m = tokenType.match(STANDARD_TOKEN_TYPE_REGEXP);
|
|
169
|
+
if (!m) {
|
|
170
|
+
return 0 /* StandardTokenType.Other */;
|
|
171
|
+
}
|
|
172
|
+
switch (m[1]) {
|
|
173
|
+
case 'comment':
|
|
174
|
+
return 1 /* StandardTokenType.Comment */;
|
|
175
|
+
case 'string':
|
|
176
|
+
return 2 /* StandardTokenType.String */;
|
|
177
|
+
case 'regex':
|
|
178
|
+
return 3 /* StandardTokenType.RegEx */;
|
|
179
|
+
case 'regexp':
|
|
180
|
+
return 3 /* StandardTokenType.RegEx */;
|
|
181
|
+
}
|
|
182
|
+
throw new Error('Unexpected match for standard token type!');
|
|
183
|
+
}
|
|
184
|
+
function strcmp(a, b) {
|
|
185
|
+
if (a < b) {
|
|
186
|
+
return -1;
|
|
187
|
+
}
|
|
188
|
+
if (a > b) {
|
|
189
|
+
return 1;
|
|
190
|
+
}
|
|
191
|
+
return 0;
|
|
192
|
+
}
|
|
193
|
+
class ThemeTrieElementRule {
|
|
194
|
+
constructor(fontStyle, foreground, background) {
|
|
195
|
+
this._themeTrieElementRuleBrand = undefined;
|
|
196
|
+
this._fontStyle = fontStyle;
|
|
197
|
+
this._foreground = foreground;
|
|
198
|
+
this._background = background;
|
|
199
|
+
this.metadata = ((this._fontStyle << 11 /* MetadataConsts.FONT_STYLE_OFFSET */)
|
|
200
|
+
| (this._foreground << 15 /* MetadataConsts.FOREGROUND_OFFSET */)
|
|
201
|
+
| (this._background << 24 /* MetadataConsts.BACKGROUND_OFFSET */)) >>> 0;
|
|
202
|
+
}
|
|
203
|
+
clone() {
|
|
204
|
+
return new ThemeTrieElementRule(this._fontStyle, this._foreground, this._background);
|
|
205
|
+
}
|
|
206
|
+
acceptOverwrite(fontStyle, foreground, background) {
|
|
207
|
+
if (fontStyle !== -1 /* FontStyle.NotSet */) {
|
|
208
|
+
this._fontStyle = fontStyle;
|
|
209
|
+
}
|
|
210
|
+
if (foreground !== 0 /* ColorId.None */) {
|
|
211
|
+
this._foreground = foreground;
|
|
212
|
+
}
|
|
213
|
+
if (background !== 0 /* ColorId.None */) {
|
|
214
|
+
this._background = background;
|
|
215
|
+
}
|
|
216
|
+
this.metadata = ((this._fontStyle << 11 /* MetadataConsts.FONT_STYLE_OFFSET */)
|
|
217
|
+
| (this._foreground << 15 /* MetadataConsts.FOREGROUND_OFFSET */)
|
|
218
|
+
| (this._background << 24 /* MetadataConsts.BACKGROUND_OFFSET */)) >>> 0;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
class ThemeTrieElement {
|
|
222
|
+
constructor(mainRule) {
|
|
223
|
+
this._themeTrieElementBrand = undefined;
|
|
224
|
+
this._mainRule = mainRule;
|
|
225
|
+
this._children = new Map();
|
|
226
|
+
}
|
|
227
|
+
match(token) {
|
|
228
|
+
if (token === '') {
|
|
229
|
+
return this._mainRule;
|
|
230
|
+
}
|
|
231
|
+
const dotIndex = token.indexOf('.');
|
|
232
|
+
let head;
|
|
233
|
+
let tail;
|
|
234
|
+
if (dotIndex === -1) {
|
|
235
|
+
head = token;
|
|
236
|
+
tail = '';
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
head = token.substring(0, dotIndex);
|
|
240
|
+
tail = token.substring(dotIndex + 1);
|
|
241
|
+
}
|
|
242
|
+
const child = this._children.get(head);
|
|
243
|
+
if (typeof child !== 'undefined') {
|
|
244
|
+
return child.match(tail);
|
|
245
|
+
}
|
|
246
|
+
return this._mainRule;
|
|
247
|
+
}
|
|
248
|
+
insert(token, fontStyle, foreground, background) {
|
|
249
|
+
if (token === '') {
|
|
250
|
+
// Merge into the main rule
|
|
251
|
+
this._mainRule.acceptOverwrite(fontStyle, foreground, background);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const dotIndex = token.indexOf('.');
|
|
255
|
+
let head;
|
|
256
|
+
let tail;
|
|
257
|
+
if (dotIndex === -1) {
|
|
258
|
+
head = token;
|
|
259
|
+
tail = '';
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
head = token.substring(0, dotIndex);
|
|
263
|
+
tail = token.substring(dotIndex + 1);
|
|
264
|
+
}
|
|
265
|
+
let child = this._children.get(head);
|
|
266
|
+
if (typeof child === 'undefined') {
|
|
267
|
+
child = new ThemeTrieElement(this._mainRule.clone());
|
|
268
|
+
this._children.set(head, child);
|
|
269
|
+
}
|
|
270
|
+
child.insert(tail, fontStyle, foreground, background);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
function generateTokensCSSForColorMap(colorMap) {
|
|
274
|
+
const rules = [];
|
|
275
|
+
for (let i = 1, len = colorMap.length; i < len; i++) {
|
|
276
|
+
const color = colorMap[i];
|
|
277
|
+
rules[i] = `.mtk${i} { color: ${color}; }`;
|
|
278
|
+
}
|
|
279
|
+
rules.push('.mtki { font-style: italic; }');
|
|
280
|
+
rules.push('.mtkb { font-weight: bold; }');
|
|
281
|
+
rules.push('.mtku { text-decoration: underline; text-underline-position: under; }');
|
|
282
|
+
rules.push('.mtks { text-decoration: line-through; }');
|
|
283
|
+
rules.push('.mtks.mtku { text-decoration: underline line-through; text-underline-position: under; }');
|
|
284
|
+
return rules.join('\n');
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export { ColorMap, ParsedTokenThemeRule, ThemeTrieElement, ThemeTrieElementRule, TokenTheme, generateTokensCSSForColorMap, parseTokenTheme, strcmp, toStandardTokenType };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { Emitter } from '../../base/common/event.js';
|
|
2
|
+
import { toDisposable, Disposable } from '../../base/common/lifecycle.js';
|
|
3
|
+
|
|
4
|
+
/*---------------------------------------------------------------------------------------------
|
|
5
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
7
|
+
*--------------------------------------------------------------------------------------------*/
|
|
8
|
+
class TokenizationRegistry {
|
|
9
|
+
constructor() {
|
|
10
|
+
this._tokenizationSupports = new Map();
|
|
11
|
+
this._factories = new Map();
|
|
12
|
+
this._onDidChange = new Emitter();
|
|
13
|
+
this.onDidChange = this._onDidChange.event;
|
|
14
|
+
this._colorMap = null;
|
|
15
|
+
}
|
|
16
|
+
handleChange(languageIds) {
|
|
17
|
+
this._onDidChange.fire({
|
|
18
|
+
changedLanguages: languageIds,
|
|
19
|
+
changedColorMap: false
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
register(languageId, support) {
|
|
23
|
+
this._tokenizationSupports.set(languageId, support);
|
|
24
|
+
this.handleChange([languageId]);
|
|
25
|
+
return toDisposable(() => {
|
|
26
|
+
if (this._tokenizationSupports.get(languageId) !== support) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
this._tokenizationSupports.delete(languageId);
|
|
30
|
+
this.handleChange([languageId]);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
get(languageId) {
|
|
34
|
+
return this._tokenizationSupports.get(languageId) || null;
|
|
35
|
+
}
|
|
36
|
+
registerFactory(languageId, factory) {
|
|
37
|
+
this._factories.get(languageId)?.dispose();
|
|
38
|
+
const myData = new TokenizationSupportFactoryData(this, languageId, factory);
|
|
39
|
+
this._factories.set(languageId, myData);
|
|
40
|
+
return toDisposable(() => {
|
|
41
|
+
const v = this._factories.get(languageId);
|
|
42
|
+
if (!v || v !== myData) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this._factories.delete(languageId);
|
|
46
|
+
v.dispose();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
async getOrCreate(languageId) {
|
|
50
|
+
// check first if the support is already set
|
|
51
|
+
const tokenizationSupport = this.get(languageId);
|
|
52
|
+
if (tokenizationSupport) {
|
|
53
|
+
return tokenizationSupport;
|
|
54
|
+
}
|
|
55
|
+
const factory = this._factories.get(languageId);
|
|
56
|
+
if (!factory || factory.isResolved) {
|
|
57
|
+
// no factory or factory.resolve already finished
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
await factory.resolve();
|
|
61
|
+
return this.get(languageId);
|
|
62
|
+
}
|
|
63
|
+
isResolved(languageId) {
|
|
64
|
+
const tokenizationSupport = this.get(languageId);
|
|
65
|
+
if (tokenizationSupport) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
const factory = this._factories.get(languageId);
|
|
69
|
+
if (!factory || factory.isResolved) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
setColorMap(colorMap) {
|
|
75
|
+
this._colorMap = colorMap;
|
|
76
|
+
this._onDidChange.fire({
|
|
77
|
+
changedLanguages: Array.from(this._tokenizationSupports.keys()),
|
|
78
|
+
changedColorMap: true
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
getColorMap() {
|
|
82
|
+
return this._colorMap;
|
|
83
|
+
}
|
|
84
|
+
getDefaultBackground() {
|
|
85
|
+
if (this._colorMap && this._colorMap.length > 2 /* ColorId.DefaultBackground */) {
|
|
86
|
+
return this._colorMap[2 /* ColorId.DefaultBackground */];
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
class TokenizationSupportFactoryData extends Disposable {
|
|
92
|
+
get isResolved() {
|
|
93
|
+
return this._isResolved;
|
|
94
|
+
}
|
|
95
|
+
constructor(_registry, _languageId, _factory) {
|
|
96
|
+
super();
|
|
97
|
+
this._registry = _registry;
|
|
98
|
+
this._languageId = _languageId;
|
|
99
|
+
this._factory = _factory;
|
|
100
|
+
this._isDisposed = false;
|
|
101
|
+
this._resolvePromise = null;
|
|
102
|
+
this._isResolved = false;
|
|
103
|
+
}
|
|
104
|
+
dispose() {
|
|
105
|
+
this._isDisposed = true;
|
|
106
|
+
super.dispose();
|
|
107
|
+
}
|
|
108
|
+
async resolve() {
|
|
109
|
+
if (!this._resolvePromise) {
|
|
110
|
+
this._resolvePromise = this._create();
|
|
111
|
+
}
|
|
112
|
+
return this._resolvePromise;
|
|
113
|
+
}
|
|
114
|
+
async _create() {
|
|
115
|
+
const value = await this._factory.tokenizationSupport;
|
|
116
|
+
this._isResolved = true;
|
|
117
|
+
if (value && !this._isDisposed) {
|
|
118
|
+
this._register(this._registry.register(this._languageId, value));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export { TokenizationRegistry };
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { BugIndicatingError } from '../../../../base/common/errors.js';
|
|
2
|
+
import { Emitter } from '../../../../base/common/event.js';
|
|
3
|
+
import { countEOL } from '../../core/misc/eolCounter.js';
|
|
4
|
+
import { Position } from '../../core/position.js';
|
|
5
|
+
import { getWordAtText } from '../../core/wordHelper.js';
|
|
6
|
+
import { ILanguageService } from '../../languages/language.js';
|
|
7
|
+
import { ILanguageConfigurationService } from '../../languages/languageConfigurationRegistry.js';
|
|
8
|
+
import { TextModelPart } from '../textModelPart.js';
|
|
9
|
+
import { TreeSitterSyntaxTokenBackend } from './treeSitter/treeSitterSyntaxTokenBackend.js';
|
|
10
|
+
import { SparseTokensStore } from '../../tokens/sparseTokensStore.js';
|
|
11
|
+
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
|
|
12
|
+
import { TokenizerSyntaxTokenBackend } from './tokenizerSyntaxTokenBackend.js';
|
|
13
|
+
import { ITreeSitterLibraryService } from '../../services/treeSitter/treeSitterLibraryService.js';
|
|
14
|
+
import '../../../../base/common/observableInternal/index.js';
|
|
15
|
+
import { observableValue } from '../../../../base/common/observableInternal/observables/observableValue.js';
|
|
16
|
+
import { derived } from '../../../../base/common/observableInternal/observables/derived.js';
|
|
17
|
+
|
|
18
|
+
/*---------------------------------------------------------------------------------------------
|
|
19
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
20
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
21
|
+
*--------------------------------------------------------------------------------------------*/
|
|
22
|
+
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
23
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
24
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
25
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
26
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
|
+
};
|
|
28
|
+
var __param = (undefined && undefined.__param) || function (paramIndex, decorator) {
|
|
29
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
30
|
+
};
|
|
31
|
+
var TokenizationTextModelPart_1;
|
|
32
|
+
let TokenizationTextModelPart = TokenizationTextModelPart_1 = class TokenizationTextModelPart extends TextModelPart {
|
|
33
|
+
constructor(_textModel, _bracketPairsTextModelPart, _languageId, _attachedViews, _languageService, _languageConfigurationService, _instantiationService, _treeSitterLibraryService) {
|
|
34
|
+
super();
|
|
35
|
+
this._textModel = _textModel;
|
|
36
|
+
this._bracketPairsTextModelPart = _bracketPairsTextModelPart;
|
|
37
|
+
this._languageId = _languageId;
|
|
38
|
+
this._attachedViews = _attachedViews;
|
|
39
|
+
this._languageService = _languageService;
|
|
40
|
+
this._languageConfigurationService = _languageConfigurationService;
|
|
41
|
+
this._instantiationService = _instantiationService;
|
|
42
|
+
this._treeSitterLibraryService = _treeSitterLibraryService;
|
|
43
|
+
this._languageIdObs = observableValue(this, this._languageId);
|
|
44
|
+
this._useTreeSitter = derived(this, reader => {
|
|
45
|
+
const languageId = this._languageIdObs.read(reader);
|
|
46
|
+
return this._treeSitterLibraryService.supportsLanguage(languageId, reader);
|
|
47
|
+
});
|
|
48
|
+
this.tokens = derived(this, reader => {
|
|
49
|
+
let tokens;
|
|
50
|
+
if (this._useTreeSitter.read(reader)) {
|
|
51
|
+
tokens = reader.store.add(this._instantiationService.createInstance(TreeSitterSyntaxTokenBackend, this._languageIdObs, this._languageService.languageIdCodec, this._textModel, this._attachedViews.visibleLineRanges));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
tokens = reader.store.add(new TokenizerSyntaxTokenBackend(this._languageService.languageIdCodec, this._textModel, () => this._languageId, this._attachedViews));
|
|
55
|
+
}
|
|
56
|
+
reader.store.add(tokens.onDidChangeTokens(e => {
|
|
57
|
+
this._emitModelTokensChangedEvent(e);
|
|
58
|
+
}));
|
|
59
|
+
reader.store.add(tokens.onDidChangeBackgroundTokenizationState(e => {
|
|
60
|
+
this._bracketPairsTextModelPart.handleDidChangeBackgroundTokenizationState();
|
|
61
|
+
}));
|
|
62
|
+
return tokens;
|
|
63
|
+
});
|
|
64
|
+
let hadTokens = false;
|
|
65
|
+
this.tokens.recomputeInitiallyAndOnChange(this._store, value => {
|
|
66
|
+
if (hadTokens) {
|
|
67
|
+
// We need to reset the tokenization, as the new token provider otherwise won't have a chance to provide tokens until some action happens in the editor.
|
|
68
|
+
// TODO@hediet: Look into why this is needed.
|
|
69
|
+
value.todo_resetTokenization();
|
|
70
|
+
}
|
|
71
|
+
hadTokens = true;
|
|
72
|
+
});
|
|
73
|
+
this._semanticTokens = new SparseTokensStore(this._languageService.languageIdCodec);
|
|
74
|
+
this._onDidChangeLanguage = this._register(new Emitter());
|
|
75
|
+
this.onDidChangeLanguage = this._onDidChangeLanguage.event;
|
|
76
|
+
this._onDidChangeLanguageConfiguration = this._register(new Emitter());
|
|
77
|
+
this.onDidChangeLanguageConfiguration = this._onDidChangeLanguageConfiguration.event;
|
|
78
|
+
this._onDidChangeTokens = this._register(new Emitter());
|
|
79
|
+
this.onDidChangeTokens = this._onDidChangeTokens.event;
|
|
80
|
+
}
|
|
81
|
+
handleLanguageConfigurationServiceChange(e) {
|
|
82
|
+
if (e.affects(this._languageId)) {
|
|
83
|
+
this._onDidChangeLanguageConfiguration.fire({});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
handleDidChangeContent(e) {
|
|
87
|
+
if (e.isFlush) {
|
|
88
|
+
this._semanticTokens.flush();
|
|
89
|
+
}
|
|
90
|
+
else if (!e.isEolChange) { // We don't have to do anything on an EOL change
|
|
91
|
+
for (const c of e.changes) {
|
|
92
|
+
const [eolCount, firstLineLength, lastLineLength] = countEOL(c.text);
|
|
93
|
+
this._semanticTokens.acceptEdit(c.range, eolCount, firstLineLength, lastLineLength, c.text.length > 0 ? c.text.charCodeAt(0) : 0 /* CharCode.Null */);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
this.tokens.get().handleDidChangeContent(e);
|
|
97
|
+
}
|
|
98
|
+
handleDidChangeAttached() {
|
|
99
|
+
this.tokens.get().handleDidChangeAttached();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Includes grammar and semantic tokens.
|
|
103
|
+
*/
|
|
104
|
+
getLineTokens(lineNumber) {
|
|
105
|
+
this.validateLineNumber(lineNumber);
|
|
106
|
+
const syntacticTokens = this.tokens.get().getLineTokens(lineNumber);
|
|
107
|
+
return this._semanticTokens.addSparseTokens(lineNumber, syntacticTokens);
|
|
108
|
+
}
|
|
109
|
+
_emitModelTokensChangedEvent(e) {
|
|
110
|
+
if (!this._textModel._isDisposing()) {
|
|
111
|
+
this._bracketPairsTextModelPart.handleDidChangeTokens(e);
|
|
112
|
+
this._onDidChangeTokens.fire(e);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// #region Grammar Tokens
|
|
116
|
+
validateLineNumber(lineNumber) {
|
|
117
|
+
if (lineNumber < 1 || lineNumber > this._textModel.getLineCount()) {
|
|
118
|
+
throw new BugIndicatingError('Illegal value for lineNumber');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
get hasTokens() {
|
|
122
|
+
return this.tokens.get().hasTokens;
|
|
123
|
+
}
|
|
124
|
+
resetTokenization() {
|
|
125
|
+
this.tokens.get().todo_resetTokenization();
|
|
126
|
+
}
|
|
127
|
+
get backgroundTokenizationState() {
|
|
128
|
+
return this.tokens.get().backgroundTokenizationState;
|
|
129
|
+
}
|
|
130
|
+
forceTokenization(lineNumber) {
|
|
131
|
+
this.validateLineNumber(lineNumber);
|
|
132
|
+
this.tokens.get().forceTokenization(lineNumber);
|
|
133
|
+
}
|
|
134
|
+
hasAccurateTokensForLine(lineNumber) {
|
|
135
|
+
this.validateLineNumber(lineNumber);
|
|
136
|
+
return this.tokens.get().hasAccurateTokensForLine(lineNumber);
|
|
137
|
+
}
|
|
138
|
+
isCheapToTokenize(lineNumber) {
|
|
139
|
+
this.validateLineNumber(lineNumber);
|
|
140
|
+
return this.tokens.get().isCheapToTokenize(lineNumber);
|
|
141
|
+
}
|
|
142
|
+
tokenizeIfCheap(lineNumber) {
|
|
143
|
+
this.validateLineNumber(lineNumber);
|
|
144
|
+
this.tokens.get().tokenizeIfCheap(lineNumber);
|
|
145
|
+
}
|
|
146
|
+
getTokenTypeIfInsertingCharacter(lineNumber, column, character) {
|
|
147
|
+
return this.tokens.get().getTokenTypeIfInsertingCharacter(lineNumber, column, character);
|
|
148
|
+
}
|
|
149
|
+
tokenizeLinesAt(lineNumber, lines) {
|
|
150
|
+
return this.tokens.get().tokenizeLinesAt(lineNumber, lines);
|
|
151
|
+
}
|
|
152
|
+
// #endregion
|
|
153
|
+
// #region Semantic Tokens
|
|
154
|
+
setSemanticTokens(tokens, isComplete) {
|
|
155
|
+
this._semanticTokens.set(tokens, isComplete, this._textModel);
|
|
156
|
+
this._emitModelTokensChangedEvent({
|
|
157
|
+
semanticTokensApplied: tokens !== null,
|
|
158
|
+
ranges: [{ fromLineNumber: 1, toLineNumber: this._textModel.getLineCount() }],
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
hasCompleteSemanticTokens() {
|
|
162
|
+
return this._semanticTokens.isComplete();
|
|
163
|
+
}
|
|
164
|
+
hasSomeSemanticTokens() {
|
|
165
|
+
return !this._semanticTokens.isEmpty();
|
|
166
|
+
}
|
|
167
|
+
setPartialSemanticTokens(range, tokens) {
|
|
168
|
+
if (this.hasCompleteSemanticTokens()) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const changedRange = this._textModel.validateRange(this._semanticTokens.setPartial(range, tokens));
|
|
172
|
+
this._emitModelTokensChangedEvent({
|
|
173
|
+
semanticTokensApplied: true,
|
|
174
|
+
ranges: [
|
|
175
|
+
{
|
|
176
|
+
fromLineNumber: changedRange.startLineNumber,
|
|
177
|
+
toLineNumber: changedRange.endLineNumber,
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
// #endregion
|
|
183
|
+
// #region Utility Methods
|
|
184
|
+
getWordAtPosition(_position) {
|
|
185
|
+
this.assertNotDisposed();
|
|
186
|
+
const position = this._textModel.validatePosition(_position);
|
|
187
|
+
const lineContent = this._textModel.getLineContent(position.lineNumber);
|
|
188
|
+
const lineTokens = this.getLineTokens(position.lineNumber);
|
|
189
|
+
const tokenIndex = lineTokens.findTokenIndexAtOffset(position.column - 1);
|
|
190
|
+
// (1). First try checking right biased word
|
|
191
|
+
const [rbStartOffset, rbEndOffset] = TokenizationTextModelPart_1._findLanguageBoundaries(lineTokens, tokenIndex);
|
|
192
|
+
const rightBiasedWord = getWordAtText(position.column, this.getLanguageConfiguration(lineTokens.getLanguageId(tokenIndex)).getWordDefinition(), lineContent.substring(rbStartOffset, rbEndOffset), rbStartOffset);
|
|
193
|
+
// Make sure the result touches the original passed in position
|
|
194
|
+
if (rightBiasedWord &&
|
|
195
|
+
rightBiasedWord.startColumn <= _position.column &&
|
|
196
|
+
_position.column <= rightBiasedWord.endColumn) {
|
|
197
|
+
return rightBiasedWord;
|
|
198
|
+
}
|
|
199
|
+
// (2). Else, if we were at a language boundary, check the left biased word
|
|
200
|
+
if (tokenIndex > 0 && rbStartOffset === position.column - 1) {
|
|
201
|
+
// edge case, where `position` sits between two tokens belonging to two different languages
|
|
202
|
+
const [lbStartOffset, lbEndOffset] = TokenizationTextModelPart_1._findLanguageBoundaries(lineTokens, tokenIndex - 1);
|
|
203
|
+
const leftBiasedWord = getWordAtText(position.column, this.getLanguageConfiguration(lineTokens.getLanguageId(tokenIndex - 1)).getWordDefinition(), lineContent.substring(lbStartOffset, lbEndOffset), lbStartOffset);
|
|
204
|
+
// Make sure the result touches the original passed in position
|
|
205
|
+
if (leftBiasedWord &&
|
|
206
|
+
leftBiasedWord.startColumn <= _position.column &&
|
|
207
|
+
_position.column <= leftBiasedWord.endColumn) {
|
|
208
|
+
return leftBiasedWord;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
getLanguageConfiguration(languageId) {
|
|
214
|
+
return this._languageConfigurationService.getLanguageConfiguration(languageId);
|
|
215
|
+
}
|
|
216
|
+
static _findLanguageBoundaries(lineTokens, tokenIndex) {
|
|
217
|
+
const languageId = lineTokens.getLanguageId(tokenIndex);
|
|
218
|
+
// go left until a different language is hit
|
|
219
|
+
let startOffset = 0;
|
|
220
|
+
for (let i = tokenIndex; i >= 0 && lineTokens.getLanguageId(i) === languageId; i--) {
|
|
221
|
+
startOffset = lineTokens.getStartOffset(i);
|
|
222
|
+
}
|
|
223
|
+
// go right until a different language is hit
|
|
224
|
+
let endOffset = lineTokens.getLineContent().length;
|
|
225
|
+
for (let i = tokenIndex, tokenCount = lineTokens.getCount(); i < tokenCount && lineTokens.getLanguageId(i) === languageId; i++) {
|
|
226
|
+
endOffset = lineTokens.getEndOffset(i);
|
|
227
|
+
}
|
|
228
|
+
return [startOffset, endOffset];
|
|
229
|
+
}
|
|
230
|
+
getWordUntilPosition(position) {
|
|
231
|
+
const wordAtPosition = this.getWordAtPosition(position);
|
|
232
|
+
if (!wordAtPosition) {
|
|
233
|
+
return { word: '', startColumn: position.column, endColumn: position.column, };
|
|
234
|
+
}
|
|
235
|
+
return {
|
|
236
|
+
word: wordAtPosition.word.substr(0, position.column - wordAtPosition.startColumn),
|
|
237
|
+
startColumn: wordAtPosition.startColumn,
|
|
238
|
+
endColumn: position.column,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
// #endregion
|
|
242
|
+
// #region Language Id handling
|
|
243
|
+
getLanguageId() {
|
|
244
|
+
return this._languageId;
|
|
245
|
+
}
|
|
246
|
+
getLanguageIdAtPosition(lineNumber, column) {
|
|
247
|
+
const position = this._textModel.validatePosition(new Position(lineNumber, column));
|
|
248
|
+
const lineTokens = this.getLineTokens(position.lineNumber);
|
|
249
|
+
return lineTokens.getLanguageId(lineTokens.findTokenIndexAtOffset(position.column - 1));
|
|
250
|
+
}
|
|
251
|
+
setLanguageId(languageId, source = 'api') {
|
|
252
|
+
if (this._languageId === languageId) {
|
|
253
|
+
// There's nothing to do
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const e = {
|
|
257
|
+
oldLanguage: this._languageId,
|
|
258
|
+
newLanguage: languageId,
|
|
259
|
+
source
|
|
260
|
+
};
|
|
261
|
+
this._languageId = languageId;
|
|
262
|
+
this._languageIdObs.set(languageId, undefined);
|
|
263
|
+
this._bracketPairsTextModelPart.handleDidChangeLanguage(e);
|
|
264
|
+
this._onDidChangeLanguage.fire(e);
|
|
265
|
+
this._onDidChangeLanguageConfiguration.fire({});
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
TokenizationTextModelPart = TokenizationTextModelPart_1 = __decorate([
|
|
269
|
+
__param(4, ILanguageService),
|
|
270
|
+
__param(5, ILanguageConfigurationService),
|
|
271
|
+
__param(6, IInstantiationService),
|
|
272
|
+
__param(7, ITreeSitterLibraryService)
|
|
273
|
+
], TokenizationTextModelPart);
|
|
274
|
+
|
|
275
|
+
export { TokenizationTextModelPart };
|