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,269 @@
|
|
|
1
|
+
import { compareBy } from '../../../../base/common/arrays.js';
|
|
2
|
+
import { assertFn, checkAdjacentItems } from '../../../../base/common/assert.js';
|
|
3
|
+
import { BugIndicatingError } from '../../../../base/common/errors.js';
|
|
4
|
+
import { commonPrefixLength, commonSuffixLength } from '../../../../base/common/strings.js';
|
|
5
|
+
import { Position } from '../position.js';
|
|
6
|
+
import { Range } from '../range.js';
|
|
7
|
+
import { TextLength } from '../text/textLength.js';
|
|
8
|
+
import { StringText } from '../text/abstractText.js';
|
|
9
|
+
|
|
10
|
+
/*---------------------------------------------------------------------------------------------
|
|
11
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
12
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
13
|
+
*--------------------------------------------------------------------------------------------*/
|
|
14
|
+
class TextEdit {
|
|
15
|
+
static fromStringEdit(edit, initialState) {
|
|
16
|
+
const edits = edit.replacements.map(e => TextReplacement.fromStringReplacement(e, initialState));
|
|
17
|
+
return new TextEdit(edits);
|
|
18
|
+
}
|
|
19
|
+
static fromParallelReplacementsUnsorted(replacements) {
|
|
20
|
+
const r = replacements.slice().sort(compareBy(i => i.range, Range.compareRangesUsingStarts));
|
|
21
|
+
return new TextEdit(r);
|
|
22
|
+
}
|
|
23
|
+
constructor(replacements) {
|
|
24
|
+
this.replacements = replacements;
|
|
25
|
+
assertFn(() => checkAdjacentItems(replacements, (a, b) => a.range.getEndPosition().isBeforeOrEqual(b.range.getStartPosition())));
|
|
26
|
+
}
|
|
27
|
+
mapPosition(position) {
|
|
28
|
+
let lineDelta = 0;
|
|
29
|
+
let curLine = 0;
|
|
30
|
+
let columnDeltaInCurLine = 0;
|
|
31
|
+
for (const replacement of this.replacements) {
|
|
32
|
+
const start = replacement.range.getStartPosition();
|
|
33
|
+
if (position.isBeforeOrEqual(start)) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
const end = replacement.range.getEndPosition();
|
|
37
|
+
const len = TextLength.ofText(replacement.text);
|
|
38
|
+
if (position.isBefore(end)) {
|
|
39
|
+
const startPos = new Position(start.lineNumber + lineDelta, start.column + (start.lineNumber + lineDelta === curLine ? columnDeltaInCurLine : 0));
|
|
40
|
+
const endPos = len.addToPosition(startPos);
|
|
41
|
+
return rangeFromPositions(startPos, endPos);
|
|
42
|
+
}
|
|
43
|
+
if (start.lineNumber + lineDelta !== curLine) {
|
|
44
|
+
columnDeltaInCurLine = 0;
|
|
45
|
+
}
|
|
46
|
+
lineDelta += len.lineCount - (replacement.range.endLineNumber - replacement.range.startLineNumber);
|
|
47
|
+
if (len.lineCount === 0) {
|
|
48
|
+
if (end.lineNumber !== start.lineNumber) {
|
|
49
|
+
columnDeltaInCurLine += len.columnCount - (end.column - 1);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
columnDeltaInCurLine += len.columnCount - (end.column - start.column);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
columnDeltaInCurLine = len.columnCount;
|
|
57
|
+
}
|
|
58
|
+
curLine = end.lineNumber + lineDelta;
|
|
59
|
+
}
|
|
60
|
+
return new Position(position.lineNumber + lineDelta, position.column + (position.lineNumber + lineDelta === curLine ? columnDeltaInCurLine : 0));
|
|
61
|
+
}
|
|
62
|
+
mapRange(range) {
|
|
63
|
+
function getStart(p) {
|
|
64
|
+
return p instanceof Position ? p : p.getStartPosition();
|
|
65
|
+
}
|
|
66
|
+
function getEnd(p) {
|
|
67
|
+
return p instanceof Position ? p : p.getEndPosition();
|
|
68
|
+
}
|
|
69
|
+
const start = getStart(this.mapPosition(range.getStartPosition()));
|
|
70
|
+
const end = getEnd(this.mapPosition(range.getEndPosition()));
|
|
71
|
+
return rangeFromPositions(start, end);
|
|
72
|
+
}
|
|
73
|
+
apply(text) {
|
|
74
|
+
let result = '';
|
|
75
|
+
let lastEditEnd = new Position(1, 1);
|
|
76
|
+
for (const replacement of this.replacements) {
|
|
77
|
+
const editRange = replacement.range;
|
|
78
|
+
const editStart = editRange.getStartPosition();
|
|
79
|
+
const editEnd = editRange.getEndPosition();
|
|
80
|
+
const r = rangeFromPositions(lastEditEnd, editStart);
|
|
81
|
+
if (!r.isEmpty()) {
|
|
82
|
+
result += text.getValueOfRange(r);
|
|
83
|
+
}
|
|
84
|
+
result += replacement.text;
|
|
85
|
+
lastEditEnd = editEnd;
|
|
86
|
+
}
|
|
87
|
+
const r = rangeFromPositions(lastEditEnd, text.endPositionExclusive);
|
|
88
|
+
if (!r.isEmpty()) {
|
|
89
|
+
result += text.getValueOfRange(r);
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
applyToString(str) {
|
|
94
|
+
const strText = new StringText(str);
|
|
95
|
+
return this.apply(strText);
|
|
96
|
+
}
|
|
97
|
+
getNewRanges() {
|
|
98
|
+
const newRanges = [];
|
|
99
|
+
let previousEditEndLineNumber = 0;
|
|
100
|
+
let lineOffset = 0;
|
|
101
|
+
let columnOffset = 0;
|
|
102
|
+
for (const replacement of this.replacements) {
|
|
103
|
+
const textLength = TextLength.ofText(replacement.text);
|
|
104
|
+
const newRangeStart = Position.lift({
|
|
105
|
+
lineNumber: replacement.range.startLineNumber + lineOffset,
|
|
106
|
+
column: replacement.range.startColumn + (replacement.range.startLineNumber === previousEditEndLineNumber ? columnOffset : 0)
|
|
107
|
+
});
|
|
108
|
+
const newRange = textLength.createRange(newRangeStart);
|
|
109
|
+
newRanges.push(newRange);
|
|
110
|
+
lineOffset = newRange.endLineNumber - replacement.range.endLineNumber;
|
|
111
|
+
columnOffset = newRange.endColumn - replacement.range.endColumn;
|
|
112
|
+
previousEditEndLineNumber = replacement.range.endLineNumber;
|
|
113
|
+
}
|
|
114
|
+
return newRanges;
|
|
115
|
+
}
|
|
116
|
+
toReplacement(text) {
|
|
117
|
+
if (this.replacements.length === 0) {
|
|
118
|
+
throw new BugIndicatingError();
|
|
119
|
+
}
|
|
120
|
+
if (this.replacements.length === 1) {
|
|
121
|
+
return this.replacements[0];
|
|
122
|
+
}
|
|
123
|
+
const startPos = this.replacements[0].range.getStartPosition();
|
|
124
|
+
const endPos = this.replacements[this.replacements.length - 1].range.getEndPosition();
|
|
125
|
+
let newText = '';
|
|
126
|
+
for (let i = 0; i < this.replacements.length; i++) {
|
|
127
|
+
const curEdit = this.replacements[i];
|
|
128
|
+
newText += curEdit.text;
|
|
129
|
+
if (i < this.replacements.length - 1) {
|
|
130
|
+
const nextEdit = this.replacements[i + 1];
|
|
131
|
+
const gapRange = Range.fromPositions(curEdit.range.getEndPosition(), nextEdit.range.getStartPosition());
|
|
132
|
+
const gapText = text.getValueOfRange(gapRange);
|
|
133
|
+
newText += gapText;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return new TextReplacement(Range.fromPositions(startPos, endPos), newText);
|
|
137
|
+
}
|
|
138
|
+
toString(text) {
|
|
139
|
+
if (text === undefined) {
|
|
140
|
+
return this.replacements.map(edit => edit.toString()).join('\n');
|
|
141
|
+
}
|
|
142
|
+
if (typeof text === 'string') {
|
|
143
|
+
return this.toString(new StringText(text));
|
|
144
|
+
}
|
|
145
|
+
if (this.replacements.length === 0) {
|
|
146
|
+
return '';
|
|
147
|
+
}
|
|
148
|
+
return this.replacements.map(r => {
|
|
149
|
+
const maxLength = 10;
|
|
150
|
+
const originalText = text.getValueOfRange(r.range);
|
|
151
|
+
// Get text before the edit
|
|
152
|
+
const beforeRange = Range.fromPositions(new Position(Math.max(1, r.range.startLineNumber - 1), 1), r.range.getStartPosition());
|
|
153
|
+
let beforeText = text.getValueOfRange(beforeRange);
|
|
154
|
+
if (beforeText.length > maxLength) {
|
|
155
|
+
beforeText = '...' + beforeText.substring(beforeText.length - maxLength);
|
|
156
|
+
}
|
|
157
|
+
// Get text after the edit
|
|
158
|
+
const afterRange = Range.fromPositions(r.range.getEndPosition(), new Position(r.range.endLineNumber + 1, 1));
|
|
159
|
+
let afterText = text.getValueOfRange(afterRange);
|
|
160
|
+
if (afterText.length > maxLength) {
|
|
161
|
+
afterText = afterText.substring(0, maxLength) + '...';
|
|
162
|
+
}
|
|
163
|
+
// Format the replaced text
|
|
164
|
+
let replacedText = originalText;
|
|
165
|
+
if (replacedText.length > maxLength) {
|
|
166
|
+
const halfMax = Math.floor(maxLength / 2);
|
|
167
|
+
replacedText = replacedText.substring(0, halfMax) + '...' +
|
|
168
|
+
replacedText.substring(replacedText.length - halfMax);
|
|
169
|
+
}
|
|
170
|
+
// Format the new text
|
|
171
|
+
let newText = r.text;
|
|
172
|
+
if (newText.length > maxLength) {
|
|
173
|
+
const halfMax = Math.floor(maxLength / 2);
|
|
174
|
+
newText = newText.substring(0, halfMax) + '...' +
|
|
175
|
+
newText.substring(newText.length - halfMax);
|
|
176
|
+
}
|
|
177
|
+
if (replacedText.length === 0) {
|
|
178
|
+
// allow-any-unicode-next-line
|
|
179
|
+
return `${beforeText}❰${newText}❱${afterText}`;
|
|
180
|
+
}
|
|
181
|
+
// allow-any-unicode-next-line
|
|
182
|
+
return `${beforeText}❰${replacedText}↦${newText}❱${afterText}`;
|
|
183
|
+
}).join('\n');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
class TextReplacement {
|
|
187
|
+
static joinReplacements(replacements, initialValue) {
|
|
188
|
+
if (replacements.length === 0) {
|
|
189
|
+
throw new BugIndicatingError();
|
|
190
|
+
}
|
|
191
|
+
if (replacements.length === 1) {
|
|
192
|
+
return replacements[0];
|
|
193
|
+
}
|
|
194
|
+
const startPos = replacements[0].range.getStartPosition();
|
|
195
|
+
const endPos = replacements[replacements.length - 1].range.getEndPosition();
|
|
196
|
+
let newText = '';
|
|
197
|
+
for (let i = 0; i < replacements.length; i++) {
|
|
198
|
+
const curEdit = replacements[i];
|
|
199
|
+
newText += curEdit.text;
|
|
200
|
+
if (i < replacements.length - 1) {
|
|
201
|
+
const nextEdit = replacements[i + 1];
|
|
202
|
+
const gapRange = Range.fromPositions(curEdit.range.getEndPosition(), nextEdit.range.getStartPosition());
|
|
203
|
+
const gapText = initialValue.getValueOfRange(gapRange);
|
|
204
|
+
newText += gapText;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return new TextReplacement(Range.fromPositions(startPos, endPos), newText);
|
|
208
|
+
}
|
|
209
|
+
static fromStringReplacement(replacement, initialState) {
|
|
210
|
+
return new TextReplacement(initialState.getTransformer().getRange(replacement.replaceRange), replacement.newText);
|
|
211
|
+
}
|
|
212
|
+
static delete(range) {
|
|
213
|
+
return new TextReplacement(range, '');
|
|
214
|
+
}
|
|
215
|
+
constructor(range, text) {
|
|
216
|
+
this.range = range;
|
|
217
|
+
this.text = text;
|
|
218
|
+
}
|
|
219
|
+
get isEmpty() {
|
|
220
|
+
return this.range.isEmpty() && this.text.length === 0;
|
|
221
|
+
}
|
|
222
|
+
static equals(first, second) {
|
|
223
|
+
return first.range.equalsRange(second.range) && first.text === second.text;
|
|
224
|
+
}
|
|
225
|
+
equals(other) {
|
|
226
|
+
return TextReplacement.equals(this, other);
|
|
227
|
+
}
|
|
228
|
+
removeCommonPrefixAndSuffix(text) {
|
|
229
|
+
const prefix = this.removeCommonPrefix(text);
|
|
230
|
+
const suffix = prefix.removeCommonSuffix(text);
|
|
231
|
+
return suffix;
|
|
232
|
+
}
|
|
233
|
+
removeCommonPrefix(text) {
|
|
234
|
+
const normalizedOriginalText = text.getValueOfRange(this.range).replaceAll('\r\n', '\n');
|
|
235
|
+
const normalizedModifiedText = this.text.replaceAll('\r\n', '\n');
|
|
236
|
+
const commonPrefixLen = commonPrefixLength(normalizedOriginalText, normalizedModifiedText);
|
|
237
|
+
const start = TextLength.ofText(normalizedOriginalText.substring(0, commonPrefixLen))
|
|
238
|
+
.addToPosition(this.range.getStartPosition());
|
|
239
|
+
const newText = normalizedModifiedText.substring(commonPrefixLen);
|
|
240
|
+
const range = Range.fromPositions(start, this.range.getEndPosition());
|
|
241
|
+
return new TextReplacement(range, newText);
|
|
242
|
+
}
|
|
243
|
+
removeCommonSuffix(text) {
|
|
244
|
+
const normalizedOriginalText = text.getValueOfRange(this.range).replaceAll('\r\n', '\n');
|
|
245
|
+
const normalizedModifiedText = this.text.replaceAll('\r\n', '\n');
|
|
246
|
+
const commonSuffixLen = commonSuffixLength(normalizedOriginalText, normalizedModifiedText);
|
|
247
|
+
const end = TextLength.ofText(normalizedOriginalText.substring(0, normalizedOriginalText.length - commonSuffixLen))
|
|
248
|
+
.addToPosition(this.range.getStartPosition());
|
|
249
|
+
const newText = normalizedModifiedText.substring(0, normalizedModifiedText.length - commonSuffixLen);
|
|
250
|
+
const range = Range.fromPositions(this.range.getStartPosition(), end);
|
|
251
|
+
return new TextReplacement(range, newText);
|
|
252
|
+
}
|
|
253
|
+
toString() {
|
|
254
|
+
const start = this.range.getStartPosition();
|
|
255
|
+
const end = this.range.getEndPosition();
|
|
256
|
+
return `(${start.lineNumber},${start.column} -> ${end.lineNumber},${end.column}): "${this.text}"`;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function rangeFromPositions(start, end) {
|
|
260
|
+
if (start.lineNumber === end.lineNumber && start.column === Number.MAX_SAFE_INTEGER) {
|
|
261
|
+
return Range.fromPositions(end, end);
|
|
262
|
+
}
|
|
263
|
+
else if (!start.isBeforeOrEqual(end)) {
|
|
264
|
+
throw new BugIndicatingError('start must be before end');
|
|
265
|
+
}
|
|
266
|
+
return new Range(start.lineNumber, start.column, end.lineNumber, end.column);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { TextEdit, TextReplacement };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { LineRange } from '../ranges/lineRange.js';
|
|
2
|
+
import { Position } from '../position.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 non-negative length of text in terms of line and column count.
|
|
11
|
+
*/
|
|
12
|
+
class TextLength {
|
|
13
|
+
static { this.zero = new TextLength(0, 0); }
|
|
14
|
+
static betweenPositions(position1, position2) {
|
|
15
|
+
if (position1.lineNumber === position2.lineNumber) {
|
|
16
|
+
return new TextLength(0, position2.column - position1.column);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
return new TextLength(position2.lineNumber - position1.lineNumber, position2.column - 1);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
static fromPosition(pos) {
|
|
23
|
+
return new TextLength(pos.lineNumber - 1, pos.column - 1);
|
|
24
|
+
}
|
|
25
|
+
static ofRange(range) {
|
|
26
|
+
return TextLength.betweenPositions(range.getStartPosition(), range.getEndPosition());
|
|
27
|
+
}
|
|
28
|
+
static ofText(text) {
|
|
29
|
+
let line = 0;
|
|
30
|
+
let column = 0;
|
|
31
|
+
for (const c of text) {
|
|
32
|
+
if (c === '\n') {
|
|
33
|
+
line++;
|
|
34
|
+
column = 0;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
column++;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return new TextLength(line, column);
|
|
41
|
+
}
|
|
42
|
+
constructor(lineCount, columnCount) {
|
|
43
|
+
this.lineCount = lineCount;
|
|
44
|
+
this.columnCount = columnCount;
|
|
45
|
+
}
|
|
46
|
+
isGreaterThanOrEqualTo(other) {
|
|
47
|
+
if (this.lineCount !== other.lineCount) {
|
|
48
|
+
return this.lineCount > other.lineCount;
|
|
49
|
+
}
|
|
50
|
+
return this.columnCount >= other.columnCount;
|
|
51
|
+
}
|
|
52
|
+
add(other) {
|
|
53
|
+
if (other.lineCount === 0) {
|
|
54
|
+
return new TextLength(this.lineCount, this.columnCount + other.columnCount);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return new TextLength(this.lineCount + other.lineCount, other.columnCount);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
createRange(startPosition) {
|
|
61
|
+
if (this.lineCount === 0) {
|
|
62
|
+
return new Range(startPosition.lineNumber, startPosition.column, startPosition.lineNumber, startPosition.column + this.columnCount);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return new Range(startPosition.lineNumber, startPosition.column, startPosition.lineNumber + this.lineCount, this.columnCount + 1);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
toRange() {
|
|
69
|
+
return new Range(1, 1, this.lineCount + 1, this.columnCount + 1);
|
|
70
|
+
}
|
|
71
|
+
toLineRange() {
|
|
72
|
+
return LineRange.ofLength(1, this.lineCount + 1);
|
|
73
|
+
}
|
|
74
|
+
addToPosition(position) {
|
|
75
|
+
if (this.lineCount === 0) {
|
|
76
|
+
return new Position(position.lineNumber, position.column + this.columnCount);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return new Position(position.lineNumber + this.lineCount, this.columnCount + 1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
toString() {
|
|
83
|
+
return `${this.lineCount},${this.columnCount}`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { TextLength };
|