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,343 @@
|
|
|
1
|
+
import { Emitter } from '../../../../../base/common/event.js';
|
|
2
|
+
import { Disposable } from '../../../../../base/common/lifecycle.js';
|
|
3
|
+
import { BracketInfo, BracketPairWithMinIndentationInfo } from '../../../textModelBracketPairs.js';
|
|
4
|
+
import { TextEditInfo } from './beforeEditPositionMapper.js';
|
|
5
|
+
import { LanguageAgnosticBracketTokens } from './brackets.js';
|
|
6
|
+
import { toLength, lengthZero, positionToLength, lengthsToRange, lengthAdd, lengthLessThanEqual, lengthGreaterThanEqual, lengthLessThan } from './length.js';
|
|
7
|
+
import { parseDocument } from './parser.js';
|
|
8
|
+
import { DenseKeyProvider } from './smallImmutableSet.js';
|
|
9
|
+
import { FastTokenizer, TextBufferTokenizer } from './tokenizer.js';
|
|
10
|
+
import { CallbackIterable } from '../../../../../base/common/arrays.js';
|
|
11
|
+
import { combineTextEditInfos } from './combineTextEditInfos.js';
|
|
12
|
+
|
|
13
|
+
/*---------------------------------------------------------------------------------------------
|
|
14
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
15
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
16
|
+
*--------------------------------------------------------------------------------------------*/
|
|
17
|
+
class BracketPairsTree extends Disposable {
|
|
18
|
+
didLanguageChange(languageId) {
|
|
19
|
+
return this.brackets.didLanguageChange(languageId);
|
|
20
|
+
}
|
|
21
|
+
constructor(textModel, getLanguageConfiguration) {
|
|
22
|
+
super();
|
|
23
|
+
this.textModel = textModel;
|
|
24
|
+
this.getLanguageConfiguration = getLanguageConfiguration;
|
|
25
|
+
this.didChangeEmitter = new Emitter();
|
|
26
|
+
this.denseKeyProvider = new DenseKeyProvider();
|
|
27
|
+
this.brackets = new LanguageAgnosticBracketTokens(this.denseKeyProvider, this.getLanguageConfiguration);
|
|
28
|
+
this.onDidChange = this.didChangeEmitter.event;
|
|
29
|
+
this.queuedTextEditsForInitialAstWithoutTokens = [];
|
|
30
|
+
this.queuedTextEdits = [];
|
|
31
|
+
if (!textModel.tokenization.hasTokens) {
|
|
32
|
+
const brackets = this.brackets.getSingleLanguageBracketTokens(this.textModel.getLanguageId());
|
|
33
|
+
const tokenizer = new FastTokenizer(this.textModel.getValue(), brackets);
|
|
34
|
+
this.initialAstWithoutTokens = parseDocument(tokenizer, [], undefined, true);
|
|
35
|
+
this.astWithTokens = this.initialAstWithoutTokens;
|
|
36
|
+
}
|
|
37
|
+
else if (textModel.tokenization.backgroundTokenizationState === 2 /* BackgroundTokenizationState.Completed */) {
|
|
38
|
+
// Skip the initial ast, as there is no flickering.
|
|
39
|
+
// Directly create the tree with token information.
|
|
40
|
+
this.initialAstWithoutTokens = undefined;
|
|
41
|
+
this.astWithTokens = this.parseDocumentFromTextBuffer([], undefined, false);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
// We missed some token changes already, so we cannot use the fast tokenizer + delta increments
|
|
45
|
+
this.initialAstWithoutTokens = this.parseDocumentFromTextBuffer([], undefined, true);
|
|
46
|
+
this.astWithTokens = this.initialAstWithoutTokens;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//#region TextModel events
|
|
50
|
+
handleDidChangeBackgroundTokenizationState() {
|
|
51
|
+
if (this.textModel.tokenization.backgroundTokenizationState === 2 /* BackgroundTokenizationState.Completed */) {
|
|
52
|
+
const wasUndefined = this.initialAstWithoutTokens === undefined;
|
|
53
|
+
// Clear the initial tree as we can use the tree with token information now.
|
|
54
|
+
this.initialAstWithoutTokens = undefined;
|
|
55
|
+
if (!wasUndefined) {
|
|
56
|
+
this.didChangeEmitter.fire();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
handleDidChangeTokens({ ranges }) {
|
|
61
|
+
const edits = ranges.map(r => new TextEditInfo(toLength(r.fromLineNumber - 1, 0), toLength(r.toLineNumber, 0), toLength(r.toLineNumber - r.fromLineNumber + 1, 0)));
|
|
62
|
+
this.handleEdits(edits, true);
|
|
63
|
+
if (!this.initialAstWithoutTokens) {
|
|
64
|
+
this.didChangeEmitter.fire();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
handleContentChanged(change) {
|
|
68
|
+
const edits = TextEditInfo.fromModelContentChanges(change.changes);
|
|
69
|
+
this.handleEdits(edits, false);
|
|
70
|
+
}
|
|
71
|
+
handleEdits(edits, tokenChange) {
|
|
72
|
+
// Lazily queue the edits and only apply them when the tree is accessed.
|
|
73
|
+
const result = combineTextEditInfos(this.queuedTextEdits, edits);
|
|
74
|
+
this.queuedTextEdits = result;
|
|
75
|
+
if (this.initialAstWithoutTokens && !tokenChange) {
|
|
76
|
+
this.queuedTextEditsForInitialAstWithoutTokens = combineTextEditInfos(this.queuedTextEditsForInitialAstWithoutTokens, edits);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//#endregion
|
|
80
|
+
flushQueue() {
|
|
81
|
+
if (this.queuedTextEdits.length > 0) {
|
|
82
|
+
this.astWithTokens = this.parseDocumentFromTextBuffer(this.queuedTextEdits, this.astWithTokens, false);
|
|
83
|
+
this.queuedTextEdits = [];
|
|
84
|
+
}
|
|
85
|
+
if (this.queuedTextEditsForInitialAstWithoutTokens.length > 0) {
|
|
86
|
+
if (this.initialAstWithoutTokens) {
|
|
87
|
+
this.initialAstWithoutTokens = this.parseDocumentFromTextBuffer(this.queuedTextEditsForInitialAstWithoutTokens, this.initialAstWithoutTokens, false);
|
|
88
|
+
}
|
|
89
|
+
this.queuedTextEditsForInitialAstWithoutTokens = [];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @pure (only if isPure = true)
|
|
94
|
+
*/
|
|
95
|
+
parseDocumentFromTextBuffer(edits, previousAst, immutable) {
|
|
96
|
+
const previousAstClone = previousAst;
|
|
97
|
+
const tokenizer = new TextBufferTokenizer(this.textModel, this.brackets);
|
|
98
|
+
const result = parseDocument(tokenizer, edits, previousAstClone, immutable);
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
getBracketsInRange(range, onlyColorizedBrackets) {
|
|
102
|
+
this.flushQueue();
|
|
103
|
+
const startOffset = toLength(range.startLineNumber - 1, range.startColumn - 1);
|
|
104
|
+
const endOffset = toLength(range.endLineNumber - 1, range.endColumn - 1);
|
|
105
|
+
return new CallbackIterable(cb => {
|
|
106
|
+
const node = this.initialAstWithoutTokens || this.astWithTokens;
|
|
107
|
+
collectBrackets(node, lengthZero, node.length, startOffset, endOffset, cb, 0, 0, new Map(), onlyColorizedBrackets);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
getBracketPairsInRange(range, includeMinIndentation) {
|
|
111
|
+
this.flushQueue();
|
|
112
|
+
const startLength = positionToLength(range.getStartPosition());
|
|
113
|
+
const endLength = positionToLength(range.getEndPosition());
|
|
114
|
+
return new CallbackIterable(cb => {
|
|
115
|
+
const node = this.initialAstWithoutTokens || this.astWithTokens;
|
|
116
|
+
const context = new CollectBracketPairsContext(cb, includeMinIndentation, this.textModel);
|
|
117
|
+
collectBracketPairs(node, lengthZero, node.length, startLength, endLength, context, 0, new Map());
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
getFirstBracketAfter(position) {
|
|
121
|
+
this.flushQueue();
|
|
122
|
+
const node = this.initialAstWithoutTokens || this.astWithTokens;
|
|
123
|
+
return getFirstBracketAfter(node, lengthZero, node.length, positionToLength(position));
|
|
124
|
+
}
|
|
125
|
+
getFirstBracketBefore(position) {
|
|
126
|
+
this.flushQueue();
|
|
127
|
+
const node = this.initialAstWithoutTokens || this.astWithTokens;
|
|
128
|
+
return getFirstBracketBefore(node, lengthZero, node.length, positionToLength(position));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function getFirstBracketBefore(node, nodeOffsetStart, nodeOffsetEnd, position) {
|
|
132
|
+
if (node.kind === 4 /* AstNodeKind.List */ || node.kind === 2 /* AstNodeKind.Pair */) {
|
|
133
|
+
const lengths = [];
|
|
134
|
+
for (const child of node.children) {
|
|
135
|
+
nodeOffsetEnd = lengthAdd(nodeOffsetStart, child.length);
|
|
136
|
+
lengths.push({ nodeOffsetStart, nodeOffsetEnd });
|
|
137
|
+
nodeOffsetStart = nodeOffsetEnd;
|
|
138
|
+
}
|
|
139
|
+
for (let i = lengths.length - 1; i >= 0; i--) {
|
|
140
|
+
const { nodeOffsetStart, nodeOffsetEnd } = lengths[i];
|
|
141
|
+
if (lengthLessThan(nodeOffsetStart, position)) {
|
|
142
|
+
const result = getFirstBracketBefore(node.children[i], nodeOffsetStart, nodeOffsetEnd, position);
|
|
143
|
+
if (result) {
|
|
144
|
+
return result;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
else if (node.kind === 3 /* AstNodeKind.UnexpectedClosingBracket */) {
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
else if (node.kind === 1 /* AstNodeKind.Bracket */) {
|
|
154
|
+
const range = lengthsToRange(nodeOffsetStart, nodeOffsetEnd);
|
|
155
|
+
return {
|
|
156
|
+
bracketInfo: node.bracketInfo,
|
|
157
|
+
range
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
function getFirstBracketAfter(node, nodeOffsetStart, nodeOffsetEnd, position) {
|
|
163
|
+
if (node.kind === 4 /* AstNodeKind.List */ || node.kind === 2 /* AstNodeKind.Pair */) {
|
|
164
|
+
for (const child of node.children) {
|
|
165
|
+
nodeOffsetEnd = lengthAdd(nodeOffsetStart, child.length);
|
|
166
|
+
if (lengthLessThan(position, nodeOffsetEnd)) {
|
|
167
|
+
const result = getFirstBracketAfter(child, nodeOffsetStart, nodeOffsetEnd, position);
|
|
168
|
+
if (result) {
|
|
169
|
+
return result;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
nodeOffsetStart = nodeOffsetEnd;
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
else if (node.kind === 3 /* AstNodeKind.UnexpectedClosingBracket */) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
else if (node.kind === 1 /* AstNodeKind.Bracket */) {
|
|
180
|
+
const range = lengthsToRange(nodeOffsetStart, nodeOffsetEnd);
|
|
181
|
+
return {
|
|
182
|
+
bracketInfo: node.bracketInfo,
|
|
183
|
+
range
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
function collectBrackets(node, nodeOffsetStart, nodeOffsetEnd, startOffset, endOffset, push, level, nestingLevelOfEqualBracketType, levelPerBracketType, onlyColorizedBrackets, parentPairIsIncomplete = false) {
|
|
189
|
+
if (level > 200) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
whileLoop: while (true) {
|
|
193
|
+
switch (node.kind) {
|
|
194
|
+
case 4 /* AstNodeKind.List */: {
|
|
195
|
+
const childCount = node.childrenLength;
|
|
196
|
+
for (let i = 0; i < childCount; i++) {
|
|
197
|
+
const child = node.getChild(i);
|
|
198
|
+
if (!child) {
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
nodeOffsetEnd = lengthAdd(nodeOffsetStart, child.length);
|
|
202
|
+
if (lengthLessThanEqual(nodeOffsetStart, endOffset) &&
|
|
203
|
+
lengthGreaterThanEqual(nodeOffsetEnd, startOffset)) {
|
|
204
|
+
const childEndsAfterEnd = lengthGreaterThanEqual(nodeOffsetEnd, endOffset);
|
|
205
|
+
if (childEndsAfterEnd) {
|
|
206
|
+
// No child after this child in the requested window, don't recurse
|
|
207
|
+
node = child;
|
|
208
|
+
continue whileLoop;
|
|
209
|
+
}
|
|
210
|
+
const shouldContinue = collectBrackets(child, nodeOffsetStart, nodeOffsetEnd, startOffset, endOffset, push, level, 0, levelPerBracketType, onlyColorizedBrackets);
|
|
211
|
+
if (!shouldContinue) {
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
nodeOffsetStart = nodeOffsetEnd;
|
|
216
|
+
}
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
case 2 /* AstNodeKind.Pair */: {
|
|
220
|
+
const colorize = !onlyColorizedBrackets || !node.closingBracket || node.closingBracket.bracketInfo.closesColorized(node.openingBracket.bracketInfo);
|
|
221
|
+
let levelPerBracket = 0;
|
|
222
|
+
if (levelPerBracketType) {
|
|
223
|
+
let existing = levelPerBracketType.get(node.openingBracket.text);
|
|
224
|
+
if (existing === undefined) {
|
|
225
|
+
existing = 0;
|
|
226
|
+
}
|
|
227
|
+
levelPerBracket = existing;
|
|
228
|
+
if (colorize) {
|
|
229
|
+
existing++;
|
|
230
|
+
levelPerBracketType.set(node.openingBracket.text, existing);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const childCount = node.childrenLength;
|
|
234
|
+
for (let i = 0; i < childCount; i++) {
|
|
235
|
+
const child = node.getChild(i);
|
|
236
|
+
if (!child) {
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
nodeOffsetEnd = lengthAdd(nodeOffsetStart, child.length);
|
|
240
|
+
if (lengthLessThanEqual(nodeOffsetStart, endOffset) &&
|
|
241
|
+
lengthGreaterThanEqual(nodeOffsetEnd, startOffset)) {
|
|
242
|
+
const childEndsAfterEnd = lengthGreaterThanEqual(nodeOffsetEnd, endOffset);
|
|
243
|
+
if (childEndsAfterEnd && child.kind !== 1 /* AstNodeKind.Bracket */) {
|
|
244
|
+
// No child after this child in the requested window, don't recurse
|
|
245
|
+
// Don't do this for brackets because of unclosed/unopened brackets
|
|
246
|
+
node = child;
|
|
247
|
+
if (colorize) {
|
|
248
|
+
level++;
|
|
249
|
+
nestingLevelOfEqualBracketType = levelPerBracket + 1;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
nestingLevelOfEqualBracketType = levelPerBracket;
|
|
253
|
+
}
|
|
254
|
+
continue whileLoop;
|
|
255
|
+
}
|
|
256
|
+
if (colorize || child.kind !== 1 /* AstNodeKind.Bracket */ || !node.closingBracket) {
|
|
257
|
+
const shouldContinue = collectBrackets(child, nodeOffsetStart, nodeOffsetEnd, startOffset, endOffset, push, colorize ? level + 1 : level, colorize ? levelPerBracket + 1 : levelPerBracket, levelPerBracketType, onlyColorizedBrackets, !node.closingBracket);
|
|
258
|
+
if (!shouldContinue) {
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
nodeOffsetStart = nodeOffsetEnd;
|
|
264
|
+
}
|
|
265
|
+
levelPerBracketType?.set(node.openingBracket.text, levelPerBracket);
|
|
266
|
+
return true;
|
|
267
|
+
}
|
|
268
|
+
case 3 /* AstNodeKind.UnexpectedClosingBracket */: {
|
|
269
|
+
const range = lengthsToRange(nodeOffsetStart, nodeOffsetEnd);
|
|
270
|
+
return push(new BracketInfo(range, level - 1, 0, true));
|
|
271
|
+
}
|
|
272
|
+
case 1 /* AstNodeKind.Bracket */: {
|
|
273
|
+
const range = lengthsToRange(nodeOffsetStart, nodeOffsetEnd);
|
|
274
|
+
return push(new BracketInfo(range, level - 1, nestingLevelOfEqualBracketType - 1, parentPairIsIncomplete));
|
|
275
|
+
}
|
|
276
|
+
case 0 /* AstNodeKind.Text */:
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
class CollectBracketPairsContext {
|
|
282
|
+
constructor(push, includeMinIndentation, textModel) {
|
|
283
|
+
this.push = push;
|
|
284
|
+
this.includeMinIndentation = includeMinIndentation;
|
|
285
|
+
this.textModel = textModel;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function collectBracketPairs(node, nodeOffsetStart, nodeOffsetEnd, startOffset, endOffset, context, level, levelPerBracketType) {
|
|
289
|
+
if (level > 200) {
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
292
|
+
let shouldContinue = true;
|
|
293
|
+
if (node.kind === 2 /* AstNodeKind.Pair */) {
|
|
294
|
+
let levelPerBracket = 0;
|
|
295
|
+
if (levelPerBracketType) {
|
|
296
|
+
let existing = levelPerBracketType.get(node.openingBracket.text);
|
|
297
|
+
if (existing === undefined) {
|
|
298
|
+
existing = 0;
|
|
299
|
+
}
|
|
300
|
+
levelPerBracket = existing;
|
|
301
|
+
existing++;
|
|
302
|
+
levelPerBracketType.set(node.openingBracket.text, existing);
|
|
303
|
+
}
|
|
304
|
+
const openingBracketEnd = lengthAdd(nodeOffsetStart, node.openingBracket.length);
|
|
305
|
+
let minIndentation = -1;
|
|
306
|
+
if (context.includeMinIndentation) {
|
|
307
|
+
minIndentation = node.computeMinIndentation(nodeOffsetStart, context.textModel);
|
|
308
|
+
}
|
|
309
|
+
shouldContinue = context.push(new BracketPairWithMinIndentationInfo(lengthsToRange(nodeOffsetStart, nodeOffsetEnd), lengthsToRange(nodeOffsetStart, openingBracketEnd), node.closingBracket
|
|
310
|
+
? lengthsToRange(lengthAdd(openingBracketEnd, node.child?.length || lengthZero), nodeOffsetEnd)
|
|
311
|
+
: undefined, level, levelPerBracket, node, minIndentation));
|
|
312
|
+
nodeOffsetStart = openingBracketEnd;
|
|
313
|
+
if (shouldContinue && node.child) {
|
|
314
|
+
const child = node.child;
|
|
315
|
+
nodeOffsetEnd = lengthAdd(nodeOffsetStart, child.length);
|
|
316
|
+
if (lengthLessThanEqual(nodeOffsetStart, endOffset) &&
|
|
317
|
+
lengthGreaterThanEqual(nodeOffsetEnd, startOffset)) {
|
|
318
|
+
shouldContinue = collectBracketPairs(child, nodeOffsetStart, nodeOffsetEnd, startOffset, endOffset, context, level + 1, levelPerBracketType);
|
|
319
|
+
if (!shouldContinue) {
|
|
320
|
+
return false;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
levelPerBracketType?.set(node.openingBracket.text, levelPerBracket);
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
let curOffset = nodeOffsetStart;
|
|
328
|
+
for (const child of node.children) {
|
|
329
|
+
const childOffset = curOffset;
|
|
330
|
+
curOffset = lengthAdd(curOffset, child.length);
|
|
331
|
+
if (lengthLessThanEqual(childOffset, endOffset) &&
|
|
332
|
+
lengthLessThanEqual(startOffset, curOffset)) {
|
|
333
|
+
shouldContinue = collectBracketPairs(child, childOffset, curOffset, startOffset, endOffset, context, level, levelPerBracketType);
|
|
334
|
+
if (!shouldContinue) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return shouldContinue;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export { BracketPairsTree };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { escapeRegExpCharacters } from '../../../../../base/common/strings.js';
|
|
2
|
+
import { BracketAstNode } from './ast.js';
|
|
3
|
+
import { toLength } from './length.js';
|
|
4
|
+
import { SmallImmutableSet, identityKeyProvider } from './smallImmutableSet.js';
|
|
5
|
+
import { Token } from './tokenizer.js';
|
|
6
|
+
|
|
7
|
+
/*---------------------------------------------------------------------------------------------
|
|
8
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
9
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
10
|
+
*--------------------------------------------------------------------------------------------*/
|
|
11
|
+
class BracketTokens {
|
|
12
|
+
static createFromLanguage(configuration, denseKeyProvider) {
|
|
13
|
+
function getId(bracketInfo) {
|
|
14
|
+
return denseKeyProvider.getKey(`${bracketInfo.languageId}:::${bracketInfo.bracketText}`);
|
|
15
|
+
}
|
|
16
|
+
const map = new Map();
|
|
17
|
+
for (const openingBracket of configuration.bracketsNew.openingBrackets) {
|
|
18
|
+
const length = toLength(0, openingBracket.bracketText.length);
|
|
19
|
+
const openingTextId = getId(openingBracket);
|
|
20
|
+
const bracketIds = SmallImmutableSet.getEmpty().add(openingTextId, identityKeyProvider);
|
|
21
|
+
map.set(openingBracket.bracketText, new Token(length, 1 /* TokenKind.OpeningBracket */, openingTextId, bracketIds, BracketAstNode.create(length, openingBracket, bracketIds)));
|
|
22
|
+
}
|
|
23
|
+
for (const closingBracket of configuration.bracketsNew.closingBrackets) {
|
|
24
|
+
const length = toLength(0, closingBracket.bracketText.length);
|
|
25
|
+
let bracketIds = SmallImmutableSet.getEmpty();
|
|
26
|
+
const closingBrackets = closingBracket.getOpeningBrackets();
|
|
27
|
+
for (const bracket of closingBrackets) {
|
|
28
|
+
bracketIds = bracketIds.add(getId(bracket), identityKeyProvider);
|
|
29
|
+
}
|
|
30
|
+
map.set(closingBracket.bracketText, new Token(length, 2 /* TokenKind.ClosingBracket */, getId(closingBrackets[0]), bracketIds, BracketAstNode.create(length, closingBracket, bracketIds)));
|
|
31
|
+
}
|
|
32
|
+
return new BracketTokens(map);
|
|
33
|
+
}
|
|
34
|
+
constructor(map) {
|
|
35
|
+
this.map = map;
|
|
36
|
+
this.hasRegExp = false;
|
|
37
|
+
this._regExpGlobal = null;
|
|
38
|
+
}
|
|
39
|
+
getRegExpStr() {
|
|
40
|
+
if (this.isEmpty) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const keys = [...this.map.keys()];
|
|
45
|
+
keys.sort();
|
|
46
|
+
keys.reverse();
|
|
47
|
+
return keys.map(k => prepareBracketForRegExp(k)).join('|');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns null if there is no such regexp (because there are no brackets).
|
|
52
|
+
*/
|
|
53
|
+
get regExpGlobal() {
|
|
54
|
+
if (!this.hasRegExp) {
|
|
55
|
+
const regExpStr = this.getRegExpStr();
|
|
56
|
+
this._regExpGlobal = regExpStr ? new RegExp(regExpStr, 'gi') : null;
|
|
57
|
+
this.hasRegExp = true;
|
|
58
|
+
}
|
|
59
|
+
return this._regExpGlobal;
|
|
60
|
+
}
|
|
61
|
+
getToken(value) {
|
|
62
|
+
return this.map.get(value.toLowerCase());
|
|
63
|
+
}
|
|
64
|
+
findClosingTokenText(openingBracketIds) {
|
|
65
|
+
for (const [closingText, info] of this.map) {
|
|
66
|
+
if (info.kind === 2 /* TokenKind.ClosingBracket */ && info.bracketIds.intersects(openingBracketIds)) {
|
|
67
|
+
return closingText;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
get isEmpty() {
|
|
73
|
+
return this.map.size === 0;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function prepareBracketForRegExp(str) {
|
|
77
|
+
let escaped = escapeRegExpCharacters(str);
|
|
78
|
+
// These bracket pair delimiters start or end with letters
|
|
79
|
+
// see https://github.com/microsoft/vscode/issues/132162 https://github.com/microsoft/vscode/issues/150440
|
|
80
|
+
if (/^[\w ]+/.test(str)) {
|
|
81
|
+
escaped = `\\b${escaped}`;
|
|
82
|
+
}
|
|
83
|
+
if (/[\w ]+$/.test(str)) {
|
|
84
|
+
escaped = `${escaped}\\b`;
|
|
85
|
+
}
|
|
86
|
+
return escaped;
|
|
87
|
+
}
|
|
88
|
+
class LanguageAgnosticBracketTokens {
|
|
89
|
+
constructor(denseKeyProvider, getLanguageConfiguration) {
|
|
90
|
+
this.denseKeyProvider = denseKeyProvider;
|
|
91
|
+
this.getLanguageConfiguration = getLanguageConfiguration;
|
|
92
|
+
this.languageIdToBracketTokens = new Map();
|
|
93
|
+
}
|
|
94
|
+
didLanguageChange(languageId) {
|
|
95
|
+
// Report a change whenever the language configuration updates.
|
|
96
|
+
return this.languageIdToBracketTokens.has(languageId);
|
|
97
|
+
}
|
|
98
|
+
getSingleLanguageBracketTokens(languageId) {
|
|
99
|
+
let singleLanguageBracketTokens = this.languageIdToBracketTokens.get(languageId);
|
|
100
|
+
if (!singleLanguageBracketTokens) {
|
|
101
|
+
singleLanguageBracketTokens = BracketTokens.createFromLanguage(this.getLanguageConfiguration(languageId), this.denseKeyProvider);
|
|
102
|
+
this.languageIdToBracketTokens.set(languageId, singleLanguageBracketTokens);
|
|
103
|
+
}
|
|
104
|
+
return singleLanguageBracketTokens;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { BracketTokens, LanguageAgnosticBracketTokens };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { toUint8 } from '../../../base/common/uint.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
|
+
/**
|
|
8
|
+
* A fast character classifier that uses a compact array for ASCII values.
|
|
9
|
+
*/
|
|
10
|
+
class CharacterClassifier {
|
|
11
|
+
constructor(_defaultValue) {
|
|
12
|
+
const defaultValue = toUint8(_defaultValue);
|
|
13
|
+
this._defaultValue = defaultValue;
|
|
14
|
+
this._asciiMap = CharacterClassifier._createAsciiMap(defaultValue);
|
|
15
|
+
this._map = new Map();
|
|
16
|
+
}
|
|
17
|
+
static _createAsciiMap(defaultValue) {
|
|
18
|
+
const asciiMap = new Uint8Array(256);
|
|
19
|
+
asciiMap.fill(defaultValue);
|
|
20
|
+
return asciiMap;
|
|
21
|
+
}
|
|
22
|
+
set(charCode, _value) {
|
|
23
|
+
const value = toUint8(_value);
|
|
24
|
+
if (charCode >= 0 && charCode < 256) {
|
|
25
|
+
this._asciiMap[charCode] = value;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
this._map.set(charCode, value);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
get(charCode) {
|
|
32
|
+
if (charCode >= 0 && charCode < 256) {
|
|
33
|
+
return this._asciiMap[charCode];
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return (this._map.get(charCode) || this._defaultValue);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
clear() {
|
|
40
|
+
this._asciiMap.fill(this._defaultValue);
|
|
41
|
+
this._map.clear();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
class CharacterSet {
|
|
45
|
+
constructor() {
|
|
46
|
+
this._actual = new CharacterClassifier(0 /* Boolean.False */);
|
|
47
|
+
}
|
|
48
|
+
add(charCode) {
|
|
49
|
+
this._actual.set(charCode, 1 /* Boolean.True */);
|
|
50
|
+
}
|
|
51
|
+
has(charCode) {
|
|
52
|
+
return (this._actual.get(charCode) === 1 /* Boolean.True */);
|
|
53
|
+
}
|
|
54
|
+
clear() {
|
|
55
|
+
return this._actual.clear();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export { CharacterClassifier, CharacterSet };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { StandardAutoClosingPairConditional } from '../languageConfiguration.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 CharacterPairSupport {
|
|
8
|
+
static { this.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_QUOTES = ';:.,=}])> \n\t'; }
|
|
9
|
+
static { this.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_BRACKETS = '\'"`;:.,=}])> \n\t'; }
|
|
10
|
+
constructor(config) {
|
|
11
|
+
if (config.autoClosingPairs) {
|
|
12
|
+
this._autoClosingPairs = config.autoClosingPairs.map(el => new StandardAutoClosingPairConditional(el));
|
|
13
|
+
}
|
|
14
|
+
else if (config.brackets) {
|
|
15
|
+
this._autoClosingPairs = config.brackets.map(b => new StandardAutoClosingPairConditional({ open: b[0], close: b[1] }));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this._autoClosingPairs = [];
|
|
19
|
+
}
|
|
20
|
+
if (config.__electricCharacterSupport && config.__electricCharacterSupport.docComment) {
|
|
21
|
+
const docComment = config.__electricCharacterSupport.docComment;
|
|
22
|
+
// IDocComment is legacy, only partially supported
|
|
23
|
+
this._autoClosingPairs.push(new StandardAutoClosingPairConditional({ open: docComment.open, close: docComment.close || '' }));
|
|
24
|
+
}
|
|
25
|
+
this._autoCloseBeforeForQuotes = typeof config.autoCloseBefore === 'string' ? config.autoCloseBefore : CharacterPairSupport.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_QUOTES;
|
|
26
|
+
this._autoCloseBeforeForBrackets = typeof config.autoCloseBefore === 'string' ? config.autoCloseBefore : CharacterPairSupport.DEFAULT_AUTOCLOSE_BEFORE_LANGUAGE_DEFINED_BRACKETS;
|
|
27
|
+
this._surroundingPairs = config.surroundingPairs || this._autoClosingPairs;
|
|
28
|
+
}
|
|
29
|
+
getAutoClosingPairs() {
|
|
30
|
+
return this._autoClosingPairs;
|
|
31
|
+
}
|
|
32
|
+
getAutoCloseBeforeSet(forQuotes) {
|
|
33
|
+
return (forQuotes ? this._autoCloseBeforeForQuotes : this._autoCloseBeforeForBrackets);
|
|
34
|
+
}
|
|
35
|
+
getSurroundingPairs() {
|
|
36
|
+
return this._surroundingPairs;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { CharacterPairSupport };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { Emitter } from '../../../../base/common/event.js';
|
|
2
|
+
import { Disposable } from '../../../../base/common/lifecycle.js';
|
|
3
|
+
import { Range } from '../../core/range.js';
|
|
4
|
+
import { editorBracketHighlightingUnexpectedBracketForeground, editorBracketHighlightingForeground1, editorBracketHighlightingForeground2, editorBracketHighlightingForeground3, editorBracketHighlightingForeground4, editorBracketHighlightingForeground5, editorBracketHighlightingForeground6 } from '../../core/editorColorRegistry.js';
|
|
5
|
+
import { registerThemingParticipant } from '../../../../platform/theme/common/themeService.js';
|
|
6
|
+
|
|
7
|
+
/*---------------------------------------------------------------------------------------------
|
|
8
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
9
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
10
|
+
*--------------------------------------------------------------------------------------------*/
|
|
11
|
+
class ColorizedBracketPairsDecorationProvider extends Disposable {
|
|
12
|
+
constructor(textModel) {
|
|
13
|
+
super();
|
|
14
|
+
this.textModel = textModel;
|
|
15
|
+
this.colorProvider = new ColorProvider();
|
|
16
|
+
this.onDidChangeEmitter = new Emitter();
|
|
17
|
+
this.onDidChange = this.onDidChangeEmitter.event;
|
|
18
|
+
this.colorizationOptions = textModel.getOptions().bracketPairColorizationOptions;
|
|
19
|
+
this._register(textModel.bracketPairs.onDidChange(e => {
|
|
20
|
+
this.onDidChangeEmitter.fire();
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
//#region TextModel events
|
|
24
|
+
handleDidChangeOptions(e) {
|
|
25
|
+
this.colorizationOptions = this.textModel.getOptions().bracketPairColorizationOptions;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
getDecorationsInRange(range, ownerId, filterOutValidation, onlyMinimapDecorations) {
|
|
29
|
+
if (onlyMinimapDecorations) {
|
|
30
|
+
// Bracket pair colorization decorations are not rendered in the minimap
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
if (ownerId === undefined) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
if (!this.colorizationOptions.enabled) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const result = this.textModel.bracketPairs.getBracketsInRange(range, true).map(bracket => ({
|
|
40
|
+
id: `bracket${bracket.range.toString()}-${bracket.nestingLevel}`,
|
|
41
|
+
options: {
|
|
42
|
+
description: 'BracketPairColorization',
|
|
43
|
+
inlineClassName: this.colorProvider.getInlineClassName(bracket, this.colorizationOptions.independentColorPoolPerBracketType),
|
|
44
|
+
},
|
|
45
|
+
ownerId: 0,
|
|
46
|
+
range: bracket.range,
|
|
47
|
+
})).toArray();
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
getAllDecorations(ownerId, filterOutValidation) {
|
|
51
|
+
if (ownerId === undefined) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
if (!this.colorizationOptions.enabled) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
return this.getDecorationsInRange(new Range(1, 1, this.textModel.getLineCount(), 1), ownerId, filterOutValidation);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
class ColorProvider {
|
|
61
|
+
constructor() {
|
|
62
|
+
this.unexpectedClosingBracketClassName = 'unexpected-closing-bracket';
|
|
63
|
+
}
|
|
64
|
+
getInlineClassName(bracket, independentColorPoolPerBracketType) {
|
|
65
|
+
if (bracket.isInvalid) {
|
|
66
|
+
return this.unexpectedClosingBracketClassName;
|
|
67
|
+
}
|
|
68
|
+
return this.getInlineClassNameOfLevel(independentColorPoolPerBracketType ? bracket.nestingLevelOfEqualBracketType : bracket.nestingLevel);
|
|
69
|
+
}
|
|
70
|
+
getInlineClassNameOfLevel(level) {
|
|
71
|
+
// To support a dynamic amount of colors up to 6 colors,
|
|
72
|
+
// we use a number that is a lcm of all numbers from 1 to 6.
|
|
73
|
+
return `bracket-highlighting-${level % 30}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
registerThemingParticipant((theme, collector) => {
|
|
77
|
+
const colors = [
|
|
78
|
+
editorBracketHighlightingForeground1,
|
|
79
|
+
editorBracketHighlightingForeground2,
|
|
80
|
+
editorBracketHighlightingForeground3,
|
|
81
|
+
editorBracketHighlightingForeground4,
|
|
82
|
+
editorBracketHighlightingForeground5,
|
|
83
|
+
editorBracketHighlightingForeground6
|
|
84
|
+
];
|
|
85
|
+
const colorProvider = new ColorProvider();
|
|
86
|
+
collector.addRule(`.monaco-editor .${colorProvider.unexpectedClosingBracketClassName} { color: ${theme.getColor(editorBracketHighlightingUnexpectedBracketForeground)}; }`);
|
|
87
|
+
const colorValues = colors
|
|
88
|
+
.map(c => theme.getColor(c))
|
|
89
|
+
.filter((c) => !!c)
|
|
90
|
+
.filter(c => !c.isTransparent());
|
|
91
|
+
for (let level = 0; level < 30; level++) {
|
|
92
|
+
const color = colorValues[level % colorValues.length];
|
|
93
|
+
collector.addRule(`.monaco-editor .${colorProvider.getInlineClassNameOfLevel(level)} { color: ${color}; }`);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
export { ColorizedBracketPairsDecorationProvider };
|