monaco-editor11 1.0.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/monaco-editor11.es.js +11 -16
- package/dist/monaco-editor11.umd.js +1 -1
- package/package.json +2 -2
- package/dist/monaco.d.ts +0 -8
- package/dist/workers/common/initialize.js +0 -16
- package/dist/workers/common/workers.js +0 -141
- package/dist/workers/editor/common/abstractSyntaxTokenBackend.js +0 -128
- package/dist/workers/editor/common/abstractText.js +0 -89
- package/dist/workers/editor/common/ast.js +0 -485
- package/dist/workers/editor/common/autoIndent.js +0 -390
- package/dist/workers/editor/common/beforeEditPositionMapper.js +0 -110
- package/dist/workers/editor/common/bracketPairsImpl.js +0 -717
- package/dist/workers/editor/common/bracketPairsTree.js +0 -343
- package/dist/workers/editor/common/brackets.js +0 -108
- package/dist/workers/editor/common/characterClassifier.js +0 -59
- package/dist/workers/editor/common/characterPair.js +0 -40
- package/dist/workers/editor/common/colorizedBracketPairsDecorationProvider.js +0 -97
- package/dist/workers/editor/common/columnRange.js +0 -35
- package/dist/workers/editor/common/combineTextEditInfos.js +0 -124
- package/dist/workers/editor/common/common.js +0 -20
- package/dist/workers/editor/common/computeMovedLines.js +0 -249
- package/dist/workers/editor/common/concat23Trees.js +0 -192
- package/dist/workers/editor/common/contiguousMultilineTokens.js +0 -32
- package/dist/workers/editor/common/contiguousMultilineTokensBuilder.js +0 -23
- package/dist/workers/editor/common/contiguousTokensEditing.js +0 -128
- package/dist/workers/editor/common/contiguousTokensStore.js +0 -207
- package/dist/workers/editor/common/coordinatesConverter.js +0 -51
- package/dist/workers/editor/common/cursor.js +0 -899
- package/dist/workers/editor/common/cursorAtomicMoveOperations.js +0 -145
- package/dist/workers/editor/common/cursorCollection.js +0 -194
- package/dist/workers/editor/common/cursorColumnSelection.js +0 -93
- package/dist/workers/editor/common/cursorColumns.js +0 -112
- package/dist/workers/editor/common/cursorCommon.js +0 -250
- package/dist/workers/editor/common/cursorContext.js +0 -15
- package/dist/workers/editor/common/cursorDeleteOperations.js +0 -231
- package/dist/workers/editor/common/cursorMoveCommands.js +0 -676
- package/dist/workers/editor/common/cursorMoveOperations.js +0 -290
- package/dist/workers/editor/common/cursorTypeEditOperations.js +0 -968
- package/dist/workers/editor/common/cursorTypeOperations.js +0 -173
- package/dist/workers/editor/common/cursorUtils.js +0 -75
- package/dist/workers/editor/common/cursorWordOperations.js +0 -720
- package/dist/workers/editor/common/defaultDocumentColorsComputer.js +0 -138
- package/dist/workers/editor/common/defaultLinesDiffComputer.js +0 -188
- package/dist/workers/editor/common/diffAlgorithm.js +0 -139
- package/dist/workers/editor/common/diffEditor.js +0 -38
- package/dist/workers/editor/common/dynamicProgrammingDiffing.js +0 -101
- package/dist/workers/editor/common/edit.js +0 -183
- package/dist/workers/editor/common/editOperation.js +0 -36
- package/dist/workers/editor/common/editStack.js +0 -363
- package/dist/workers/editor/common/editorAction.js +0 -26
- package/dist/workers/editor/common/editorBaseApi.js +0 -43
- package/dist/workers/editor/common/editorColorRegistry.js +0 -102
- package/dist/workers/editor/common/editorCommon.js +0 -13
- package/dist/workers/editor/common/editorConfigurationSchema.js +0 -338
- package/dist/workers/editor/common/editorContextKeys.js +0 -84
- package/dist/workers/editor/common/editorFeatures.js +0 -17
- package/dist/workers/editor/common/editorOptions.js +0 -3440
- package/dist/workers/editor/common/editorTheme.js +0 -23
- package/dist/workers/editor/common/editorWebWorker.js +0 -299
- package/dist/workers/editor/common/editorWorker.js +0 -9
- package/dist/workers/editor/common/editorWorkerHost.js +0 -15
- package/dist/workers/editor/common/editorZoom.js +0 -26
- package/dist/workers/editor/common/electricCharacter.js +0 -55
- package/dist/workers/editor/common/encodedTokenAttributes.js +0 -79
- package/dist/workers/editor/common/enterAction.js +0 -53
- package/dist/workers/editor/common/eolCounter.js +0 -44
- package/dist/workers/editor/common/findSectionHeaders.js +0 -128
- package/dist/workers/editor/common/fixBrackets.js +0 -67
- package/dist/workers/editor/common/fixedArray.js +0 -70
- package/dist/workers/editor/common/fontInfo.js +0 -172
- package/dist/workers/editor/common/fontInfoFromSettings.js +0 -29
- package/dist/workers/editor/common/getIconClasses.js +0 -106
- package/dist/workers/editor/common/getPositionOffsetTransformerFromTextModel.js +0 -24
- package/dist/workers/editor/common/glyphLanesModel.js +0 -61
- package/dist/workers/editor/common/guidesTextModelPart.js +0 -405
- package/dist/workers/editor/common/heuristicSequenceOptimizations.js +0 -374
- package/dist/workers/editor/common/indentRules.js +0 -63
- package/dist/workers/editor/common/indentation.js +0 -39
- package/dist/workers/editor/common/indentationGuesser.js +0 -178
- package/dist/workers/editor/common/indentationLineProcessor.js +0 -193
- package/dist/workers/editor/common/inlineDecorations.js +0 -26
- package/dist/workers/editor/common/inplaceReplaceSupport.js +0 -87
- package/dist/workers/editor/common/inputMode.js +0 -22
- package/dist/workers/editor/common/intervalTree.js +0 -1002
- package/dist/workers/editor/common/language.js +0 -9
- package/dist/workers/editor/common/languageBracketsConfiguration.js +0 -133
- package/dist/workers/editor/common/languageConfiguration.js +0 -138
- package/dist/workers/editor/common/languageConfigurationRegistry.js +0 -361
- package/dist/workers/editor/common/languageFeatureDebounce.js +0 -137
- package/dist/workers/editor/common/languageFeatureRegistry.js +0 -180
- package/dist/workers/editor/common/languageFeatures.js +0 -9
- package/dist/workers/editor/common/languageFeaturesService.js +0 -47
- package/dist/workers/editor/common/languageSelector.js +0 -112
- package/dist/workers/editor/common/languageService.js +0 -92
- package/dist/workers/editor/common/languages.js +0 -522
- package/dist/workers/editor/common/languagesAssociations.js +0 -193
- package/dist/workers/editor/common/languagesRegistry.js +0 -237
- package/dist/workers/editor/common/legacyLinesDiffComputer.js +0 -468
- package/dist/workers/editor/common/length.js +0 -129
- package/dist/workers/editor/common/lineDecorations.js +0 -208
- package/dist/workers/editor/common/lineEdit.js +0 -75
- package/dist/workers/editor/common/lineHeights.js +0 -370
- package/dist/workers/editor/common/linePart.js +0 -25
- package/dist/workers/editor/common/lineRange.js +0 -312
- package/dist/workers/editor/common/lineSequence.js +0 -36
- package/dist/workers/editor/common/lineTokens.js +0 -405
- package/dist/workers/editor/common/linesDiffComputer.js +0 -29
- package/dist/workers/editor/common/linesDiffComputers.js +0 -13
- package/dist/workers/editor/common/linesLayout.js +0 -765
- package/dist/workers/editor/common/linesSliceCharSequence.js +0 -205
- package/dist/workers/editor/common/linkComputer.js +0 -269
- package/dist/workers/editor/common/markerDecorations.js +0 -9
- package/dist/workers/editor/common/markerDecorationsService.js +0 -248
- package/dist/workers/editor/common/minimapTokensColorTracker.js +0 -58
- package/dist/workers/editor/common/mirrorTextModel.js +0 -117
- package/dist/workers/editor/common/model.js +0 -9
- package/dist/workers/editor/common/modelLineProjection.js +0 -350
- package/dist/workers/editor/common/modelLineProjectionData.js +0 -297
- package/dist/workers/editor/common/modelService.js +0 -413
- package/dist/workers/editor/common/modesRegistry.js +0 -75
- package/dist/workers/editor/common/monospaceLineBreaksComputer.js +0 -473
- package/dist/workers/editor/common/myersDiffAlgorithm.js +0 -159
- package/dist/workers/editor/common/nodeReader.js +0 -127
- package/dist/workers/editor/common/nullTokenize.js +0 -29
- package/dist/workers/editor/common/offsetRange.js +0 -225
- package/dist/workers/editor/common/onEnter.js +0 -109
- package/dist/workers/editor/common/oneCursor.js +0 -117
- package/dist/workers/editor/common/overviewZoneManager.js +0 -176
- package/dist/workers/editor/common/parser.js +0 -121
- package/dist/workers/editor/common/pieceTreeBase.js +0 -1473
- package/dist/workers/editor/common/pieceTreeTextBuffer.js +0 -461
- package/dist/workers/editor/common/pieceTreeTextBufferBuilder.js +0 -140
- package/dist/workers/editor/common/point.js +0 -50
- package/dist/workers/editor/common/position.js +0 -142
- package/dist/workers/editor/common/positionToOffset.js +0 -17
- package/dist/workers/editor/common/positionToOffsetImpl.js +0 -98
- package/dist/workers/editor/common/prefixSumComputer.js +0 -226
- package/dist/workers/editor/common/range.js +0 -421
- package/dist/workers/editor/common/rangeMapping.js +0 -229
- package/dist/workers/editor/common/rangeSingleLine.js +0 -17
- package/dist/workers/editor/common/rbTreeBase.js +0 -362
- package/dist/workers/editor/common/rect.js +0 -163
- package/dist/workers/editor/common/replaceCommand.js +0 -158
- package/dist/workers/editor/common/resolverService.js +0 -5
- package/dist/workers/editor/common/rgba.js +0 -35
- package/dist/workers/editor/common/richEditBrackets.js +0 -356
- package/dist/workers/editor/common/selection.js +0 -145
- package/dist/workers/editor/common/semanticTokensDto.js +0 -82
- package/dist/workers/editor/common/semanticTokensProviderStyling.js +0 -263
- package/dist/workers/editor/common/semanticTokensStyling.js +0 -9
- package/dist/workers/editor/common/semanticTokensStylingService.js +0 -47
- package/dist/workers/editor/common/shiftCommand.js +0 -241
- package/dist/workers/editor/common/smallImmutableSet.js +0 -108
- package/dist/workers/editor/common/sparseMultilineTokens.js +0 -548
- package/dist/workers/editor/common/sparseTokensStore.js +0 -210
- package/dist/workers/editor/common/standaloneEnums.js +0 -1017
- package/dist/workers/editor/common/standaloneStrings.js +0 -42
- package/dist/workers/editor/common/stringBuilder.js +0 -122
- package/dist/workers/editor/common/stringEdit.js +0 -165
- package/dist/workers/editor/common/supports.js +0 -58
- package/dist/workers/editor/common/surroundSelectionCommand.js +0 -44
- package/dist/workers/editor/common/textChange.js +0 -248
- package/dist/workers/editor/common/textEdit.js +0 -269
- package/dist/workers/editor/common/textLength.js +0 -87
- package/dist/workers/editor/common/textModel.js +0 -2031
- package/dist/workers/editor/common/textModelBracketPairs.js +0 -45
- package/dist/workers/editor/common/textModelDefaults.js +0 -18
- package/dist/workers/editor/common/textModelEditSource.js +0 -166
- package/dist/workers/editor/common/textModelEvents.js +0 -216
- package/dist/workers/editor/common/textModelGuides.js +0 -40
- package/dist/workers/editor/common/textModelPart.js +0 -23
- package/dist/workers/editor/common/textModelSearch.js +0 -455
- package/dist/workers/editor/common/textModelStringEdit.js +0 -11
- package/dist/workers/editor/common/textModelSync.impl.js +0 -307
- package/dist/workers/editor/common/textModelText.js +0 -26
- package/dist/workers/editor/common/textModelTokens.js +0 -436
- package/dist/workers/editor/common/textResourceConfiguration.js +0 -6
- package/dist/workers/editor/common/textToHtmlTokenizer.js +0 -139
- package/dist/workers/editor/common/tokenStore.js +0 -407
- package/dist/workers/editor/common/tokenWithTextArray.js +0 -73
- package/dist/workers/editor/common/tokenization.js +0 -287
- package/dist/workers/editor/common/tokenizationRegistry.js +0 -123
- package/dist/workers/editor/common/tokenizationTextModelPart.js +0 -275
- package/dist/workers/editor/common/tokenizer.js +0 -301
- package/dist/workers/editor/common/tokenizerSyntaxTokenBackend.js +0 -261
- package/dist/workers/editor/common/treeSitterLibraryService.js +0 -9
- package/dist/workers/editor/common/treeSitterSyntaxTokenBackend.js +0 -167
- package/dist/workers/editor/common/treeSitterThemeService.js +0 -9
- package/dist/workers/editor/common/treeSitterTokenizationImpl.js +0 -713
- package/dist/workers/editor/common/treeSitterTree.js +0 -395
- package/dist/workers/editor/common/treeViewsDnd.js +0 -24
- package/dist/workers/editor/common/treeViewsDndService.js +0 -12
- package/dist/workers/editor/common/trimTrailingWhitespaceCommand.js +0 -98
- package/dist/workers/editor/common/unicodeTextModelHighlighter.js +0 -188
- package/dist/workers/editor/common/utils.js +0 -62
- package/dist/workers/editor/common/viewContext.js +0 -22
- package/dist/workers/editor/common/viewEventHandler.js +0 -186
- package/dist/workers/editor/common/viewEvents.js +0 -180
- package/dist/workers/editor/common/viewLayout.js +0 -368
- package/dist/workers/editor/common/viewLineRenderer.js +0 -948
- package/dist/workers/editor/common/viewLinesViewportData.js +0 -30
- package/dist/workers/editor/common/viewModel.js +0 -98
- package/dist/workers/editor/common/viewModelDecoration.js +0 -55
- package/dist/workers/editor/common/viewModelDecorations.js +0 -132
- package/dist/workers/editor/common/viewModelEventDispatcher.js +0 -398
- package/dist/workers/editor/common/viewModelImpl.js +0 -1163
- package/dist/workers/editor/common/viewModelLines.js +0 -938
- package/dist/workers/editor/common/wordCharacterClassifier.js +0 -87
- package/dist/workers/editor/common/wordHelper.js +0 -127
- package/dist/workers/language/cssMode.js +0 -198
- package/dist/workers/language/cssWorker.js +0 -183
- package/dist/workers/language/htmlMode.js +0 -213
- package/dist/workers/language/htmlWorker.js +0 -126
- package/dist/workers/language/jsonMode.js +0 -224
- package/dist/workers/language/jsonWorker.js +0 -187
- package/dist/workers/language/languageFeatures.js +0 -1009
- package/dist/workers/language/lib.index.js +0 -103
- package/dist/workers/language/lib.js +0 -1107
- package/dist/workers/language/lspLanguageFeatures.js +0 -716
- package/dist/workers/language/monaco.contribution.js +0 -144
- package/dist/workers/language/tokenization.js +0 -189
- package/dist/workers/language/tsMode.js +0 -212
- package/dist/workers/language/tsWorker.js +0 -352
- package/dist/workers/language/typescriptServices.js +0 -210154
- package/dist/workers/language/typescriptServicesMetadata.js +0 -3
- package/dist/workers/language/workerManager.js +0 -65
- /package/dist/workers/{language/css.worker.js → css.worker.js} +0 -0
- /package/dist/workers/{editor/editor.worker.js → editor.worker.js} +0 -0
- /package/dist/workers/{language/html.worker.js → html.worker.js} +0 -0
- /package/dist/workers/{language/json.worker.js → json.worker.js} +0 -0
- /package/dist/workers/{language/ts.worker.js → ts.worker.js} +0 -0
|
@@ -1,374 +0,0 @@
|
|
|
1
|
-
import { forEachWithNeighbors } from '../../../../base/common/arrays.js';
|
|
2
|
-
import { OffsetRange } from '../../core/ranges/offsetRange.js';
|
|
3
|
-
import { SequenceDiff, OffsetPair } from './algorithms/diffAlgorithm.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 optimizeSequenceDiffs(sequence1, sequence2, sequenceDiffs) {
|
|
10
|
-
let result = sequenceDiffs;
|
|
11
|
-
result = joinSequenceDiffsByShifting(sequence1, sequence2, result);
|
|
12
|
-
// Sometimes, calling this function twice improves the result.
|
|
13
|
-
// Uncomment the second invocation and run the tests to see the difference.
|
|
14
|
-
result = joinSequenceDiffsByShifting(sequence1, sequence2, result);
|
|
15
|
-
result = shiftSequenceDiffs(sequence1, sequence2, result);
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* This function fixes issues like this:
|
|
20
|
-
* ```
|
|
21
|
-
* import { Baz, Bar } from "foo";
|
|
22
|
-
* ```
|
|
23
|
-
* <->
|
|
24
|
-
* ```
|
|
25
|
-
* import { Baz, Bar, Foo } from "foo";
|
|
26
|
-
* ```
|
|
27
|
-
* Computed diff: [ {Add "," after Bar}, {Add "Foo " after space} }
|
|
28
|
-
* Improved diff: [{Add ", Foo" after Bar}]
|
|
29
|
-
*/
|
|
30
|
-
function joinSequenceDiffsByShifting(sequence1, sequence2, sequenceDiffs) {
|
|
31
|
-
if (sequenceDiffs.length === 0) {
|
|
32
|
-
return sequenceDiffs;
|
|
33
|
-
}
|
|
34
|
-
const result = [];
|
|
35
|
-
result.push(sequenceDiffs[0]);
|
|
36
|
-
// First move them all to the left as much as possible and join them if possible
|
|
37
|
-
for (let i = 1; i < sequenceDiffs.length; i++) {
|
|
38
|
-
const prevResult = result[result.length - 1];
|
|
39
|
-
let cur = sequenceDiffs[i];
|
|
40
|
-
if (cur.seq1Range.isEmpty || cur.seq2Range.isEmpty) {
|
|
41
|
-
const length = cur.seq1Range.start - prevResult.seq1Range.endExclusive;
|
|
42
|
-
let d;
|
|
43
|
-
for (d = 1; d <= length; d++) {
|
|
44
|
-
if (sequence1.getElement(cur.seq1Range.start - d) !== sequence1.getElement(cur.seq1Range.endExclusive - d) ||
|
|
45
|
-
sequence2.getElement(cur.seq2Range.start - d) !== sequence2.getElement(cur.seq2Range.endExclusive - d)) {
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
d--;
|
|
50
|
-
if (d === length) {
|
|
51
|
-
// Merge previous and current diff
|
|
52
|
-
result[result.length - 1] = new SequenceDiff(new OffsetRange(prevResult.seq1Range.start, cur.seq1Range.endExclusive - length), new OffsetRange(prevResult.seq2Range.start, cur.seq2Range.endExclusive - length));
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
cur = cur.delta(-d);
|
|
56
|
-
}
|
|
57
|
-
result.push(cur);
|
|
58
|
-
}
|
|
59
|
-
const result2 = [];
|
|
60
|
-
// Then move them all to the right and join them again if possible
|
|
61
|
-
for (let i = 0; i < result.length - 1; i++) {
|
|
62
|
-
const nextResult = result[i + 1];
|
|
63
|
-
let cur = result[i];
|
|
64
|
-
if (cur.seq1Range.isEmpty || cur.seq2Range.isEmpty) {
|
|
65
|
-
const length = nextResult.seq1Range.start - cur.seq1Range.endExclusive;
|
|
66
|
-
let d;
|
|
67
|
-
for (d = 0; d < length; d++) {
|
|
68
|
-
if (!sequence1.isStronglyEqual(cur.seq1Range.start + d, cur.seq1Range.endExclusive + d) ||
|
|
69
|
-
!sequence2.isStronglyEqual(cur.seq2Range.start + d, cur.seq2Range.endExclusive + d)) {
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (d === length) {
|
|
74
|
-
// Merge previous and current diff, write to result!
|
|
75
|
-
result[i + 1] = new SequenceDiff(new OffsetRange(cur.seq1Range.start + length, nextResult.seq1Range.endExclusive), new OffsetRange(cur.seq2Range.start + length, nextResult.seq2Range.endExclusive));
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
if (d > 0) {
|
|
79
|
-
cur = cur.delta(d);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
result2.push(cur);
|
|
83
|
-
}
|
|
84
|
-
if (result.length > 0) {
|
|
85
|
-
result2.push(result[result.length - 1]);
|
|
86
|
-
}
|
|
87
|
-
return result2;
|
|
88
|
-
}
|
|
89
|
-
// align character level diffs at whitespace characters
|
|
90
|
-
// import { IBar } from "foo";
|
|
91
|
-
// import { I[Arr, I]Bar } from "foo";
|
|
92
|
-
// ->
|
|
93
|
-
// import { [IArr, ]IBar } from "foo";
|
|
94
|
-
// import { ITransaction, observableValue, transaction } from 'vs/base/common/observable';
|
|
95
|
-
// import { ITransaction, observable[FromEvent, observable]Value, transaction } from 'vs/base/common/observable';
|
|
96
|
-
// ->
|
|
97
|
-
// import { ITransaction, [observableFromEvent, ]observableValue, transaction } from 'vs/base/common/observable';
|
|
98
|
-
// collectBrackets(level + 1, levelPerBracketType);
|
|
99
|
-
// collectBrackets(level + 1, levelPerBracket[ + 1, levelPerBracket]Type);
|
|
100
|
-
// ->
|
|
101
|
-
// collectBrackets(level + 1, [levelPerBracket + 1, ]levelPerBracketType);
|
|
102
|
-
function shiftSequenceDiffs(sequence1, sequence2, sequenceDiffs) {
|
|
103
|
-
if (!sequence1.getBoundaryScore || !sequence2.getBoundaryScore) {
|
|
104
|
-
return sequenceDiffs;
|
|
105
|
-
}
|
|
106
|
-
for (let i = 0; i < sequenceDiffs.length; i++) {
|
|
107
|
-
const prevDiff = (i > 0 ? sequenceDiffs[i - 1] : undefined);
|
|
108
|
-
const diff = sequenceDiffs[i];
|
|
109
|
-
const nextDiff = (i + 1 < sequenceDiffs.length ? sequenceDiffs[i + 1] : undefined);
|
|
110
|
-
const seq1ValidRange = new OffsetRange(prevDiff ? prevDiff.seq1Range.endExclusive + 1 : 0, nextDiff ? nextDiff.seq1Range.start - 1 : sequence1.length);
|
|
111
|
-
const seq2ValidRange = new OffsetRange(prevDiff ? prevDiff.seq2Range.endExclusive + 1 : 0, nextDiff ? nextDiff.seq2Range.start - 1 : sequence2.length);
|
|
112
|
-
if (diff.seq1Range.isEmpty) {
|
|
113
|
-
sequenceDiffs[i] = shiftDiffToBetterPosition(diff, sequence1, sequence2, seq1ValidRange, seq2ValidRange);
|
|
114
|
-
}
|
|
115
|
-
else if (diff.seq2Range.isEmpty) {
|
|
116
|
-
sequenceDiffs[i] = shiftDiffToBetterPosition(diff.swap(), sequence2, sequence1, seq2ValidRange, seq1ValidRange).swap();
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return sequenceDiffs;
|
|
120
|
-
}
|
|
121
|
-
function shiftDiffToBetterPosition(diff, sequence1, sequence2, seq1ValidRange, seq2ValidRange) {
|
|
122
|
-
const maxShiftLimit = 100; // To prevent performance issues
|
|
123
|
-
// don't touch previous or next!
|
|
124
|
-
let deltaBefore = 1;
|
|
125
|
-
while (diff.seq1Range.start - deltaBefore >= seq1ValidRange.start &&
|
|
126
|
-
diff.seq2Range.start - deltaBefore >= seq2ValidRange.start &&
|
|
127
|
-
sequence2.isStronglyEqual(diff.seq2Range.start - deltaBefore, diff.seq2Range.endExclusive - deltaBefore) && deltaBefore < maxShiftLimit) {
|
|
128
|
-
deltaBefore++;
|
|
129
|
-
}
|
|
130
|
-
deltaBefore--;
|
|
131
|
-
let deltaAfter = 0;
|
|
132
|
-
while (diff.seq1Range.start + deltaAfter < seq1ValidRange.endExclusive &&
|
|
133
|
-
diff.seq2Range.endExclusive + deltaAfter < seq2ValidRange.endExclusive &&
|
|
134
|
-
sequence2.isStronglyEqual(diff.seq2Range.start + deltaAfter, diff.seq2Range.endExclusive + deltaAfter) && deltaAfter < maxShiftLimit) {
|
|
135
|
-
deltaAfter++;
|
|
136
|
-
}
|
|
137
|
-
if (deltaBefore === 0 && deltaAfter === 0) {
|
|
138
|
-
return diff;
|
|
139
|
-
}
|
|
140
|
-
// Visualize `[sequence1.text, diff.seq1Range.start + deltaAfter]`
|
|
141
|
-
// and `[sequence2.text, diff.seq2Range.start + deltaAfter, diff.seq2Range.endExclusive + deltaAfter]`
|
|
142
|
-
let bestDelta = 0;
|
|
143
|
-
let bestScore = -1;
|
|
144
|
-
// find best scored delta
|
|
145
|
-
for (let delta = -deltaBefore; delta <= deltaAfter; delta++) {
|
|
146
|
-
const seq2OffsetStart = diff.seq2Range.start + delta;
|
|
147
|
-
const seq2OffsetEndExclusive = diff.seq2Range.endExclusive + delta;
|
|
148
|
-
const seq1Offset = diff.seq1Range.start + delta;
|
|
149
|
-
const score = sequence1.getBoundaryScore(seq1Offset) + sequence2.getBoundaryScore(seq2OffsetStart) + sequence2.getBoundaryScore(seq2OffsetEndExclusive);
|
|
150
|
-
if (score > bestScore) {
|
|
151
|
-
bestScore = score;
|
|
152
|
-
bestDelta = delta;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
return diff.delta(bestDelta);
|
|
156
|
-
}
|
|
157
|
-
function removeShortMatches(sequence1, sequence2, sequenceDiffs) {
|
|
158
|
-
const result = [];
|
|
159
|
-
for (const s of sequenceDiffs) {
|
|
160
|
-
const last = result[result.length - 1];
|
|
161
|
-
if (!last) {
|
|
162
|
-
result.push(s);
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
if (s.seq1Range.start - last.seq1Range.endExclusive <= 2 || s.seq2Range.start - last.seq2Range.endExclusive <= 2) {
|
|
166
|
-
result[result.length - 1] = new SequenceDiff(last.seq1Range.join(s.seq1Range), last.seq2Range.join(s.seq2Range));
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
result.push(s);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return result;
|
|
173
|
-
}
|
|
174
|
-
function extendDiffsToEntireWordIfAppropriate(sequence1, sequence2, sequenceDiffs, findParent, force = false) {
|
|
175
|
-
const equalMappings = SequenceDiff.invert(sequenceDiffs, sequence1.length);
|
|
176
|
-
const additional = [];
|
|
177
|
-
let lastPoint = new OffsetPair(0, 0);
|
|
178
|
-
function scanWord(pair, equalMapping) {
|
|
179
|
-
if (pair.offset1 < lastPoint.offset1 || pair.offset2 < lastPoint.offset2) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
const w1 = findParent(sequence1, pair.offset1);
|
|
183
|
-
const w2 = findParent(sequence2, pair.offset2);
|
|
184
|
-
if (!w1 || !w2) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
let w = new SequenceDiff(w1, w2);
|
|
188
|
-
const equalPart = w.intersect(equalMapping);
|
|
189
|
-
let equalChars1 = equalPart.seq1Range.length;
|
|
190
|
-
let equalChars2 = equalPart.seq2Range.length;
|
|
191
|
-
// The words do not touch previous equals mappings, as we would have processed them already.
|
|
192
|
-
// But they might touch the next ones.
|
|
193
|
-
while (equalMappings.length > 0) {
|
|
194
|
-
const next = equalMappings[0];
|
|
195
|
-
const intersects = next.seq1Range.intersects(w.seq1Range) || next.seq2Range.intersects(w.seq2Range);
|
|
196
|
-
if (!intersects) {
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
const v1 = findParent(sequence1, next.seq1Range.start);
|
|
200
|
-
const v2 = findParent(sequence2, next.seq2Range.start);
|
|
201
|
-
// Because there is an intersection, we know that the words are not empty.
|
|
202
|
-
const v = new SequenceDiff(v1, v2);
|
|
203
|
-
const equalPart = v.intersect(next);
|
|
204
|
-
equalChars1 += equalPart.seq1Range.length;
|
|
205
|
-
equalChars2 += equalPart.seq2Range.length;
|
|
206
|
-
w = w.join(v);
|
|
207
|
-
if (w.seq1Range.endExclusive >= next.seq1Range.endExclusive) {
|
|
208
|
-
// The word extends beyond the next equal mapping.
|
|
209
|
-
equalMappings.shift();
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if ((force && equalChars1 + equalChars2 < w.seq1Range.length + w.seq2Range.length) || equalChars1 + equalChars2 < (w.seq1Range.length + w.seq2Range.length) * 2 / 3) {
|
|
216
|
-
additional.push(w);
|
|
217
|
-
}
|
|
218
|
-
lastPoint = w.getEndExclusives();
|
|
219
|
-
}
|
|
220
|
-
while (equalMappings.length > 0) {
|
|
221
|
-
const next = equalMappings.shift();
|
|
222
|
-
if (next.seq1Range.isEmpty) {
|
|
223
|
-
continue;
|
|
224
|
-
}
|
|
225
|
-
scanWord(next.getStarts(), next);
|
|
226
|
-
// The equal parts are not empty, so -1 gives us a character that is equal in both parts.
|
|
227
|
-
scanWord(next.getEndExclusives().delta(-1), next);
|
|
228
|
-
}
|
|
229
|
-
const merged = mergeSequenceDiffs(sequenceDiffs, additional);
|
|
230
|
-
return merged;
|
|
231
|
-
}
|
|
232
|
-
function mergeSequenceDiffs(sequenceDiffs1, sequenceDiffs2) {
|
|
233
|
-
const result = [];
|
|
234
|
-
while (sequenceDiffs1.length > 0 || sequenceDiffs2.length > 0) {
|
|
235
|
-
const sd1 = sequenceDiffs1[0];
|
|
236
|
-
const sd2 = sequenceDiffs2[0];
|
|
237
|
-
let next;
|
|
238
|
-
if (sd1 && (!sd2 || sd1.seq1Range.start < sd2.seq1Range.start)) {
|
|
239
|
-
next = sequenceDiffs1.shift();
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
next = sequenceDiffs2.shift();
|
|
243
|
-
}
|
|
244
|
-
if (result.length > 0 && result[result.length - 1].seq1Range.endExclusive >= next.seq1Range.start) {
|
|
245
|
-
result[result.length - 1] = result[result.length - 1].join(next);
|
|
246
|
-
}
|
|
247
|
-
else {
|
|
248
|
-
result.push(next);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
return result;
|
|
252
|
-
}
|
|
253
|
-
function removeVeryShortMatchingLinesBetweenDiffs(sequence1, _sequence2, sequenceDiffs) {
|
|
254
|
-
let diffs = sequenceDiffs;
|
|
255
|
-
if (diffs.length === 0) {
|
|
256
|
-
return diffs;
|
|
257
|
-
}
|
|
258
|
-
let counter = 0;
|
|
259
|
-
let shouldRepeat;
|
|
260
|
-
do {
|
|
261
|
-
shouldRepeat = false;
|
|
262
|
-
const result = [
|
|
263
|
-
diffs[0]
|
|
264
|
-
];
|
|
265
|
-
for (let i = 1; i < diffs.length; i++) {
|
|
266
|
-
const cur = diffs[i];
|
|
267
|
-
const lastResult = result[result.length - 1];
|
|
268
|
-
function shouldJoinDiffs(before, after) {
|
|
269
|
-
const unchangedRange = new OffsetRange(lastResult.seq1Range.endExclusive, cur.seq1Range.start);
|
|
270
|
-
const unchangedText = sequence1.getText(unchangedRange);
|
|
271
|
-
const unchangedTextWithoutWs = unchangedText.replace(/\s/g, '');
|
|
272
|
-
if (unchangedTextWithoutWs.length <= 4
|
|
273
|
-
&& (before.seq1Range.length + before.seq2Range.length > 5 || after.seq1Range.length + after.seq2Range.length > 5)) {
|
|
274
|
-
return true;
|
|
275
|
-
}
|
|
276
|
-
return false;
|
|
277
|
-
}
|
|
278
|
-
const shouldJoin = shouldJoinDiffs(lastResult, cur);
|
|
279
|
-
if (shouldJoin) {
|
|
280
|
-
shouldRepeat = true;
|
|
281
|
-
result[result.length - 1] = result[result.length - 1].join(cur);
|
|
282
|
-
}
|
|
283
|
-
else {
|
|
284
|
-
result.push(cur);
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
diffs = result;
|
|
288
|
-
} while (counter++ < 10 && shouldRepeat);
|
|
289
|
-
return diffs;
|
|
290
|
-
}
|
|
291
|
-
function removeVeryShortMatchingTextBetweenLongDiffs(sequence1, sequence2, sequenceDiffs) {
|
|
292
|
-
let diffs = sequenceDiffs;
|
|
293
|
-
if (diffs.length === 0) {
|
|
294
|
-
return diffs;
|
|
295
|
-
}
|
|
296
|
-
let counter = 0;
|
|
297
|
-
let shouldRepeat;
|
|
298
|
-
do {
|
|
299
|
-
shouldRepeat = false;
|
|
300
|
-
const result = [
|
|
301
|
-
diffs[0]
|
|
302
|
-
];
|
|
303
|
-
for (let i = 1; i < diffs.length; i++) {
|
|
304
|
-
const cur = diffs[i];
|
|
305
|
-
const lastResult = result[result.length - 1];
|
|
306
|
-
function shouldJoinDiffs(before, after) {
|
|
307
|
-
const unchangedRange = new OffsetRange(lastResult.seq1Range.endExclusive, cur.seq1Range.start);
|
|
308
|
-
const unchangedLineCount = sequence1.countLinesIn(unchangedRange);
|
|
309
|
-
if (unchangedLineCount > 5 || unchangedRange.length > 500) {
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
const unchangedText = sequence1.getText(unchangedRange).trim();
|
|
313
|
-
if (unchangedText.length > 20 || unchangedText.split(/\r\n|\r|\n/).length > 1) {
|
|
314
|
-
return false;
|
|
315
|
-
}
|
|
316
|
-
const beforeLineCount1 = sequence1.countLinesIn(before.seq1Range);
|
|
317
|
-
const beforeSeq1Length = before.seq1Range.length;
|
|
318
|
-
const beforeLineCount2 = sequence2.countLinesIn(before.seq2Range);
|
|
319
|
-
const beforeSeq2Length = before.seq2Range.length;
|
|
320
|
-
const afterLineCount1 = sequence1.countLinesIn(after.seq1Range);
|
|
321
|
-
const afterSeq1Length = after.seq1Range.length;
|
|
322
|
-
const afterLineCount2 = sequence2.countLinesIn(after.seq2Range);
|
|
323
|
-
const afterSeq2Length = after.seq2Range.length;
|
|
324
|
-
// TODO: Maybe a neural net can be used to derive the result from these numbers
|
|
325
|
-
const max = 2 * 40 + 50;
|
|
326
|
-
function cap(v) {
|
|
327
|
-
return Math.min(v, max);
|
|
328
|
-
}
|
|
329
|
-
if (Math.pow(Math.pow(cap(beforeLineCount1 * 40 + beforeSeq1Length), 1.5) + Math.pow(cap(beforeLineCount2 * 40 + beforeSeq2Length), 1.5), 1.5)
|
|
330
|
-
+ Math.pow(Math.pow(cap(afterLineCount1 * 40 + afterSeq1Length), 1.5) + Math.pow(cap(afterLineCount2 * 40 + afterSeq2Length), 1.5), 1.5) > ((max ** 1.5) ** 1.5) * 1.3) {
|
|
331
|
-
return true;
|
|
332
|
-
}
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
const shouldJoin = shouldJoinDiffs(lastResult, cur);
|
|
336
|
-
if (shouldJoin) {
|
|
337
|
-
shouldRepeat = true;
|
|
338
|
-
result[result.length - 1] = result[result.length - 1].join(cur);
|
|
339
|
-
}
|
|
340
|
-
else {
|
|
341
|
-
result.push(cur);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
diffs = result;
|
|
345
|
-
} while (counter++ < 10 && shouldRepeat);
|
|
346
|
-
const newDiffs = [];
|
|
347
|
-
// Remove short suffixes/prefixes
|
|
348
|
-
forEachWithNeighbors(diffs, (prev, cur, next) => {
|
|
349
|
-
let newDiff = cur;
|
|
350
|
-
function shouldMarkAsChanged(text) {
|
|
351
|
-
return text.length > 0 && text.trim().length <= 3 && cur.seq1Range.length + cur.seq2Range.length > 100;
|
|
352
|
-
}
|
|
353
|
-
const fullRange1 = sequence1.extendToFullLines(cur.seq1Range);
|
|
354
|
-
const prefix = sequence1.getText(new OffsetRange(fullRange1.start, cur.seq1Range.start));
|
|
355
|
-
if (shouldMarkAsChanged(prefix)) {
|
|
356
|
-
newDiff = newDiff.deltaStart(-prefix.length);
|
|
357
|
-
}
|
|
358
|
-
const suffix = sequence1.getText(new OffsetRange(cur.seq1Range.endExclusive, fullRange1.endExclusive));
|
|
359
|
-
if (shouldMarkAsChanged(suffix)) {
|
|
360
|
-
newDiff = newDiff.deltaEnd(suffix.length);
|
|
361
|
-
}
|
|
362
|
-
const availableSpace = SequenceDiff.fromOffsetPairs(prev ? prev.getEndExclusives() : OffsetPair.zero, next ? next.getStarts() : OffsetPair.max);
|
|
363
|
-
const result = newDiff.intersect(availableSpace);
|
|
364
|
-
if (newDiffs.length > 0 && result.getStarts().equals(newDiffs[newDiffs.length - 1].getEndExclusives())) {
|
|
365
|
-
newDiffs[newDiffs.length - 1] = newDiffs[newDiffs.length - 1].join(result);
|
|
366
|
-
}
|
|
367
|
-
else {
|
|
368
|
-
newDiffs.push(result);
|
|
369
|
-
}
|
|
370
|
-
});
|
|
371
|
-
return newDiffs;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
export { extendDiffsToEntireWordIfAppropriate, optimizeSequenceDiffs, removeShortMatches, removeVeryShortMatchingLinesBetweenDiffs, removeVeryShortMatchingTextBetweenLongDiffs };
|
|
@@ -1,63 +0,0 @@
|
|
|
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
|
-
function resetGlobalRegex(reg) {
|
|
6
|
-
if (reg.global) {
|
|
7
|
-
reg.lastIndex = 0;
|
|
8
|
-
}
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
class IndentRulesSupport {
|
|
12
|
-
constructor(indentationRules) {
|
|
13
|
-
this._indentationRules = indentationRules;
|
|
14
|
-
}
|
|
15
|
-
shouldIncrease(text) {
|
|
16
|
-
if (this._indentationRules) {
|
|
17
|
-
if (this._indentationRules.increaseIndentPattern && resetGlobalRegex(this._indentationRules.increaseIndentPattern) && this._indentationRules.increaseIndentPattern.test(text)) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
// if (this._indentationRules.indentNextLinePattern && this._indentationRules.indentNextLinePattern.test(text)) {
|
|
21
|
-
// return true;
|
|
22
|
-
// }
|
|
23
|
-
}
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
shouldDecrease(text) {
|
|
27
|
-
if (this._indentationRules && this._indentationRules.decreaseIndentPattern && resetGlobalRegex(this._indentationRules.decreaseIndentPattern) && this._indentationRules.decreaseIndentPattern.test(text)) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
shouldIndentNextLine(text) {
|
|
33
|
-
if (this._indentationRules && this._indentationRules.indentNextLinePattern && resetGlobalRegex(this._indentationRules.indentNextLinePattern) && this._indentationRules.indentNextLinePattern.test(text)) {
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
shouldIgnore(text) {
|
|
39
|
-
// the text matches `unIndentedLinePattern`
|
|
40
|
-
if (this._indentationRules && this._indentationRules.unIndentedLinePattern && resetGlobalRegex(this._indentationRules.unIndentedLinePattern) && this._indentationRules.unIndentedLinePattern.test(text)) {
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
getIndentMetadata(text) {
|
|
46
|
-
let ret = 0;
|
|
47
|
-
if (this.shouldIncrease(text)) {
|
|
48
|
-
ret += 1 /* IndentConsts.INCREASE_MASK */;
|
|
49
|
-
}
|
|
50
|
-
if (this.shouldDecrease(text)) {
|
|
51
|
-
ret += 2 /* IndentConsts.DECREASE_MASK */;
|
|
52
|
-
}
|
|
53
|
-
if (this.shouldIndentNextLine(text)) {
|
|
54
|
-
ret += 4 /* IndentConsts.INDENT_NEXTLINE_MASK */;
|
|
55
|
-
}
|
|
56
|
-
if (this.shouldIgnore(text)) {
|
|
57
|
-
ret += 8 /* IndentConsts.UNINDENT_MASK */;
|
|
58
|
-
}
|
|
59
|
-
return ret;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export { IndentRulesSupport };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { firstNonWhitespaceIndex } from '../../../../base/common/strings.js';
|
|
2
|
-
import { CursorColumns } from '../cursorColumns.js';
|
|
3
|
-
|
|
4
|
-
/*---------------------------------------------------------------------------------------------
|
|
5
|
-
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
6
|
-
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
7
|
-
*--------------------------------------------------------------------------------------------*/
|
|
8
|
-
function _normalizeIndentationFromWhitespace(str, indentSize, insertSpaces) {
|
|
9
|
-
let spacesCnt = 0;
|
|
10
|
-
for (let i = 0; i < str.length; i++) {
|
|
11
|
-
if (str.charAt(i) === '\t') {
|
|
12
|
-
spacesCnt = CursorColumns.nextIndentTabStop(spacesCnt, indentSize);
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
spacesCnt++;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
let result = '';
|
|
19
|
-
if (!insertSpaces) {
|
|
20
|
-
const tabsCnt = Math.floor(spacesCnt / indentSize);
|
|
21
|
-
spacesCnt = spacesCnt % indentSize;
|
|
22
|
-
for (let i = 0; i < tabsCnt; i++) {
|
|
23
|
-
result += '\t';
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
for (let i = 0; i < spacesCnt; i++) {
|
|
27
|
-
result += ' ';
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
function normalizeIndentation(str, indentSize, insertSpaces) {
|
|
32
|
-
let firstNonWhitespaceIndex$1 = firstNonWhitespaceIndex(str);
|
|
33
|
-
if (firstNonWhitespaceIndex$1 === -1) {
|
|
34
|
-
firstNonWhitespaceIndex$1 = str.length;
|
|
35
|
-
}
|
|
36
|
-
return _normalizeIndentationFromWhitespace(str.substring(0, firstNonWhitespaceIndex$1), indentSize, insertSpaces) + str.substring(firstNonWhitespaceIndex$1);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export { normalizeIndentation };
|
|
@@ -1,178 +0,0 @@
|
|
|
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 SpacesDiffResult {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.spacesDiff = 0;
|
|
8
|
-
this.looksLikeAlignment = false;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Compute the diff in spaces between two line's indentation.
|
|
13
|
-
*/
|
|
14
|
-
function spacesDiff(a, aLength, b, bLength, result) {
|
|
15
|
-
result.spacesDiff = 0;
|
|
16
|
-
result.looksLikeAlignment = false;
|
|
17
|
-
// This can go both ways (e.g.):
|
|
18
|
-
// - a: "\t"
|
|
19
|
-
// - b: "\t "
|
|
20
|
-
// => This should count 1 tab and 4 spaces
|
|
21
|
-
let i;
|
|
22
|
-
for (i = 0; i < aLength && i < bLength; i++) {
|
|
23
|
-
const aCharCode = a.charCodeAt(i);
|
|
24
|
-
const bCharCode = b.charCodeAt(i);
|
|
25
|
-
if (aCharCode !== bCharCode) {
|
|
26
|
-
break;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
let aSpacesCnt = 0, aTabsCount = 0;
|
|
30
|
-
for (let j = i; j < aLength; j++) {
|
|
31
|
-
const aCharCode = a.charCodeAt(j);
|
|
32
|
-
if (aCharCode === 32 /* CharCode.Space */) {
|
|
33
|
-
aSpacesCnt++;
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
aTabsCount++;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
let bSpacesCnt = 0, bTabsCount = 0;
|
|
40
|
-
for (let j = i; j < bLength; j++) {
|
|
41
|
-
const bCharCode = b.charCodeAt(j);
|
|
42
|
-
if (bCharCode === 32 /* CharCode.Space */) {
|
|
43
|
-
bSpacesCnt++;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
bTabsCount++;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
if (aSpacesCnt > 0 && aTabsCount > 0) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (bSpacesCnt > 0 && bTabsCount > 0) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const tabsDiff = Math.abs(aTabsCount - bTabsCount);
|
|
56
|
-
const spacesDiff = Math.abs(aSpacesCnt - bSpacesCnt);
|
|
57
|
-
if (tabsDiff === 0) {
|
|
58
|
-
// check if the indentation difference might be caused by alignment reasons
|
|
59
|
-
// sometime folks like to align their code, but this should not be used as a hint
|
|
60
|
-
result.spacesDiff = spacesDiff;
|
|
61
|
-
if (spacesDiff > 0 && 0 <= bSpacesCnt - 1 && bSpacesCnt - 1 < a.length && bSpacesCnt < b.length) {
|
|
62
|
-
if (b.charCodeAt(bSpacesCnt) !== 32 /* CharCode.Space */ && a.charCodeAt(bSpacesCnt - 1) === 32 /* CharCode.Space */) {
|
|
63
|
-
if (a.charCodeAt(a.length - 1) === 44 /* CharCode.Comma */) {
|
|
64
|
-
// This looks like an alignment desire: e.g.
|
|
65
|
-
// const a = b + c,
|
|
66
|
-
// d = b - c;
|
|
67
|
-
result.looksLikeAlignment = true;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (spacesDiff % tabsDiff === 0) {
|
|
74
|
-
result.spacesDiff = spacesDiff / tabsDiff;
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
function guessIndentation(source, defaultTabSize, defaultInsertSpaces) {
|
|
79
|
-
// Look at most at the first 10k lines
|
|
80
|
-
const linesCount = Math.min(source.getLineCount(), 10000);
|
|
81
|
-
let linesIndentedWithTabsCount = 0; // number of lines that contain at least one tab in indentation
|
|
82
|
-
let linesIndentedWithSpacesCount = 0; // number of lines that contain only spaces in indentation
|
|
83
|
-
let previousLineText = ''; // content of latest line that contained non-whitespace chars
|
|
84
|
-
let previousLineIndentation = 0; // index at which latest line contained the first non-whitespace char
|
|
85
|
-
const ALLOWED_TAB_SIZE_GUESSES = [2, 4, 6, 8, 3, 5, 7]; // prefer even guesses for `tabSize`, limit to [2, 8].
|
|
86
|
-
const MAX_ALLOWED_TAB_SIZE_GUESS = 8; // max(ALLOWED_TAB_SIZE_GUESSES) = 8
|
|
87
|
-
const spacesDiffCount = [0, 0, 0, 0, 0, 0, 0, 0, 0]; // `tabSize` scores
|
|
88
|
-
const tmp = new SpacesDiffResult();
|
|
89
|
-
for (let lineNumber = 1; lineNumber <= linesCount; lineNumber++) {
|
|
90
|
-
const currentLineLength = source.getLineLength(lineNumber);
|
|
91
|
-
const currentLineText = source.getLineContent(lineNumber);
|
|
92
|
-
// if the text buffer is chunk based, so long lines are cons-string, v8 will flattern the string when we check charCode.
|
|
93
|
-
// checking charCode on chunks directly is cheaper.
|
|
94
|
-
const useCurrentLineText = (currentLineLength <= 65536);
|
|
95
|
-
let currentLineHasContent = false; // does `currentLineText` contain non-whitespace chars
|
|
96
|
-
let currentLineIndentation = 0; // index at which `currentLineText` contains the first non-whitespace char
|
|
97
|
-
let currentLineSpacesCount = 0; // count of spaces found in `currentLineText` indentation
|
|
98
|
-
let currentLineTabsCount = 0; // count of tabs found in `currentLineText` indentation
|
|
99
|
-
for (let j = 0, lenJ = currentLineLength; j < lenJ; j++) {
|
|
100
|
-
const charCode = (useCurrentLineText ? currentLineText.charCodeAt(j) : source.getLineCharCode(lineNumber, j));
|
|
101
|
-
if (charCode === 9 /* CharCode.Tab */) {
|
|
102
|
-
currentLineTabsCount++;
|
|
103
|
-
}
|
|
104
|
-
else if (charCode === 32 /* CharCode.Space */) {
|
|
105
|
-
currentLineSpacesCount++;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
// Hit non whitespace character on this line
|
|
109
|
-
currentLineHasContent = true;
|
|
110
|
-
currentLineIndentation = j;
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// Ignore empty or only whitespace lines
|
|
115
|
-
if (!currentLineHasContent) {
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (currentLineTabsCount > 0) {
|
|
119
|
-
linesIndentedWithTabsCount++;
|
|
120
|
-
}
|
|
121
|
-
else if (currentLineSpacesCount > 1) {
|
|
122
|
-
linesIndentedWithSpacesCount++;
|
|
123
|
-
}
|
|
124
|
-
spacesDiff(previousLineText, previousLineIndentation, currentLineText, currentLineIndentation, tmp);
|
|
125
|
-
if (tmp.looksLikeAlignment) {
|
|
126
|
-
// if defaultInsertSpaces === true && the spaces count == tabSize, we may want to count it as valid indentation
|
|
127
|
-
//
|
|
128
|
-
// - item1
|
|
129
|
-
// - item2
|
|
130
|
-
//
|
|
131
|
-
// otherwise skip this line entirely
|
|
132
|
-
//
|
|
133
|
-
// const a = 1,
|
|
134
|
-
// b = 2;
|
|
135
|
-
if (!(defaultInsertSpaces && defaultTabSize === tmp.spacesDiff)) {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
const currentSpacesDiff = tmp.spacesDiff;
|
|
140
|
-
if (currentSpacesDiff <= MAX_ALLOWED_TAB_SIZE_GUESS) {
|
|
141
|
-
spacesDiffCount[currentSpacesDiff]++;
|
|
142
|
-
}
|
|
143
|
-
previousLineText = currentLineText;
|
|
144
|
-
previousLineIndentation = currentLineIndentation;
|
|
145
|
-
}
|
|
146
|
-
let insertSpaces = defaultInsertSpaces;
|
|
147
|
-
if (linesIndentedWithTabsCount !== linesIndentedWithSpacesCount) {
|
|
148
|
-
insertSpaces = (linesIndentedWithTabsCount < linesIndentedWithSpacesCount);
|
|
149
|
-
}
|
|
150
|
-
let tabSize = defaultTabSize;
|
|
151
|
-
// Guess tabSize only if inserting spaces...
|
|
152
|
-
if (insertSpaces) {
|
|
153
|
-
let tabSizeScore = (insertSpaces ? 0 : 0.1 * linesCount);
|
|
154
|
-
// console.log("score threshold: " + tabSizeScore);
|
|
155
|
-
ALLOWED_TAB_SIZE_GUESSES.forEach((possibleTabSize) => {
|
|
156
|
-
const possibleTabSizeScore = spacesDiffCount[possibleTabSize];
|
|
157
|
-
if (possibleTabSizeScore > tabSizeScore) {
|
|
158
|
-
tabSizeScore = possibleTabSizeScore;
|
|
159
|
-
tabSize = possibleTabSize;
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
// Let a tabSize of 2 win even if it is not the maximum
|
|
163
|
-
// (only in case 4 was guessed)
|
|
164
|
-
if (tabSize === 4 && spacesDiffCount[4] > 0 && spacesDiffCount[2] > 0 && spacesDiffCount[2] >= spacesDiffCount[4] / 2) {
|
|
165
|
-
tabSize = 2;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
// console.log('--------------------------');
|
|
169
|
-
// console.log('linesIndentedWithTabsCount: ' + linesIndentedWithTabsCount + ', linesIndentedWithSpacesCount: ' + linesIndentedWithSpacesCount);
|
|
170
|
-
// console.log('spacesDiffCount: ' + spacesDiffCount);
|
|
171
|
-
// console.log('tabSize: ' + tabSize + ', tabSizeScore: ' + tabSizeScore);
|
|
172
|
-
return {
|
|
173
|
-
insertSpaces: insertSpaces,
|
|
174
|
-
tabSize: tabSize
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
export { guessIndentation };
|