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.
Files changed (232) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/monaco-editor11.es.js +11 -16
  3. package/dist/monaco-editor11.umd.js +1 -1
  4. package/package.json +2 -2
  5. package/dist/monaco.d.ts +0 -8
  6. package/dist/workers/common/initialize.js +0 -16
  7. package/dist/workers/common/workers.js +0 -141
  8. package/dist/workers/editor/common/abstractSyntaxTokenBackend.js +0 -128
  9. package/dist/workers/editor/common/abstractText.js +0 -89
  10. package/dist/workers/editor/common/ast.js +0 -485
  11. package/dist/workers/editor/common/autoIndent.js +0 -390
  12. package/dist/workers/editor/common/beforeEditPositionMapper.js +0 -110
  13. package/dist/workers/editor/common/bracketPairsImpl.js +0 -717
  14. package/dist/workers/editor/common/bracketPairsTree.js +0 -343
  15. package/dist/workers/editor/common/brackets.js +0 -108
  16. package/dist/workers/editor/common/characterClassifier.js +0 -59
  17. package/dist/workers/editor/common/characterPair.js +0 -40
  18. package/dist/workers/editor/common/colorizedBracketPairsDecorationProvider.js +0 -97
  19. package/dist/workers/editor/common/columnRange.js +0 -35
  20. package/dist/workers/editor/common/combineTextEditInfos.js +0 -124
  21. package/dist/workers/editor/common/common.js +0 -20
  22. package/dist/workers/editor/common/computeMovedLines.js +0 -249
  23. package/dist/workers/editor/common/concat23Trees.js +0 -192
  24. package/dist/workers/editor/common/contiguousMultilineTokens.js +0 -32
  25. package/dist/workers/editor/common/contiguousMultilineTokensBuilder.js +0 -23
  26. package/dist/workers/editor/common/contiguousTokensEditing.js +0 -128
  27. package/dist/workers/editor/common/contiguousTokensStore.js +0 -207
  28. package/dist/workers/editor/common/coordinatesConverter.js +0 -51
  29. package/dist/workers/editor/common/cursor.js +0 -899
  30. package/dist/workers/editor/common/cursorAtomicMoveOperations.js +0 -145
  31. package/dist/workers/editor/common/cursorCollection.js +0 -194
  32. package/dist/workers/editor/common/cursorColumnSelection.js +0 -93
  33. package/dist/workers/editor/common/cursorColumns.js +0 -112
  34. package/dist/workers/editor/common/cursorCommon.js +0 -250
  35. package/dist/workers/editor/common/cursorContext.js +0 -15
  36. package/dist/workers/editor/common/cursorDeleteOperations.js +0 -231
  37. package/dist/workers/editor/common/cursorMoveCommands.js +0 -676
  38. package/dist/workers/editor/common/cursorMoveOperations.js +0 -290
  39. package/dist/workers/editor/common/cursorTypeEditOperations.js +0 -968
  40. package/dist/workers/editor/common/cursorTypeOperations.js +0 -173
  41. package/dist/workers/editor/common/cursorUtils.js +0 -75
  42. package/dist/workers/editor/common/cursorWordOperations.js +0 -720
  43. package/dist/workers/editor/common/defaultDocumentColorsComputer.js +0 -138
  44. package/dist/workers/editor/common/defaultLinesDiffComputer.js +0 -188
  45. package/dist/workers/editor/common/diffAlgorithm.js +0 -139
  46. package/dist/workers/editor/common/diffEditor.js +0 -38
  47. package/dist/workers/editor/common/dynamicProgrammingDiffing.js +0 -101
  48. package/dist/workers/editor/common/edit.js +0 -183
  49. package/dist/workers/editor/common/editOperation.js +0 -36
  50. package/dist/workers/editor/common/editStack.js +0 -363
  51. package/dist/workers/editor/common/editorAction.js +0 -26
  52. package/dist/workers/editor/common/editorBaseApi.js +0 -43
  53. package/dist/workers/editor/common/editorColorRegistry.js +0 -102
  54. package/dist/workers/editor/common/editorCommon.js +0 -13
  55. package/dist/workers/editor/common/editorConfigurationSchema.js +0 -338
  56. package/dist/workers/editor/common/editorContextKeys.js +0 -84
  57. package/dist/workers/editor/common/editorFeatures.js +0 -17
  58. package/dist/workers/editor/common/editorOptions.js +0 -3440
  59. package/dist/workers/editor/common/editorTheme.js +0 -23
  60. package/dist/workers/editor/common/editorWebWorker.js +0 -299
  61. package/dist/workers/editor/common/editorWorker.js +0 -9
  62. package/dist/workers/editor/common/editorWorkerHost.js +0 -15
  63. package/dist/workers/editor/common/editorZoom.js +0 -26
  64. package/dist/workers/editor/common/electricCharacter.js +0 -55
  65. package/dist/workers/editor/common/encodedTokenAttributes.js +0 -79
  66. package/dist/workers/editor/common/enterAction.js +0 -53
  67. package/dist/workers/editor/common/eolCounter.js +0 -44
  68. package/dist/workers/editor/common/findSectionHeaders.js +0 -128
  69. package/dist/workers/editor/common/fixBrackets.js +0 -67
  70. package/dist/workers/editor/common/fixedArray.js +0 -70
  71. package/dist/workers/editor/common/fontInfo.js +0 -172
  72. package/dist/workers/editor/common/fontInfoFromSettings.js +0 -29
  73. package/dist/workers/editor/common/getIconClasses.js +0 -106
  74. package/dist/workers/editor/common/getPositionOffsetTransformerFromTextModel.js +0 -24
  75. package/dist/workers/editor/common/glyphLanesModel.js +0 -61
  76. package/dist/workers/editor/common/guidesTextModelPart.js +0 -405
  77. package/dist/workers/editor/common/heuristicSequenceOptimizations.js +0 -374
  78. package/dist/workers/editor/common/indentRules.js +0 -63
  79. package/dist/workers/editor/common/indentation.js +0 -39
  80. package/dist/workers/editor/common/indentationGuesser.js +0 -178
  81. package/dist/workers/editor/common/indentationLineProcessor.js +0 -193
  82. package/dist/workers/editor/common/inlineDecorations.js +0 -26
  83. package/dist/workers/editor/common/inplaceReplaceSupport.js +0 -87
  84. package/dist/workers/editor/common/inputMode.js +0 -22
  85. package/dist/workers/editor/common/intervalTree.js +0 -1002
  86. package/dist/workers/editor/common/language.js +0 -9
  87. package/dist/workers/editor/common/languageBracketsConfiguration.js +0 -133
  88. package/dist/workers/editor/common/languageConfiguration.js +0 -138
  89. package/dist/workers/editor/common/languageConfigurationRegistry.js +0 -361
  90. package/dist/workers/editor/common/languageFeatureDebounce.js +0 -137
  91. package/dist/workers/editor/common/languageFeatureRegistry.js +0 -180
  92. package/dist/workers/editor/common/languageFeatures.js +0 -9
  93. package/dist/workers/editor/common/languageFeaturesService.js +0 -47
  94. package/dist/workers/editor/common/languageSelector.js +0 -112
  95. package/dist/workers/editor/common/languageService.js +0 -92
  96. package/dist/workers/editor/common/languages.js +0 -522
  97. package/dist/workers/editor/common/languagesAssociations.js +0 -193
  98. package/dist/workers/editor/common/languagesRegistry.js +0 -237
  99. package/dist/workers/editor/common/legacyLinesDiffComputer.js +0 -468
  100. package/dist/workers/editor/common/length.js +0 -129
  101. package/dist/workers/editor/common/lineDecorations.js +0 -208
  102. package/dist/workers/editor/common/lineEdit.js +0 -75
  103. package/dist/workers/editor/common/lineHeights.js +0 -370
  104. package/dist/workers/editor/common/linePart.js +0 -25
  105. package/dist/workers/editor/common/lineRange.js +0 -312
  106. package/dist/workers/editor/common/lineSequence.js +0 -36
  107. package/dist/workers/editor/common/lineTokens.js +0 -405
  108. package/dist/workers/editor/common/linesDiffComputer.js +0 -29
  109. package/dist/workers/editor/common/linesDiffComputers.js +0 -13
  110. package/dist/workers/editor/common/linesLayout.js +0 -765
  111. package/dist/workers/editor/common/linesSliceCharSequence.js +0 -205
  112. package/dist/workers/editor/common/linkComputer.js +0 -269
  113. package/dist/workers/editor/common/markerDecorations.js +0 -9
  114. package/dist/workers/editor/common/markerDecorationsService.js +0 -248
  115. package/dist/workers/editor/common/minimapTokensColorTracker.js +0 -58
  116. package/dist/workers/editor/common/mirrorTextModel.js +0 -117
  117. package/dist/workers/editor/common/model.js +0 -9
  118. package/dist/workers/editor/common/modelLineProjection.js +0 -350
  119. package/dist/workers/editor/common/modelLineProjectionData.js +0 -297
  120. package/dist/workers/editor/common/modelService.js +0 -413
  121. package/dist/workers/editor/common/modesRegistry.js +0 -75
  122. package/dist/workers/editor/common/monospaceLineBreaksComputer.js +0 -473
  123. package/dist/workers/editor/common/myersDiffAlgorithm.js +0 -159
  124. package/dist/workers/editor/common/nodeReader.js +0 -127
  125. package/dist/workers/editor/common/nullTokenize.js +0 -29
  126. package/dist/workers/editor/common/offsetRange.js +0 -225
  127. package/dist/workers/editor/common/onEnter.js +0 -109
  128. package/dist/workers/editor/common/oneCursor.js +0 -117
  129. package/dist/workers/editor/common/overviewZoneManager.js +0 -176
  130. package/dist/workers/editor/common/parser.js +0 -121
  131. package/dist/workers/editor/common/pieceTreeBase.js +0 -1473
  132. package/dist/workers/editor/common/pieceTreeTextBuffer.js +0 -461
  133. package/dist/workers/editor/common/pieceTreeTextBufferBuilder.js +0 -140
  134. package/dist/workers/editor/common/point.js +0 -50
  135. package/dist/workers/editor/common/position.js +0 -142
  136. package/dist/workers/editor/common/positionToOffset.js +0 -17
  137. package/dist/workers/editor/common/positionToOffsetImpl.js +0 -98
  138. package/dist/workers/editor/common/prefixSumComputer.js +0 -226
  139. package/dist/workers/editor/common/range.js +0 -421
  140. package/dist/workers/editor/common/rangeMapping.js +0 -229
  141. package/dist/workers/editor/common/rangeSingleLine.js +0 -17
  142. package/dist/workers/editor/common/rbTreeBase.js +0 -362
  143. package/dist/workers/editor/common/rect.js +0 -163
  144. package/dist/workers/editor/common/replaceCommand.js +0 -158
  145. package/dist/workers/editor/common/resolverService.js +0 -5
  146. package/dist/workers/editor/common/rgba.js +0 -35
  147. package/dist/workers/editor/common/richEditBrackets.js +0 -356
  148. package/dist/workers/editor/common/selection.js +0 -145
  149. package/dist/workers/editor/common/semanticTokensDto.js +0 -82
  150. package/dist/workers/editor/common/semanticTokensProviderStyling.js +0 -263
  151. package/dist/workers/editor/common/semanticTokensStyling.js +0 -9
  152. package/dist/workers/editor/common/semanticTokensStylingService.js +0 -47
  153. package/dist/workers/editor/common/shiftCommand.js +0 -241
  154. package/dist/workers/editor/common/smallImmutableSet.js +0 -108
  155. package/dist/workers/editor/common/sparseMultilineTokens.js +0 -548
  156. package/dist/workers/editor/common/sparseTokensStore.js +0 -210
  157. package/dist/workers/editor/common/standaloneEnums.js +0 -1017
  158. package/dist/workers/editor/common/standaloneStrings.js +0 -42
  159. package/dist/workers/editor/common/stringBuilder.js +0 -122
  160. package/dist/workers/editor/common/stringEdit.js +0 -165
  161. package/dist/workers/editor/common/supports.js +0 -58
  162. package/dist/workers/editor/common/surroundSelectionCommand.js +0 -44
  163. package/dist/workers/editor/common/textChange.js +0 -248
  164. package/dist/workers/editor/common/textEdit.js +0 -269
  165. package/dist/workers/editor/common/textLength.js +0 -87
  166. package/dist/workers/editor/common/textModel.js +0 -2031
  167. package/dist/workers/editor/common/textModelBracketPairs.js +0 -45
  168. package/dist/workers/editor/common/textModelDefaults.js +0 -18
  169. package/dist/workers/editor/common/textModelEditSource.js +0 -166
  170. package/dist/workers/editor/common/textModelEvents.js +0 -216
  171. package/dist/workers/editor/common/textModelGuides.js +0 -40
  172. package/dist/workers/editor/common/textModelPart.js +0 -23
  173. package/dist/workers/editor/common/textModelSearch.js +0 -455
  174. package/dist/workers/editor/common/textModelStringEdit.js +0 -11
  175. package/dist/workers/editor/common/textModelSync.impl.js +0 -307
  176. package/dist/workers/editor/common/textModelText.js +0 -26
  177. package/dist/workers/editor/common/textModelTokens.js +0 -436
  178. package/dist/workers/editor/common/textResourceConfiguration.js +0 -6
  179. package/dist/workers/editor/common/textToHtmlTokenizer.js +0 -139
  180. package/dist/workers/editor/common/tokenStore.js +0 -407
  181. package/dist/workers/editor/common/tokenWithTextArray.js +0 -73
  182. package/dist/workers/editor/common/tokenization.js +0 -287
  183. package/dist/workers/editor/common/tokenizationRegistry.js +0 -123
  184. package/dist/workers/editor/common/tokenizationTextModelPart.js +0 -275
  185. package/dist/workers/editor/common/tokenizer.js +0 -301
  186. package/dist/workers/editor/common/tokenizerSyntaxTokenBackend.js +0 -261
  187. package/dist/workers/editor/common/treeSitterLibraryService.js +0 -9
  188. package/dist/workers/editor/common/treeSitterSyntaxTokenBackend.js +0 -167
  189. package/dist/workers/editor/common/treeSitterThemeService.js +0 -9
  190. package/dist/workers/editor/common/treeSitterTokenizationImpl.js +0 -713
  191. package/dist/workers/editor/common/treeSitterTree.js +0 -395
  192. package/dist/workers/editor/common/treeViewsDnd.js +0 -24
  193. package/dist/workers/editor/common/treeViewsDndService.js +0 -12
  194. package/dist/workers/editor/common/trimTrailingWhitespaceCommand.js +0 -98
  195. package/dist/workers/editor/common/unicodeTextModelHighlighter.js +0 -188
  196. package/dist/workers/editor/common/utils.js +0 -62
  197. package/dist/workers/editor/common/viewContext.js +0 -22
  198. package/dist/workers/editor/common/viewEventHandler.js +0 -186
  199. package/dist/workers/editor/common/viewEvents.js +0 -180
  200. package/dist/workers/editor/common/viewLayout.js +0 -368
  201. package/dist/workers/editor/common/viewLineRenderer.js +0 -948
  202. package/dist/workers/editor/common/viewLinesViewportData.js +0 -30
  203. package/dist/workers/editor/common/viewModel.js +0 -98
  204. package/dist/workers/editor/common/viewModelDecoration.js +0 -55
  205. package/dist/workers/editor/common/viewModelDecorations.js +0 -132
  206. package/dist/workers/editor/common/viewModelEventDispatcher.js +0 -398
  207. package/dist/workers/editor/common/viewModelImpl.js +0 -1163
  208. package/dist/workers/editor/common/viewModelLines.js +0 -938
  209. package/dist/workers/editor/common/wordCharacterClassifier.js +0 -87
  210. package/dist/workers/editor/common/wordHelper.js +0 -127
  211. package/dist/workers/language/cssMode.js +0 -198
  212. package/dist/workers/language/cssWorker.js +0 -183
  213. package/dist/workers/language/htmlMode.js +0 -213
  214. package/dist/workers/language/htmlWorker.js +0 -126
  215. package/dist/workers/language/jsonMode.js +0 -224
  216. package/dist/workers/language/jsonWorker.js +0 -187
  217. package/dist/workers/language/languageFeatures.js +0 -1009
  218. package/dist/workers/language/lib.index.js +0 -103
  219. package/dist/workers/language/lib.js +0 -1107
  220. package/dist/workers/language/lspLanguageFeatures.js +0 -716
  221. package/dist/workers/language/monaco.contribution.js +0 -144
  222. package/dist/workers/language/tokenization.js +0 -189
  223. package/dist/workers/language/tsMode.js +0 -212
  224. package/dist/workers/language/tsWorker.js +0 -352
  225. package/dist/workers/language/typescriptServices.js +0 -210154
  226. package/dist/workers/language/typescriptServicesMetadata.js +0 -3
  227. package/dist/workers/language/workerManager.js +0 -65
  228. /package/dist/workers/{language/css.worker.js → css.worker.js} +0 -0
  229. /package/dist/workers/{editor/editor.worker.js → editor.worker.js} +0 -0
  230. /package/dist/workers/{language/html.worker.js → html.worker.js} +0 -0
  231. /package/dist/workers/{language/json.worker.js → json.worker.js} +0 -0
  232. /package/dist/workers/{language/ts.worker.js → ts.worker.js} +0 -0
