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,35 @@
|
|
|
1
|
+
import { BugIndicatingError } from '../../../../base/common/errors.js';
|
|
2
|
+
import { OffsetRange } from './offsetRange.js';
|
|
3
|
+
import { Range } from '../range.js';
|
|
4
|
+
|
|
5
|
+
/*---------------------------------------------------------------------------------------------
|
|
6
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
8
|
+
*--------------------------------------------------------------------------------------------*/
|
|
9
|
+
/**
|
|
10
|
+
* Represents a 1-based range of columns.
|
|
11
|
+
* Use {@lik OffsetRange} to represent a 0-based range.
|
|
12
|
+
*/
|
|
13
|
+
class ColumnRange {
|
|
14
|
+
constructor(
|
|
15
|
+
/** 1-based */
|
|
16
|
+
startColumn, endColumnExclusive) {
|
|
17
|
+
this.startColumn = startColumn;
|
|
18
|
+
this.endColumnExclusive = endColumnExclusive;
|
|
19
|
+
if (startColumn > endColumnExclusive) {
|
|
20
|
+
throw new BugIndicatingError(`startColumn ${startColumn} cannot be after endColumnExclusive ${endColumnExclusive}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
toRange(lineNumber) {
|
|
24
|
+
return new Range(lineNumber, this.startColumn, lineNumber, this.endColumnExclusive);
|
|
25
|
+
}
|
|
26
|
+
equals(other) {
|
|
27
|
+
return this.startColumn === other.startColumn
|
|
28
|
+
&& this.endColumnExclusive === other.endColumnExclusive;
|
|
29
|
+
}
|
|
30
|
+
toZeroBasedOffsetRange() {
|
|
31
|
+
return new OffsetRange(this.startColumn - 1, this.endColumnExclusive - 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { ColumnRange };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { ArrayQueue } from '../../../../../base/common/arrays.js';
|
|
2
|
+
import { TextEditInfo } from './beforeEditPositionMapper.js';
|
|
3
|
+
import { sumLengths, lengthAdd, lengthDiffNonNegative, lengthIsZero, lengthEquals, lengthZero, lengthToObj } from './length.js';
|
|
4
|
+
|
|
5
|
+
/*---------------------------------------------------------------------------------------------
|
|
6
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
7
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
8
|
+
*--------------------------------------------------------------------------------------------*/
|
|
9
|
+
function combineTextEditInfos(textEditInfoFirst, textEditInfoSecond) {
|
|
10
|
+
if (textEditInfoFirst.length === 0) {
|
|
11
|
+
return textEditInfoSecond;
|
|
12
|
+
}
|
|
13
|
+
if (textEditInfoSecond.length === 0) {
|
|
14
|
+
return textEditInfoFirst;
|
|
15
|
+
}
|
|
16
|
+
// s0: State before any edits
|
|
17
|
+
const s0ToS1Map = new ArrayQueue(toLengthMapping(textEditInfoFirst));
|
|
18
|
+
// s1: State after first edit, but before second edit
|
|
19
|
+
const s1ToS2Map = toLengthMapping(textEditInfoSecond);
|
|
20
|
+
s1ToS2Map.push({ modified: false, lengthBefore: undefined, lengthAfter: undefined }); // Copy everything from old to new
|
|
21
|
+
// s2: State after both edits
|
|
22
|
+
let curItem = s0ToS1Map.dequeue();
|
|
23
|
+
/**
|
|
24
|
+
* @param s1Length Use undefined for length "infinity"
|
|
25
|
+
*/
|
|
26
|
+
function nextS0ToS1MapWithS1LengthOf(s1Length) {
|
|
27
|
+
if (s1Length === undefined) {
|
|
28
|
+
const arr = s0ToS1Map.takeWhile(v => true) || [];
|
|
29
|
+
if (curItem) {
|
|
30
|
+
arr.unshift(curItem);
|
|
31
|
+
}
|
|
32
|
+
return arr;
|
|
33
|
+
}
|
|
34
|
+
const result = [];
|
|
35
|
+
while (curItem && !lengthIsZero(s1Length)) {
|
|
36
|
+
const [item, remainingItem] = curItem.splitAt(s1Length);
|
|
37
|
+
result.push(item);
|
|
38
|
+
s1Length = lengthDiffNonNegative(item.lengthAfter, s1Length);
|
|
39
|
+
curItem = remainingItem ?? s0ToS1Map.dequeue();
|
|
40
|
+
}
|
|
41
|
+
if (!lengthIsZero(s1Length)) {
|
|
42
|
+
result.push(new LengthMapping(false, s1Length, s1Length));
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
const result = [];
|
|
47
|
+
function pushEdit(startOffset, endOffset, newLength) {
|
|
48
|
+
if (result.length > 0 && lengthEquals(result[result.length - 1].endOffset, startOffset)) {
|
|
49
|
+
const lastResult = result[result.length - 1];
|
|
50
|
+
result[result.length - 1] = new TextEditInfo(lastResult.startOffset, endOffset, lengthAdd(lastResult.newLength, newLength));
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
result.push({ startOffset, endOffset, newLength });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
let s0offset = lengthZero;
|
|
57
|
+
for (const s1ToS2 of s1ToS2Map) {
|
|
58
|
+
const s0ToS1Map = nextS0ToS1MapWithS1LengthOf(s1ToS2.lengthBefore);
|
|
59
|
+
if (s1ToS2.modified) {
|
|
60
|
+
const s0Length = sumLengths(s0ToS1Map, s => s.lengthBefore);
|
|
61
|
+
const s0EndOffset = lengthAdd(s0offset, s0Length);
|
|
62
|
+
pushEdit(s0offset, s0EndOffset, s1ToS2.lengthAfter);
|
|
63
|
+
s0offset = s0EndOffset;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
for (const s1 of s0ToS1Map) {
|
|
67
|
+
const s0startOffset = s0offset;
|
|
68
|
+
s0offset = lengthAdd(s0offset, s1.lengthBefore);
|
|
69
|
+
if (s1.modified) {
|
|
70
|
+
pushEdit(s0startOffset, s0offset, s1.lengthAfter);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
class LengthMapping {
|
|
78
|
+
constructor(
|
|
79
|
+
/**
|
|
80
|
+
* If false, length before and length after equal.
|
|
81
|
+
*/
|
|
82
|
+
modified, lengthBefore, lengthAfter) {
|
|
83
|
+
this.modified = modified;
|
|
84
|
+
this.lengthBefore = lengthBefore;
|
|
85
|
+
this.lengthAfter = lengthAfter;
|
|
86
|
+
}
|
|
87
|
+
splitAt(lengthAfter) {
|
|
88
|
+
const remainingLengthAfter = lengthDiffNonNegative(lengthAfter, this.lengthAfter);
|
|
89
|
+
if (lengthEquals(remainingLengthAfter, lengthZero)) {
|
|
90
|
+
return [this, undefined];
|
|
91
|
+
}
|
|
92
|
+
else if (this.modified) {
|
|
93
|
+
return [
|
|
94
|
+
new LengthMapping(this.modified, this.lengthBefore, lengthAfter),
|
|
95
|
+
new LengthMapping(this.modified, lengthZero, remainingLengthAfter)
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return [
|
|
100
|
+
new LengthMapping(this.modified, lengthAfter, lengthAfter),
|
|
101
|
+
new LengthMapping(this.modified, remainingLengthAfter, remainingLengthAfter)
|
|
102
|
+
];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
toString() {
|
|
106
|
+
return `${this.modified ? 'M' : 'U'}:${lengthToObj(this.lengthBefore)} -> ${lengthToObj(this.lengthAfter)}`;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function toLengthMapping(textEditInfos) {
|
|
110
|
+
const result = [];
|
|
111
|
+
let lastOffset = lengthZero;
|
|
112
|
+
for (const textEditInfo of textEditInfos) {
|
|
113
|
+
const spaceLength = lengthDiffNonNegative(lastOffset, textEditInfo.startOffset);
|
|
114
|
+
if (!lengthIsZero(spaceLength)) {
|
|
115
|
+
result.push(new LengthMapping(false, spaceLength, spaceLength));
|
|
116
|
+
}
|
|
117
|
+
const lengthBefore = lengthDiffNonNegative(textEditInfo.startOffset, textEditInfo.endOffset);
|
|
118
|
+
result.push(new LengthMapping(true, lengthBefore, textEditInfo.newLength));
|
|
119
|
+
lastOffset = textEditInfo.endOffset;
|
|
120
|
+
}
|
|
121
|
+
return result;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export { combineTextEditInfos };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
class RateLimiter {
|
|
6
|
+
constructor(timesPerSecond = 5) {
|
|
7
|
+
this.timesPerSecond = timesPerSecond;
|
|
8
|
+
this._lastRun = 0;
|
|
9
|
+
this._minimumTimeBetweenRuns = 1000 / timesPerSecond;
|
|
10
|
+
}
|
|
11
|
+
runIfNotLimited(callback) {
|
|
12
|
+
const now = Date.now();
|
|
13
|
+
if (now - this._lastRun >= this._minimumTimeBetweenRuns) {
|
|
14
|
+
this._lastRun = now;
|
|
15
|
+
callback();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export { RateLimiter };
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { SequenceDiff } from './algorithms/diffAlgorithm.js';
|
|
2
|
+
import { LineRangeMapping } from '../rangeMapping.js';
|
|
3
|
+
import { pushMany, compareBy, numberComparator, reverseOrder } from '../../../../base/common/arrays.js';
|
|
4
|
+
import { MonotonousArray, findLastMonotonous } from '../../../../base/common/arraysFind.js';
|
|
5
|
+
import { SetMap } from '../../../../base/common/map.js';
|
|
6
|
+
import { LineRange, LineRangeSet } from '../../core/ranges/lineRange.js';
|
|
7
|
+
import { LinesSliceCharSequence } from './linesSliceCharSequence.js';
|
|
8
|
+
import { LineRangeFragment, isSpace } from './utils.js';
|
|
9
|
+
import { MyersDiffAlgorithm } from './algorithms/myersDiffAlgorithm.js';
|
|
10
|
+
import { Range } from '../../core/range.js';
|
|
11
|
+
|
|
12
|
+
/*---------------------------------------------------------------------------------------------
|
|
13
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
14
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
15
|
+
*--------------------------------------------------------------------------------------------*/
|
|
16
|
+
function computeMovedLines(changes, originalLines, modifiedLines, hashedOriginalLines, hashedModifiedLines, timeout) {
|
|
17
|
+
let { moves, excludedChanges } = computeMovesFromSimpleDeletionsToSimpleInsertions(changes, originalLines, modifiedLines, timeout);
|
|
18
|
+
if (!timeout.isValid()) {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
const filteredChanges = changes.filter(c => !excludedChanges.has(c));
|
|
22
|
+
const unchangedMoves = computeUnchangedMoves(filteredChanges, hashedOriginalLines, hashedModifiedLines, originalLines, modifiedLines, timeout);
|
|
23
|
+
pushMany(moves, unchangedMoves);
|
|
24
|
+
moves = joinCloseConsecutiveMoves(moves);
|
|
25
|
+
// Ignore too short moves
|
|
26
|
+
moves = moves.filter(current => {
|
|
27
|
+
const lines = current.original.toOffsetRange().slice(originalLines).map(l => l.trim());
|
|
28
|
+
const originalText = lines.join('\n');
|
|
29
|
+
return originalText.length >= 15 && countWhere(lines, l => l.length >= 2) >= 2;
|
|
30
|
+
});
|
|
31
|
+
moves = removeMovesInSameDiff(changes, moves);
|
|
32
|
+
return moves;
|
|
33
|
+
}
|
|
34
|
+
function countWhere(arr, predicate) {
|
|
35
|
+
let count = 0;
|
|
36
|
+
for (const t of arr) {
|
|
37
|
+
if (predicate(t)) {
|
|
38
|
+
count++;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return count;
|
|
42
|
+
}
|
|
43
|
+
function computeMovesFromSimpleDeletionsToSimpleInsertions(changes, originalLines, modifiedLines, timeout) {
|
|
44
|
+
const moves = [];
|
|
45
|
+
const deletions = changes
|
|
46
|
+
.filter(c => c.modified.isEmpty && c.original.length >= 3)
|
|
47
|
+
.map(d => new LineRangeFragment(d.original, originalLines, d));
|
|
48
|
+
const insertions = new Set(changes
|
|
49
|
+
.filter(c => c.original.isEmpty && c.modified.length >= 3)
|
|
50
|
+
.map(d => new LineRangeFragment(d.modified, modifiedLines, d)));
|
|
51
|
+
const excludedChanges = new Set();
|
|
52
|
+
for (const deletion of deletions) {
|
|
53
|
+
let highestSimilarity = -1;
|
|
54
|
+
let best;
|
|
55
|
+
for (const insertion of insertions) {
|
|
56
|
+
const similarity = deletion.computeSimilarity(insertion);
|
|
57
|
+
if (similarity > highestSimilarity) {
|
|
58
|
+
highestSimilarity = similarity;
|
|
59
|
+
best = insertion;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (highestSimilarity > 0.90 && best) {
|
|
63
|
+
insertions.delete(best);
|
|
64
|
+
moves.push(new LineRangeMapping(deletion.range, best.range));
|
|
65
|
+
excludedChanges.add(deletion.source);
|
|
66
|
+
excludedChanges.add(best.source);
|
|
67
|
+
}
|
|
68
|
+
if (!timeout.isValid()) {
|
|
69
|
+
return { moves, excludedChanges };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { moves, excludedChanges };
|
|
73
|
+
}
|
|
74
|
+
function computeUnchangedMoves(changes, hashedOriginalLines, hashedModifiedLines, originalLines, modifiedLines, timeout) {
|
|
75
|
+
const moves = [];
|
|
76
|
+
const original3LineHashes = new SetMap();
|
|
77
|
+
for (const change of changes) {
|
|
78
|
+
for (let i = change.original.startLineNumber; i < change.original.endLineNumberExclusive - 2; i++) {
|
|
79
|
+
const key = `${hashedOriginalLines[i - 1]}:${hashedOriginalLines[i + 1 - 1]}:${hashedOriginalLines[i + 2 - 1]}`;
|
|
80
|
+
original3LineHashes.add(key, { range: new LineRange(i, i + 3) });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const possibleMappings = [];
|
|
84
|
+
changes.sort(compareBy(c => c.modified.startLineNumber, numberComparator));
|
|
85
|
+
for (const change of changes) {
|
|
86
|
+
let lastMappings = [];
|
|
87
|
+
for (let i = change.modified.startLineNumber; i < change.modified.endLineNumberExclusive - 2; i++) {
|
|
88
|
+
const key = `${hashedModifiedLines[i - 1]}:${hashedModifiedLines[i + 1 - 1]}:${hashedModifiedLines[i + 2 - 1]}`;
|
|
89
|
+
const currentModifiedRange = new LineRange(i, i + 3);
|
|
90
|
+
const nextMappings = [];
|
|
91
|
+
original3LineHashes.forEach(key, ({ range }) => {
|
|
92
|
+
for (const lastMapping of lastMappings) {
|
|
93
|
+
// does this match extend some last match?
|
|
94
|
+
if (lastMapping.originalLineRange.endLineNumberExclusive + 1 === range.endLineNumberExclusive &&
|
|
95
|
+
lastMapping.modifiedLineRange.endLineNumberExclusive + 1 === currentModifiedRange.endLineNumberExclusive) {
|
|
96
|
+
lastMapping.originalLineRange = new LineRange(lastMapping.originalLineRange.startLineNumber, range.endLineNumberExclusive);
|
|
97
|
+
lastMapping.modifiedLineRange = new LineRange(lastMapping.modifiedLineRange.startLineNumber, currentModifiedRange.endLineNumberExclusive);
|
|
98
|
+
nextMappings.push(lastMapping);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const mapping = {
|
|
103
|
+
modifiedLineRange: currentModifiedRange,
|
|
104
|
+
originalLineRange: range,
|
|
105
|
+
};
|
|
106
|
+
possibleMappings.push(mapping);
|
|
107
|
+
nextMappings.push(mapping);
|
|
108
|
+
});
|
|
109
|
+
lastMappings = nextMappings;
|
|
110
|
+
}
|
|
111
|
+
if (!timeout.isValid()) {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
possibleMappings.sort(reverseOrder(compareBy(m => m.modifiedLineRange.length, numberComparator)));
|
|
116
|
+
const modifiedSet = new LineRangeSet();
|
|
117
|
+
const originalSet = new LineRangeSet();
|
|
118
|
+
for (const mapping of possibleMappings) {
|
|
119
|
+
const diffOrigToMod = mapping.modifiedLineRange.startLineNumber - mapping.originalLineRange.startLineNumber;
|
|
120
|
+
const modifiedSections = modifiedSet.subtractFrom(mapping.modifiedLineRange);
|
|
121
|
+
const originalTranslatedSections = originalSet.subtractFrom(mapping.originalLineRange).getWithDelta(diffOrigToMod);
|
|
122
|
+
const modifiedIntersectedSections = modifiedSections.getIntersection(originalTranslatedSections);
|
|
123
|
+
for (const s of modifiedIntersectedSections.ranges) {
|
|
124
|
+
if (s.length < 3) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
const modifiedLineRange = s;
|
|
128
|
+
const originalLineRange = s.delta(-diffOrigToMod);
|
|
129
|
+
moves.push(new LineRangeMapping(originalLineRange, modifiedLineRange));
|
|
130
|
+
modifiedSet.addRange(modifiedLineRange);
|
|
131
|
+
originalSet.addRange(originalLineRange);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
moves.sort(compareBy(m => m.original.startLineNumber, numberComparator));
|
|
135
|
+
const monotonousChanges = new MonotonousArray(changes);
|
|
136
|
+
for (let i = 0; i < moves.length; i++) {
|
|
137
|
+
const move = moves[i];
|
|
138
|
+
const firstTouchingChangeOrig = monotonousChanges.findLastMonotonous(c => c.original.startLineNumber <= move.original.startLineNumber);
|
|
139
|
+
const firstTouchingChangeMod = findLastMonotonous(changes, c => c.modified.startLineNumber <= move.modified.startLineNumber);
|
|
140
|
+
const linesAbove = Math.max(move.original.startLineNumber - firstTouchingChangeOrig.original.startLineNumber, move.modified.startLineNumber - firstTouchingChangeMod.modified.startLineNumber);
|
|
141
|
+
const lastTouchingChangeOrig = monotonousChanges.findLastMonotonous(c => c.original.startLineNumber < move.original.endLineNumberExclusive);
|
|
142
|
+
const lastTouchingChangeMod = findLastMonotonous(changes, c => c.modified.startLineNumber < move.modified.endLineNumberExclusive);
|
|
143
|
+
const linesBelow = Math.max(lastTouchingChangeOrig.original.endLineNumberExclusive - move.original.endLineNumberExclusive, lastTouchingChangeMod.modified.endLineNumberExclusive - move.modified.endLineNumberExclusive);
|
|
144
|
+
let extendToTop;
|
|
145
|
+
for (extendToTop = 0; extendToTop < linesAbove; extendToTop++) {
|
|
146
|
+
const origLine = move.original.startLineNumber - extendToTop - 1;
|
|
147
|
+
const modLine = move.modified.startLineNumber - extendToTop - 1;
|
|
148
|
+
if (origLine > originalLines.length || modLine > modifiedLines.length) {
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
if (modifiedSet.contains(modLine) || originalSet.contains(origLine)) {
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
if (!areLinesSimilar(originalLines[origLine - 1], modifiedLines[modLine - 1], timeout)) {
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (extendToTop > 0) {
|
|
159
|
+
originalSet.addRange(new LineRange(move.original.startLineNumber - extendToTop, move.original.startLineNumber));
|
|
160
|
+
modifiedSet.addRange(new LineRange(move.modified.startLineNumber - extendToTop, move.modified.startLineNumber));
|
|
161
|
+
}
|
|
162
|
+
let extendToBottom;
|
|
163
|
+
for (extendToBottom = 0; extendToBottom < linesBelow; extendToBottom++) {
|
|
164
|
+
const origLine = move.original.endLineNumberExclusive + extendToBottom;
|
|
165
|
+
const modLine = move.modified.endLineNumberExclusive + extendToBottom;
|
|
166
|
+
if (origLine > originalLines.length || modLine > modifiedLines.length) {
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
if (modifiedSet.contains(modLine) || originalSet.contains(origLine)) {
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
if (!areLinesSimilar(originalLines[origLine - 1], modifiedLines[modLine - 1], timeout)) {
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (extendToBottom > 0) {
|
|
177
|
+
originalSet.addRange(new LineRange(move.original.endLineNumberExclusive, move.original.endLineNumberExclusive + extendToBottom));
|
|
178
|
+
modifiedSet.addRange(new LineRange(move.modified.endLineNumberExclusive, move.modified.endLineNumberExclusive + extendToBottom));
|
|
179
|
+
}
|
|
180
|
+
if (extendToTop > 0 || extendToBottom > 0) {
|
|
181
|
+
moves[i] = new LineRangeMapping(new LineRange(move.original.startLineNumber - extendToTop, move.original.endLineNumberExclusive + extendToBottom), new LineRange(move.modified.startLineNumber - extendToTop, move.modified.endLineNumberExclusive + extendToBottom));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return moves;
|
|
185
|
+
}
|
|
186
|
+
function areLinesSimilar(line1, line2, timeout) {
|
|
187
|
+
if (line1.trim() === line2.trim()) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
if (line1.length > 300 && line2.length > 300) {
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
const myersDiffingAlgorithm = new MyersDiffAlgorithm();
|
|
194
|
+
const result = myersDiffingAlgorithm.compute(new LinesSliceCharSequence([line1], new Range(1, 1, 1, line1.length), false), new LinesSliceCharSequence([line2], new Range(1, 1, 1, line2.length), false), timeout);
|
|
195
|
+
let commonNonSpaceCharCount = 0;
|
|
196
|
+
const inverted = SequenceDiff.invert(result.diffs, line1.length);
|
|
197
|
+
for (const seq of inverted) {
|
|
198
|
+
seq.seq1Range.forEach(idx => {
|
|
199
|
+
if (!isSpace(line1.charCodeAt(idx))) {
|
|
200
|
+
commonNonSpaceCharCount++;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function countNonWsChars(str) {
|
|
205
|
+
let count = 0;
|
|
206
|
+
for (let i = 0; i < line1.length; i++) {
|
|
207
|
+
if (!isSpace(str.charCodeAt(i))) {
|
|
208
|
+
count++;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return count;
|
|
212
|
+
}
|
|
213
|
+
const longerLineLength = countNonWsChars(line1.length > line2.length ? line1 : line2);
|
|
214
|
+
const r = commonNonSpaceCharCount / longerLineLength > 0.6 && longerLineLength > 10;
|
|
215
|
+
return r;
|
|
216
|
+
}
|
|
217
|
+
function joinCloseConsecutiveMoves(moves) {
|
|
218
|
+
if (moves.length === 0) {
|
|
219
|
+
return moves;
|
|
220
|
+
}
|
|
221
|
+
moves.sort(compareBy(m => m.original.startLineNumber, numberComparator));
|
|
222
|
+
const result = [moves[0]];
|
|
223
|
+
for (let i = 1; i < moves.length; i++) {
|
|
224
|
+
const last = result[result.length - 1];
|
|
225
|
+
const current = moves[i];
|
|
226
|
+
const originalDist = current.original.startLineNumber - last.original.endLineNumberExclusive;
|
|
227
|
+
const modifiedDist = current.modified.startLineNumber - last.modified.endLineNumberExclusive;
|
|
228
|
+
const currentMoveAfterLast = originalDist >= 0 && modifiedDist >= 0;
|
|
229
|
+
if (currentMoveAfterLast && originalDist + modifiedDist <= 2) {
|
|
230
|
+
result[result.length - 1] = last.join(current);
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
result.push(current);
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
function removeMovesInSameDiff(changes, moves) {
|
|
238
|
+
const changesMonotonous = new MonotonousArray(changes);
|
|
239
|
+
moves = moves.filter(m => {
|
|
240
|
+
const diffBeforeEndOfMoveOriginal = changesMonotonous.findLastMonotonous(c => c.original.startLineNumber < m.original.endLineNumberExclusive)
|
|
241
|
+
|| new LineRangeMapping(new LineRange(1, 1), new LineRange(1, 1));
|
|
242
|
+
const diffBeforeEndOfMoveModified = findLastMonotonous(changes, c => c.modified.startLineNumber < m.modified.endLineNumberExclusive);
|
|
243
|
+
const differentDiffs = diffBeforeEndOfMoveOriginal !== diffBeforeEndOfMoveModified;
|
|
244
|
+
return differentDiffs;
|
|
245
|
+
});
|
|
246
|
+
return moves;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export { computeMovedLines };
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { ListAstNode } from './ast.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
|
+
* Concatenates a list of (2,3) AstNode's into a single (2,3) AstNode.
|
|
9
|
+
* This mutates the items of the input array!
|
|
10
|
+
* If all items have the same height, this method has runtime O(items.length).
|
|
11
|
+
* Otherwise, it has runtime O(items.length * max(log(items.length), items.max(i => i.height))).
|
|
12
|
+
*/
|
|
13
|
+
function concat23Trees(items) {
|
|
14
|
+
if (items.length === 0) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (items.length === 1) {
|
|
18
|
+
return items[0];
|
|
19
|
+
}
|
|
20
|
+
let i = 0;
|
|
21
|
+
/**
|
|
22
|
+
* Reads nodes of same height and concatenates them to a single node.
|
|
23
|
+
*/
|
|
24
|
+
function readNode() {
|
|
25
|
+
if (i >= items.length) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const start = i;
|
|
29
|
+
const height = items[start].listHeight;
|
|
30
|
+
i++;
|
|
31
|
+
while (i < items.length && items[i].listHeight === height) {
|
|
32
|
+
i++;
|
|
33
|
+
}
|
|
34
|
+
if (i - start >= 2) {
|
|
35
|
+
return concat23TreesOfSameHeight(start === 0 && i === items.length ? items : items.slice(start, i), false);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return items[start];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// The items might not have the same height.
|
|
42
|
+
// We merge all items by using a binary concat operator.
|
|
43
|
+
let first = readNode(); // There must be a first item
|
|
44
|
+
let second = readNode();
|
|
45
|
+
if (!second) {
|
|
46
|
+
return first;
|
|
47
|
+
}
|
|
48
|
+
for (let item = readNode(); item; item = readNode()) {
|
|
49
|
+
// Prefer concatenating smaller trees, as the runtime of concat depends on the tree height.
|
|
50
|
+
if (heightDiff(first, second) <= heightDiff(second, item)) {
|
|
51
|
+
first = concat(first, second);
|
|
52
|
+
second = item;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
second = concat(second, item);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const result = concat(first, second);
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
function concat23TreesOfSameHeight(items, createImmutableLists = false) {
|
|
62
|
+
if (items.length === 0) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (items.length === 1) {
|
|
66
|
+
return items[0];
|
|
67
|
+
}
|
|
68
|
+
let length = items.length;
|
|
69
|
+
// All trees have same height, just create parent nodes.
|
|
70
|
+
while (length > 3) {
|
|
71
|
+
const newLength = length >> 1;
|
|
72
|
+
for (let i = 0; i < newLength; i++) {
|
|
73
|
+
const j = i << 1;
|
|
74
|
+
items[i] = ListAstNode.create23(items[j], items[j + 1], j + 3 === length ? items[j + 2] : null, createImmutableLists);
|
|
75
|
+
}
|
|
76
|
+
length = newLength;
|
|
77
|
+
}
|
|
78
|
+
return ListAstNode.create23(items[0], items[1], length >= 3 ? items[2] : null, createImmutableLists);
|
|
79
|
+
}
|
|
80
|
+
function heightDiff(node1, node2) {
|
|
81
|
+
return Math.abs(node1.listHeight - node2.listHeight);
|
|
82
|
+
}
|
|
83
|
+
function concat(node1, node2) {
|
|
84
|
+
if (node1.listHeight === node2.listHeight) {
|
|
85
|
+
return ListAstNode.create23(node1, node2, null, false);
|
|
86
|
+
}
|
|
87
|
+
else if (node1.listHeight > node2.listHeight) {
|
|
88
|
+
// node1 is the tree we want to insert into
|
|
89
|
+
return append(node1, node2);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
return prepend(node2, node1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Appends the given node to the end of this (2,3) tree.
|
|
97
|
+
* Returns the new root.
|
|
98
|
+
*/
|
|
99
|
+
function append(list, nodeToAppend) {
|
|
100
|
+
list = list.toMutable();
|
|
101
|
+
let curNode = list;
|
|
102
|
+
const parents = [];
|
|
103
|
+
let nodeToAppendOfCorrectHeight;
|
|
104
|
+
while (true) {
|
|
105
|
+
// assert nodeToInsert.listHeight <= curNode.listHeight
|
|
106
|
+
if (nodeToAppend.listHeight === curNode.listHeight) {
|
|
107
|
+
nodeToAppendOfCorrectHeight = nodeToAppend;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
// assert 0 <= nodeToInsert.listHeight < curNode.listHeight
|
|
111
|
+
if (curNode.kind !== 4 /* AstNodeKind.List */) {
|
|
112
|
+
throw new Error('unexpected');
|
|
113
|
+
}
|
|
114
|
+
parents.push(curNode);
|
|
115
|
+
// assert 2 <= curNode.childrenLength <= 3
|
|
116
|
+
curNode = curNode.makeLastElementMutable();
|
|
117
|
+
}
|
|
118
|
+
// assert nodeToAppendOfCorrectHeight!.listHeight === curNode.listHeight
|
|
119
|
+
for (let i = parents.length - 1; i >= 0; i--) {
|
|
120
|
+
const parent = parents[i];
|
|
121
|
+
if (nodeToAppendOfCorrectHeight) {
|
|
122
|
+
// Can we take the element?
|
|
123
|
+
if (parent.childrenLength >= 3) {
|
|
124
|
+
// assert parent.childrenLength === 3 && parent.listHeight === nodeToAppendOfCorrectHeight.listHeight + 1
|
|
125
|
+
// we need to split to maintain (2,3)-tree property.
|
|
126
|
+
// Send the third element + the new element to the parent.
|
|
127
|
+
nodeToAppendOfCorrectHeight = ListAstNode.create23(parent.unappendChild(), nodeToAppendOfCorrectHeight, null, false);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
parent.appendChildOfSameHeight(nodeToAppendOfCorrectHeight);
|
|
131
|
+
nodeToAppendOfCorrectHeight = undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
parent.handleChildrenChanged();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (nodeToAppendOfCorrectHeight) {
|
|
139
|
+
return ListAstNode.create23(list, nodeToAppendOfCorrectHeight, null, false);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
return list;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Prepends the given node to the end of this (2,3) tree.
|
|
147
|
+
* Returns the new root.
|
|
148
|
+
*/
|
|
149
|
+
function prepend(list, nodeToAppend) {
|
|
150
|
+
list = list.toMutable();
|
|
151
|
+
let curNode = list;
|
|
152
|
+
const parents = [];
|
|
153
|
+
// assert nodeToInsert.listHeight <= curNode.listHeight
|
|
154
|
+
while (nodeToAppend.listHeight !== curNode.listHeight) {
|
|
155
|
+
// assert 0 <= nodeToInsert.listHeight < curNode.listHeight
|
|
156
|
+
if (curNode.kind !== 4 /* AstNodeKind.List */) {
|
|
157
|
+
throw new Error('unexpected');
|
|
158
|
+
}
|
|
159
|
+
parents.push(curNode);
|
|
160
|
+
// assert 2 <= curNode.childrenFast.length <= 3
|
|
161
|
+
curNode = curNode.makeFirstElementMutable();
|
|
162
|
+
}
|
|
163
|
+
let nodeToPrependOfCorrectHeight = nodeToAppend;
|
|
164
|
+
// assert nodeToAppendOfCorrectHeight!.listHeight === curNode.listHeight
|
|
165
|
+
for (let i = parents.length - 1; i >= 0; i--) {
|
|
166
|
+
const parent = parents[i];
|
|
167
|
+
if (nodeToPrependOfCorrectHeight) {
|
|
168
|
+
// Can we take the element?
|
|
169
|
+
if (parent.childrenLength >= 3) {
|
|
170
|
+
// assert parent.childrenLength === 3 && parent.listHeight === nodeToAppendOfCorrectHeight.listHeight + 1
|
|
171
|
+
// we need to split to maintain (2,3)-tree property.
|
|
172
|
+
// Send the third element + the new element to the parent.
|
|
173
|
+
nodeToPrependOfCorrectHeight = ListAstNode.create23(nodeToPrependOfCorrectHeight, parent.unprependChild(), null, false);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
parent.prependChildOfSameHeight(nodeToPrependOfCorrectHeight);
|
|
177
|
+
nodeToPrependOfCorrectHeight = undefined;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
parent.handleChildrenChanged();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (nodeToPrependOfCorrectHeight) {
|
|
185
|
+
return ListAstNode.create23(nodeToPrependOfCorrectHeight, list, null, false);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
return list;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export { concat23Trees, concat23TreesOfSameHeight };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents contiguous tokens over a contiguous range of lines.
|
|
3
|
+
*/
|
|
4
|
+
class ContiguousMultilineTokens {
|
|
5
|
+
/**
|
|
6
|
+
* (Inclusive) start line number for these tokens.
|
|
7
|
+
*/
|
|
8
|
+
get startLineNumber() {
|
|
9
|
+
return this._startLineNumber;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* (Inclusive) end line number for these tokens.
|
|
13
|
+
*/
|
|
14
|
+
get endLineNumber() {
|
|
15
|
+
return this._startLineNumber + this._tokens.length - 1;
|
|
16
|
+
}
|
|
17
|
+
constructor(startLineNumber, tokens) {
|
|
18
|
+
this._startLineNumber = startLineNumber;
|
|
19
|
+
this._tokens = tokens;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @see {@link _tokens}
|
|
23
|
+
*/
|
|
24
|
+
getLineTokens(lineNumber) {
|
|
25
|
+
return this._tokens[lineNumber - this._startLineNumber];
|
|
26
|
+
}
|
|
27
|
+
appendLineTokens(lineTokens) {
|
|
28
|
+
this._tokens.push(lineTokens);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { ContiguousMultilineTokens };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ContiguousMultilineTokens } from './contiguousMultilineTokens.js';
|
|
2
|
+
|
|
3
|
+
class ContiguousMultilineTokensBuilder {
|
|
4
|
+
constructor() {
|
|
5
|
+
this._tokens = [];
|
|
6
|
+
}
|
|
7
|
+
add(lineNumber, lineTokens) {
|
|
8
|
+
if (this._tokens.length > 0) {
|
|
9
|
+
const last = this._tokens[this._tokens.length - 1];
|
|
10
|
+
if (last.endLineNumber + 1 === lineNumber) {
|
|
11
|
+
// append
|
|
12
|
+
last.appendLineTokens(lineTokens);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
this._tokens.push(new ContiguousMultilineTokens(lineNumber, [lineTokens]));
|
|
17
|
+
}
|
|
18
|
+
finalize() {
|
|
19
|
+
return this._tokens;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { ContiguousMultilineTokensBuilder };
|