@@ -1,468 +0,0 @@
1
- import { LcsDiff } from '../../../base/common/diff/diff.js';
2
- import { LinesDiff } from './linesDiffComputer.js';
3
- import { DetailedLineRangeMapping, RangeMapping } from './rangeMapping.js';
4
- import { firstNonWhitespaceIndex, lastNonWhitespaceIndex } from '../../../base/common/strings.js';
5
- import { Range } from '../core/range.js';
6
- import { assertFn, checkAdjacentItems } from '../../../base/common/assert.js';
7
- import { LineRange } from '../core/ranges/lineRange.js';
8
-
9
- /*---------------------------------------------------------------------------------------------
10
- * Copyright (c) Microsoft Corporation. All rights reserved.
11
- * Licensed under the MIT License. See License.txt in the project root for license information.
12
- *--------------------------------------------------------------------------------------------*/
13
- const MINIMUM_MATCHING_CHARACTER_LENGTH = 3;
14
- class LegacyLinesDiffComputer {
15
- computeDiff(originalLines, modifiedLines, options) {
16
- const diffComputer = new DiffComputer(originalLines, modifiedLines, {
17
- maxComputationTime: options.maxComputationTimeMs,
18
- shouldIgnoreTrimWhitespace: options.ignoreTrimWhitespace,
19
- shouldComputeCharChanges: true,
20
- shouldMakePrettyDiff: true,
21
- shouldPostProcessCharChanges: true,
22
- });
23
- const result = diffComputer.computeDiff();
24
- const changes = [];
25
- let lastChange = null;
26
- for (const c of result.changes) {
27
- let originalRange;
28
- if (c.originalEndLineNumber === 0) {
29
- // Insertion
30
- originalRange = new LineRange(c.originalStartLineNumber + 1, c.originalStartLineNumber + 1);
31
- }
32
- else {
33
- originalRange = new LineRange(c.originalStartLineNumber, c.originalEndLineNumber + 1);
34
- }
35
- let modifiedRange;
36
- if (c.modifiedEndLineNumber === 0) {
37
- // Deletion
38
- modifiedRange = new LineRange(c.modifiedStartLineNumber + 1, c.modifiedStartLineNumber + 1);
39
- }
40
- else {
41
- modifiedRange = new LineRange(c.modifiedStartLineNumber, c.modifiedEndLineNumber + 1);
42
- }
43
- let change = new DetailedLineRangeMapping(originalRange, modifiedRange, c.charChanges?.map(c => new RangeMapping(new Range(c.originalStartLineNumber, c.originalStartColumn, c.originalEndLineNumber, c.originalEndColumn), new Range(c.modifiedStartLineNumber, c.modifiedStartColumn, c.modifiedEndLineNumber, c.modifiedEndColumn))));
44
- if (lastChange) {
45
- if (lastChange.modified.endLineNumberExclusive === change.modified.startLineNumber
46
- || lastChange.original.endLineNumberExclusive === change.original.startLineNumber) {
47
- // join touching diffs. Probably moving diffs up/down in the algorithm causes touching diffs.
48
- change = new DetailedLineRangeMapping(lastChange.original.join(change.original), lastChange.modified.join(change.modified), lastChange.innerChanges && change.innerChanges ?
49
- lastChange.innerChanges.concat(change.innerChanges) : undefined);
50
- changes.pop();
51
- }
52
- }
53
- changes.push(change);
54
- lastChange = change;
55
- }
56
- assertFn(() => {
57
- return checkAdjacentItems(changes, (m1, m2) => m2.original.startLineNumber - m1.original.endLineNumberExclusive === m2.modified.startLineNumber - m1.modified.endLineNumberExclusive &&
58
- // There has to be an unchanged line in between (otherwise both diffs should have been joined)
59
- m1.original.endLineNumberExclusive < m2.original.startLineNumber &&
60
- m1.modified.endLineNumberExclusive < m2.modified.startLineNumber);
61
- });
62
- return new LinesDiff(changes, [], result.quitEarly);
63
- }
64
- }
65
- function computeDiff(originalSequence, modifiedSequence, continueProcessingPredicate, pretty) {
66
- const diffAlgo = new LcsDiff(originalSequence, modifiedSequence, continueProcessingPredicate);
67
- return diffAlgo.ComputeDiff(pretty);
68
- }
69
- class LineSequence {
70
- constructor(lines) {
71
- const startColumns = [];
72
- const endColumns = [];
73
- for (let i = 0, length = lines.length; i < length; i++) {
74
- startColumns[i] = getFirstNonBlankColumn(lines[i], 1);
75
- endColumns[i] = getLastNonBlankColumn(lines[i], 1);
76
- }
77
- this.lines = lines;
78
- this._startColumns = startColumns;
79
- this._endColumns = endColumns;
80
- }
81
- getElements() {
82
- const elements = [];
83
- for (let i = 0, len = this.lines.length; i < len; i++) {
84
- elements[i] = this.lines[i].substring(this._startColumns[i] - 1, this._endColumns[i] - 1);
85
- }
86
- return elements;
87
- }
88
- getStrictElement(index) {
89
- return this.lines[index];
90
- }
91
- getStartLineNumber(i) {
92
- return i + 1;
93
- }
94
- getEndLineNumber(i) {
95
- return i + 1;
96
- }
97
- createCharSequence(shouldIgnoreTrimWhitespace, startIndex, endIndex) {
98
- const charCodes = [];
99
- const lineNumbers = [];
100
- const columns = [];
101
- let len = 0;
102
- for (let index = startIndex; index <= endIndex; index++) {
103
- const lineContent = this.lines[index];
104
- const startColumn = (shouldIgnoreTrimWhitespace ? this._startColumns[index] : 1);
105
- const endColumn = (shouldIgnoreTrimWhitespace ? this._endColumns[index] : lineContent.length + 1);
106
- for (let col = startColumn; col < endColumn; col++) {
107
- charCodes[len] = lineContent.charCodeAt(col - 1);
108
- lineNumbers[len] = index + 1;
109
- columns[len] = col;
110
- len++;
111
- }
112
- if (!shouldIgnoreTrimWhitespace && index < endIndex) {
113
- // Add \n if trim whitespace is not ignored
114
- charCodes[len] = 10 /* CharCode.LineFeed */;
115
- lineNumbers[len] = index + 1;
116
- columns[len] = lineContent.length + 1;
117
- len++;
118
- }
119
- }
120
- return new CharSequence(charCodes, lineNumbers, columns);
121
- }
122
- }
123
- class CharSequence {
124
- constructor(charCodes, lineNumbers, columns) {
125
- this._charCodes = charCodes;
126
- this._lineNumbers = lineNumbers;
127
- this._columns = columns;
128
- }
129
- toString() {
130
- return ('[' + this._charCodes.map((s, idx) => (s === 10 /* CharCode.LineFeed */ ? '\\n' : String.fromCharCode(s)) + `-(${this._lineNumbers[idx]},${this._columns[idx]})`).join(', ') + ']');
131
- }
132
- _assertIndex(index, arr) {
133
- if (index < 0 || index >= arr.length) {
134
- throw new Error(`Illegal index`);
135
- }
136
- }
137
- getElements() {
138
- return this._charCodes;
139
- }
140
- getStartLineNumber(i) {
141
- if (i > 0 && i === this._lineNumbers.length) {
142
- // the start line number of the element after the last element
143
- // is the end line number of the last element
144
- return this.getEndLineNumber(i - 1);
145
- }
146
- this._assertIndex(i, this._lineNumbers);
147
- return this._lineNumbers[i];
148
- }
149
- getEndLineNumber(i) {
150
- if (i === -1) {
151
- // the end line number of the element before the first element
152
- // is the start line number of the first element
153
- return this.getStartLineNumber(i + 1);
154
- }
155
- this._assertIndex(i, this._lineNumbers);
156
- if (this._charCodes[i] === 10 /* CharCode.LineFeed */) {
157
- return this._lineNumbers[i] + 1;
158
- }
159
- return this._lineNumbers[i];
160
- }
161
- getStartColumn(i) {
162
- if (i > 0 && i === this._columns.length) {
163
- // the start column of the element after the last element
164
- // is the end column of the last element
165
- return this.getEndColumn(i - 1);
166
- }
167
- this._assertIndex(i, this._columns);
168
- return this._columns[i];
169
- }
170
- getEndColumn(i) {
171
- if (i === -1) {
172
- // the end column of the element before the first element
173
- // is the start column of the first element
174
- return this.getStartColumn(i + 1);
175
- }
176
- this._assertIndex(i, this._columns);
177
- if (this._charCodes[i] === 10 /* CharCode.LineFeed */) {
178
- return 1;
179
- }
180
- return this._columns[i] + 1;
181
- }
182
- }
183
- class CharChange {
184
- constructor(originalStartLineNumber, originalStartColumn, originalEndLineNumber, originalEndColumn, modifiedStartLineNumber, modifiedStartColumn, modifiedEndLineNumber, modifiedEndColumn) {
185
- this.originalStartLineNumber = originalStartLineNumber;
186
- this.originalStartColumn = originalStartColumn;
187
- this.originalEndLineNumber = originalEndLineNumber;
188
- this.originalEndColumn = originalEndColumn;
189
- this.modifiedStartLineNumber = modifiedStartLineNumber;
190
- this.modifiedStartColumn = modifiedStartColumn;
191
- this.modifiedEndLineNumber = modifiedEndLineNumber;
192
- this.modifiedEndColumn = modifiedEndColumn;
193
- }
194
- static createFromDiffChange(diffChange, originalCharSequence, modifiedCharSequence) {
195
- const originalStartLineNumber = originalCharSequence.getStartLineNumber(diffChange.originalStart);
196
- const originalStartColumn = originalCharSequence.getStartColumn(diffChange.originalStart);
197
- const originalEndLineNumber = originalCharSequence.getEndLineNumber(diffChange.originalStart + diffChange.originalLength - 1);
198
- const originalEndColumn = originalCharSequence.getEndColumn(diffChange.originalStart + diffChange.originalLength - 1);
199
- const modifiedStartLineNumber = modifiedCharSequence.getStartLineNumber(diffChange.modifiedStart);
200
- const modifiedStartColumn = modifiedCharSequence.getStartColumn(diffChange.modifiedStart);
201
- const modifiedEndLineNumber = modifiedCharSequence.getEndLineNumber(diffChange.modifiedStart + diffChange.modifiedLength - 1);
202
- const modifiedEndColumn = modifiedCharSequence.getEndColumn(diffChange.modifiedStart + diffChange.modifiedLength - 1);
203
- return new CharChange(originalStartLineNumber, originalStartColumn, originalEndLineNumber, originalEndColumn, modifiedStartLineNumber, modifiedStartColumn, modifiedEndLineNumber, modifiedEndColumn);
204
- }
205
- }
206
- function postProcessCharChanges(rawChanges) {
207
- if (rawChanges.length <= 1) {
208
- return rawChanges;
209
- }
210
- const result = [rawChanges[0]];
211
- let prevChange = result[0];
212
- for (let i = 1, len = rawChanges.length; i < len; i++) {
213
- const currChange = rawChanges[i];
214
- const originalMatchingLength = currChange.originalStart - (prevChange.originalStart + prevChange.originalLength);
215
- const modifiedMatchingLength = currChange.modifiedStart - (prevChange.modifiedStart + prevChange.modifiedLength);
216
- // Both of the above should be equal, but the continueProcessingPredicate may prevent this from being true
217
- const matchingLength = Math.min(originalMatchingLength, modifiedMatchingLength);
218
- if (matchingLength < MINIMUM_MATCHING_CHARACTER_LENGTH) {
219
- // Merge the current change into the previous one
220
- prevChange.originalLength = (currChange.originalStart + currChange.originalLength) - prevChange.originalStart;
221
- prevChange.modifiedLength = (currChange.modifiedStart + currChange.modifiedLength) - prevChange.modifiedStart;
222
- }
223
- else {
224
- // Add the current change
225
- result.push(currChange);
226
- prevChange = currChange;
227
- }
228
- }
229
- return result;
230
- }
231
- class LineChange {
232
- constructor(originalStartLineNumber, originalEndLineNumber, modifiedStartLineNumber, modifiedEndLineNumber, charChanges) {
233
- this.originalStartLineNumber = originalStartLineNumber;
234
- this.originalEndLineNumber = originalEndLineNumber;
235
- this.modifiedStartLineNumber = modifiedStartLineNumber;
236
- this.modifiedEndLineNumber = modifiedEndLineNumber;
237
- this.charChanges = charChanges;
238
- }
239
- static createFromDiffResult(shouldIgnoreTrimWhitespace, diffChange, originalLineSequence, modifiedLineSequence, continueCharDiff, shouldComputeCharChanges, shouldPostProcessCharChanges) {
240
- let originalStartLineNumber;
241
- let originalEndLineNumber;
242
- let modifiedStartLineNumber;
243
- let modifiedEndLineNumber;
244
- let charChanges = undefined;
245
- if (diffChange.originalLength === 0) {
246
- originalStartLineNumber = originalLineSequence.getStartLineNumber(diffChange.originalStart) - 1;
247
- originalEndLineNumber = 0;
248
- }
249
- else {
250
- originalStartLineNumber = originalLineSequence.getStartLineNumber(diffChange.originalStart);
251
- originalEndLineNumber = originalLineSequence.getEndLineNumber(diffChange.originalStart + diffChange.originalLength - 1);
252
- }
253
- if (diffChange.modifiedLength === 0) {
254
- modifiedStartLineNumber = modifiedLineSequence.getStartLineNumber(diffChange.modifiedStart) - 1;
255
- modifiedEndLineNumber = 0;
256
- }
257
- else {
258
- modifiedStartLineNumber = modifiedLineSequence.getStartLineNumber(diffChange.modifiedStart);
259
- modifiedEndLineNumber = modifiedLineSequence.getEndLineNumber(diffChange.modifiedStart + diffChange.modifiedLength - 1);
260
- }
261
- if (shouldComputeCharChanges && diffChange.originalLength > 0 && diffChange.originalLength < 20 && diffChange.modifiedLength > 0 && diffChange.modifiedLength < 20 && continueCharDiff()) {
262
- // Compute character changes for diff chunks of at most 20 lines...
263
- const originalCharSequence = originalLineSequence.createCharSequence(shouldIgnoreTrimWhitespace, diffChange.originalStart, diffChange.originalStart + diffChange.originalLength - 1);
264
- const modifiedCharSequence = modifiedLineSequence.createCharSequence(shouldIgnoreTrimWhitespace, diffChange.modifiedStart, diffChange.modifiedStart + diffChange.modifiedLength - 1);
265
- if (originalCharSequence.getElements().length > 0 && modifiedCharSequence.getElements().length > 0) {
266
- let rawChanges = computeDiff(originalCharSequence, modifiedCharSequence, continueCharDiff, true).changes;
267
- if (shouldPostProcessCharChanges) {
268
- rawChanges = postProcessCharChanges(rawChanges);
269
- }
270
- charChanges = [];
271
- for (let i = 0, length = rawChanges.length; i < length; i++) {
272
- charChanges.push(CharChange.createFromDiffChange(rawChanges[i], originalCharSequence, modifiedCharSequence));
273
- }
274
- }
275
- }
276
- return new LineChange(originalStartLineNumber, originalEndLineNumber, modifiedStartLineNumber, modifiedEndLineNumber, charChanges);
277
- }
278
- }
279
- class DiffComputer {
280
- constructor(originalLines, modifiedLines, opts) {
281
- this.shouldComputeCharChanges = opts.shouldComputeCharChanges;
282
- this.shouldPostProcessCharChanges = opts.shouldPostProcessCharChanges;
283
- this.shouldIgnoreTrimWhitespace = opts.shouldIgnoreTrimWhitespace;
284
- this.shouldMakePrettyDiff = opts.shouldMakePrettyDiff;
285
- this.originalLines = originalLines;
286
- this.modifiedLines = modifiedLines;
287
- this.original = new LineSequence(originalLines);
288
- this.modified = new LineSequence(modifiedLines);
289
- this.continueLineDiff = createContinueProcessingPredicate(opts.maxComputationTime);
290
- this.continueCharDiff = createContinueProcessingPredicate(opts.maxComputationTime === 0 ? 0 : Math.min(opts.maxComputationTime, 5000)); // never run after 5s for character changes...
291
- }
292
- computeDiff() {
293
- if (this.original.lines.length === 1 && this.original.lines[0].length === 0) {
294
- // empty original => fast path
295
- if (this.modified.lines.length === 1 && this.modified.lines[0].length === 0) {
296
- return {
297
- quitEarly: false,
298
- changes: []
299
- };
300
- }
301
- return {
302
- quitEarly: false,
303
- changes: [{
304
- originalStartLineNumber: 1,
305
- originalEndLineNumber: 1,
306
- modifiedStartLineNumber: 1,
307
- modifiedEndLineNumber: this.modified.lines.length,
308
- charChanges: undefined
309
- }]
310
- };
311
- }
312
- if (this.modified.lines.length === 1 && this.modified.lines[0].length === 0) {
313
- // empty modified => fast path
314
- return {
315
- quitEarly: false,
316
- changes: [{
317
- originalStartLineNumber: 1,
318
- originalEndLineNumber: this.original.lines.length,
319
- modifiedStartLineNumber: 1,
320
- modifiedEndLineNumber: 1,
321
- charChanges: undefined
322
- }]
323
- };
324
- }
325
- const diffResult = computeDiff(this.original, this.modified, this.continueLineDiff, this.shouldMakePrettyDiff);
326
- const rawChanges = diffResult.changes;
327
- const quitEarly = diffResult.quitEarly;
328
- // The diff is always computed with ignoring trim whitespace
329
- // This ensures we get the prettiest diff
330
- if (this.shouldIgnoreTrimWhitespace) {
331
- const lineChanges = [];
332
- for (let i = 0, length = rawChanges.length; i < length; i++) {
333
- lineChanges.push(LineChange.createFromDiffResult(this.shouldIgnoreTrimWhitespace, rawChanges[i], this.original, this.modified, this.continueCharDiff, this.shouldComputeCharChanges, this.shouldPostProcessCharChanges));
334
- }
335
- return {
336
- quitEarly: quitEarly,
337
- changes: lineChanges
338
- };
339
- }
340
- // Need to post-process and introduce changes where the trim whitespace is different
341
- // Note that we are looping starting at -1 to also cover the lines before the first change
342
- const result = [];
343
- let originalLineIndex = 0;
344
- let modifiedLineIndex = 0;
345
- for (let i = -1 /* !!!! */, len = rawChanges.length; i < len; i++) {
346
- const nextChange = (i + 1 < len ? rawChanges[i + 1] : null);
347
- const originalStop = (nextChange ? nextChange.originalStart : this.originalLines.length);
348
- const modifiedStop = (nextChange ? nextChange.modifiedStart : this.modifiedLines.length);
349
- while (originalLineIndex < originalStop && modifiedLineIndex < modifiedStop) {
350
- const originalLine = this.originalLines[originalLineIndex];
351
- const modifiedLine = this.modifiedLines[modifiedLineIndex];
352
- if (originalLine !== modifiedLine) {
353
- // These lines differ only in trim whitespace
354
- // Check the leading whitespace
355
- {
356
- let originalStartColumn = getFirstNonBlankColumn(originalLine, 1);
357
- let modifiedStartColumn = getFirstNonBlankColumn(modifiedLine, 1);
358
- while (originalStartColumn > 1 && modifiedStartColumn > 1) {
359
- const originalChar = originalLine.charCodeAt(originalStartColumn - 2);
360
- const modifiedChar = modifiedLine.charCodeAt(modifiedStartColumn - 2);
361
- if (originalChar !== modifiedChar) {
362
- break;
363
- }
364
- originalStartColumn--;
365
- modifiedStartColumn--;
366
- }
367
- if (originalStartColumn > 1 || modifiedStartColumn > 1) {
368
- this._pushTrimWhitespaceCharChange(result, originalLineIndex + 1, 1, originalStartColumn, modifiedLineIndex + 1, 1, modifiedStartColumn);
369
- }
370
- }
371
- // Check the trailing whitespace
372
- {
373
- let originalEndColumn = getLastNonBlankColumn(originalLine, 1);
374
- let modifiedEndColumn = getLastNonBlankColumn(modifiedLine, 1);
375
- const originalMaxColumn = originalLine.length + 1;
376
- const modifiedMaxColumn = modifiedLine.length + 1;
377
- while (originalEndColumn < originalMaxColumn && modifiedEndColumn < modifiedMaxColumn) {
378
- const originalChar = originalLine.charCodeAt(originalEndColumn - 1);
379
- const modifiedChar = originalLine.charCodeAt(modifiedEndColumn - 1);
380
- if (originalChar !== modifiedChar) {
381
- break;
382
- }
383
- originalEndColumn++;
384
- modifiedEndColumn++;
385
- }
386
- if (originalEndColumn < originalMaxColumn || modifiedEndColumn < modifiedMaxColumn) {
387
- this._pushTrimWhitespaceCharChange(result, originalLineIndex + 1, originalEndColumn, originalMaxColumn, modifiedLineIndex + 1, modifiedEndColumn, modifiedMaxColumn);
388
- }
389
- }
390
- }
391
- originalLineIndex++;
392
- modifiedLineIndex++;
393
- }
394
- if (nextChange) {
395
- // Emit the actual change
396
- result.push(LineChange.createFromDiffResult(this.shouldIgnoreTrimWhitespace, nextChange, this.original, this.modified, this.continueCharDiff, this.shouldComputeCharChanges, this.shouldPostProcessCharChanges));
397
- originalLineIndex += nextChange.originalLength;
398
- modifiedLineIndex += nextChange.modifiedLength;
399
- }
400
- }
401
- return {
402
- quitEarly: quitEarly,
403
- changes: result
404
- };
405
- }
406
- _pushTrimWhitespaceCharChange(result, originalLineNumber, originalStartColumn, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedEndColumn) {
407
- if (this._mergeTrimWhitespaceCharChange(result, originalLineNumber, originalStartColumn, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedEndColumn)) {
408
- // Merged into previous
409
- return;
410
- }
411
- let charChanges = undefined;
412
- if (this.shouldComputeCharChanges) {
413
- charChanges = [new CharChange(originalLineNumber, originalStartColumn, originalLineNumber, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedLineNumber, modifiedEndColumn)];
414
- }
415
- result.push(new LineChange(originalLineNumber, originalLineNumber, modifiedLineNumber, modifiedLineNumber, charChanges));
416
- }
417
- _mergeTrimWhitespaceCharChange(result, originalLineNumber, originalStartColumn, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedEndColumn) {
418
- const len = result.length;
419
- if (len === 0) {
420
- return false;
421
- }
422
- const prevChange = result[len - 1];
423
- if (prevChange.originalEndLineNumber === 0 || prevChange.modifiedEndLineNumber === 0) {
424
- // Don't merge with inserts/deletes
425
- return false;
426
- }
427
- if (prevChange.originalEndLineNumber === originalLineNumber && prevChange.modifiedEndLineNumber === modifiedLineNumber) {
428
- if (this.shouldComputeCharChanges && prevChange.charChanges) {
429
- prevChange.charChanges.push(new CharChange(originalLineNumber, originalStartColumn, originalLineNumber, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedLineNumber, modifiedEndColumn));
430
- }
431
- return true;
432
- }
433
- if (prevChange.originalEndLineNumber + 1 === originalLineNumber && prevChange.modifiedEndLineNumber + 1 === modifiedLineNumber) {
434
- prevChange.originalEndLineNumber = originalLineNumber;
435
- prevChange.modifiedEndLineNumber = modifiedLineNumber;
436
- if (this.shouldComputeCharChanges && prevChange.charChanges) {
437
- prevChange.charChanges.push(new CharChange(originalLineNumber, originalStartColumn, originalLineNumber, originalEndColumn, modifiedLineNumber, modifiedStartColumn, modifiedLineNumber, modifiedEndColumn));
438
- }
439
- return true;
440
- }
441
- return false;
442
- }
443
- }
444
- function getFirstNonBlankColumn(txt, defaultValue) {
445
- const r = firstNonWhitespaceIndex(txt);
446
- if (r === -1) {
447
- return defaultValue;
448
- }
449
- return r + 1;
450
- }
451
- function getLastNonBlankColumn(txt, defaultValue) {
452
- const r = lastNonWhitespaceIndex(txt);
453
- if (r === -1) {
454
- return defaultValue;
455
- }
456
- return r + 2;
457
- }
458
- function createContinueProcessingPredicate(maximumRuntime) {
459
- if (maximumRuntime === 0) {
460
- return () => true;
461
- }
462
- const startTime = Date.now();
463
- return () => {
464
- return Date.now() - startTime < maximumRuntime;
465
- };
466
- }
467
-
468
- export { DiffComputer, LegacyLinesDiffComputer };
@@ -1,129 +0,0 @@
1
- import { splitLines } from '../../../../../base/common/strings.js';
2
- import { Range } from '../../../core/range.js';
3
- import { TextLength } from '../../../core/text/textLength.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
- * The end must be greater than or equal to the start.
11
- */
12
- function lengthDiff(startLineCount, startColumnCount, endLineCount, endColumnCount) {
13
- return (startLineCount !== endLineCount)
14
- ? toLength(endLineCount - startLineCount, endColumnCount)
15
- : toLength(0, endColumnCount - startColumnCount);
16
- }
17
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
18
- const lengthZero = 0;
19
- function lengthIsZero(length) {
20
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
21
- return length === 0;
22
- }
23
- /*
24
- * We have 52 bits available in a JS number.
25
- * We use the upper 26 bits to store the line and the lower 26 bits to store the column.
26
- */
27
- ///*
28
- const factor = 2 ** 26;
29
- /*/
30
- const factor = 1000000;
31
- // */
32
- function toLength(lineCount, columnCount) {
33
- // llllllllllllllllllllllllllcccccccccccccccccccccccccc (52 bits)
34
- // line count (26 bits) column count (26 bits)
35
- // If there is no overflow (all values/sums below 2^26 = 67108864),
36
- // we have `toLength(lns1, cols1) + toLength(lns2, cols2) = toLength(lns1 + lns2, cols1 + cols2)`.
37
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
38
- return (lineCount * factor + columnCount);
39
- }
40
- function lengthToObj(length) {
41
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
42
- const l = length;
43
- const lineCount = Math.floor(l / factor);
44
- const columnCount = l - lineCount * factor;
45
- return new TextLength(lineCount, columnCount);
46
- }
47
- function lengthGetLineCount(length) {
48
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
49
- return Math.floor(length / factor);
50
- }
51
- /**
52
- * Returns the amount of columns of the given length, assuming that it does not span any line.
53
- */
54
- function lengthGetColumnCountIfZeroLineCount(length) {
55
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
56
- return length;
57
- }
58
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
- function lengthAdd(l1, l2) {
60
- let r = l1 + l2;
61
- if (l2 >= factor) {
62
- r = r - (l1 % factor);
63
- }
64
- return r;
65
- }
66
- function sumLengths(items, lengthFn) {
67
- return items.reduce((a, b) => lengthAdd(a, lengthFn(b)), lengthZero);
68
- }
69
- function lengthEquals(length1, length2) {
70
- return length1 === length2;
71
- }
72
- /**
73
- * Returns a non negative length `result` such that `lengthAdd(length1, result) = length2`, or zero if such length does not exist.
74
- */
75
- function lengthDiffNonNegative(length1, length2) {
76
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
77
- const l1 = length1;
78
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
79
- const l2 = length2;
80
- const diff = l2 - l1;
81
- if (diff <= 0) {
82
- // line-count of length1 is higher than line-count of length2
83
- // or they are equal and column-count of length1 is higher than column-count of length2
84
- return lengthZero;
85
- }
86
- const lineCount1 = Math.floor(l1 / factor);
87
- const lineCount2 = Math.floor(l2 / factor);
88
- const colCount2 = l2 - lineCount2 * factor;
89
- if (lineCount1 === lineCount2) {
90
- const colCount1 = l1 - lineCount1 * factor;
91
- return toLength(0, colCount2 - colCount1);
92
- }
93
- else {
94
- return toLength(lineCount2 - lineCount1, colCount2);
95
- }
96
- }
97
- function lengthLessThan(length1, length2) {
98
- // First, compare line counts, then column counts.
99
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
100
- return length1 < length2;
101
- }
102
- function lengthLessThanEqual(length1, length2) {
103
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
104
- return length1 <= length2;
105
- }
106
- function lengthGreaterThanEqual(length1, length2) {
107
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
108
- return length1 >= length2;
109
- }
110
- function positionToLength(position) {
111
- return toLength(position.lineNumber - 1, position.column - 1);
112
- }
113
- function lengthsToRange(lengthStart, lengthEnd) {
114
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
115
- const l = lengthStart;
116
- const lineCount = Math.floor(l / factor);
117
- const colCount = l - lineCount * factor;
118
- // eslint-disable-next-line local/code-no-any-casts, @typescript-eslint/no-explicit-any
119
- const l2 = lengthEnd;
120
- const lineCount2 = Math.floor(l2 / factor);
121
- const colCount2 = l2 - lineCount2 * factor;
122
- return new Range(lineCount + 1, colCount + 1, lineCount2 + 1, colCount2 + 1);
123
- }
124
- function lengthOfString(str) {
125
- const lines = splitLines(str);
126
- return toLength(lines.length - 1, lines[lines.length - 1].length);
127
- }
128
-
129
- export { lengthAdd, lengthDiff, lengthDiffNonNegative, lengthEquals, lengthGetColumnCountIfZeroLineCount, lengthGetLineCount, lengthGreaterThanEqual, lengthIsZero, lengthLessThan, lengthLessThanEqual, lengthOfString, lengthToObj, lengthZero, lengthsToRange, positionToLength, sumLengths, toLength };