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.
Files changed (237) hide show
  1. package/dist/assets/css.worker-C7FogG4G.js +93 -0
  2. package/dist/assets/editor.worker-iXcRX1Tq.js +26 -0
  3. package/dist/assets/html.worker-C8VxctEJ.js +470 -0
  4. package/dist/assets/json.worker-CMC9kgPL.js +58 -0
  5. package/dist/assets/ts.worker-CtTJ3hNN.js +67731 -0
  6. package/dist/index.d.ts +0 -6
  7. package/dist/monaco-editor11.es.js +49 -78
  8. package/dist/monaco-editor11.umd.js +1 -50
  9. package/dist/monaco.d.ts +8 -0
  10. package/dist/workers/common/initialize.js +16 -0
  11. package/dist/workers/common/workers.js +141 -0
  12. package/dist/workers/editor/common/abstractSyntaxTokenBackend.js +128 -0
  13. package/dist/workers/editor/common/abstractText.js +89 -0
  14. package/dist/workers/editor/common/ast.js +485 -0
  15. package/dist/workers/editor/common/autoIndent.js +390 -0
  16. package/dist/workers/editor/common/beforeEditPositionMapper.js +110 -0
  17. package/dist/workers/editor/common/bracketPairsImpl.js +717 -0
  18. package/dist/workers/editor/common/bracketPairsTree.js +343 -0
  19. package/dist/workers/editor/common/brackets.js +108 -0
  20. package/dist/workers/editor/common/characterClassifier.js +59 -0
  21. package/dist/workers/editor/common/characterPair.js +40 -0
  22. package/dist/workers/editor/common/colorizedBracketPairsDecorationProvider.js +97 -0
  23. package/dist/workers/editor/common/columnRange.js +35 -0
  24. package/dist/workers/editor/common/combineTextEditInfos.js +124 -0
  25. package/dist/workers/editor/common/common.js +20 -0
  26. package/dist/workers/editor/common/computeMovedLines.js +249 -0
  27. package/dist/workers/editor/common/concat23Trees.js +192 -0
  28. package/dist/workers/editor/common/contiguousMultilineTokens.js +32 -0
  29. package/dist/workers/editor/common/contiguousMultilineTokensBuilder.js +23 -0
  30. package/dist/workers/editor/common/contiguousTokensEditing.js +128 -0
  31. package/dist/workers/editor/common/contiguousTokensStore.js +207 -0
  32. package/dist/workers/editor/common/coordinatesConverter.js +51 -0
  33. package/dist/workers/editor/common/cursor.js +899 -0
  34. package/dist/workers/editor/common/cursorAtomicMoveOperations.js +145 -0
  35. package/dist/workers/editor/common/cursorCollection.js +194 -0
  36. package/dist/workers/editor/common/cursorColumnSelection.js +93 -0
  37. package/dist/workers/editor/common/cursorColumns.js +112 -0
  38. package/dist/workers/editor/common/cursorCommon.js +250 -0
  39. package/dist/workers/editor/common/cursorContext.js +15 -0
  40. package/dist/workers/editor/common/cursorDeleteOperations.js +231 -0
  41. package/dist/workers/editor/common/cursorMoveCommands.js +676 -0
  42. package/dist/workers/editor/common/cursorMoveOperations.js +290 -0
  43. package/dist/workers/editor/common/cursorTypeEditOperations.js +968 -0
  44. package/dist/workers/editor/common/cursorTypeOperations.js +173 -0
  45. package/dist/workers/editor/common/cursorUtils.js +75 -0
  46. package/dist/workers/editor/common/cursorWordOperations.js +720 -0
  47. package/dist/workers/editor/common/defaultDocumentColorsComputer.js +138 -0
  48. package/dist/workers/editor/common/defaultLinesDiffComputer.js +188 -0
  49. package/dist/workers/editor/common/diffAlgorithm.js +139 -0
  50. package/dist/workers/editor/common/diffEditor.js +38 -0
  51. package/dist/workers/editor/common/dynamicProgrammingDiffing.js +101 -0
  52. package/dist/workers/editor/common/edit.js +183 -0
  53. package/dist/workers/editor/common/editOperation.js +36 -0
  54. package/dist/workers/editor/common/editStack.js +363 -0
  55. package/dist/workers/editor/common/editorAction.js +26 -0
  56. package/dist/workers/editor/common/editorBaseApi.js +43 -0
  57. package/dist/workers/editor/common/editorColorRegistry.js +102 -0
  58. package/dist/workers/editor/common/editorCommon.js +13 -0
  59. package/dist/workers/editor/common/editorConfigurationSchema.js +338 -0
  60. package/dist/workers/editor/common/editorContextKeys.js +84 -0
  61. package/dist/workers/editor/common/editorFeatures.js +17 -0
  62. package/dist/workers/editor/common/editorOptions.js +3440 -0
  63. package/dist/workers/editor/common/editorTheme.js +23 -0
  64. package/dist/workers/editor/common/editorWebWorker.js +299 -0
  65. package/dist/workers/editor/common/editorWorker.js +9 -0
  66. package/dist/workers/editor/common/editorWorkerHost.js +15 -0
  67. package/dist/workers/editor/common/editorZoom.js +26 -0
  68. package/dist/workers/editor/common/electricCharacter.js +55 -0
  69. package/dist/workers/editor/common/encodedTokenAttributes.js +79 -0
  70. package/dist/workers/editor/common/enterAction.js +53 -0
  71. package/dist/workers/editor/common/eolCounter.js +44 -0
  72. package/dist/workers/editor/common/findSectionHeaders.js +128 -0
  73. package/dist/workers/editor/common/fixBrackets.js +67 -0
  74. package/dist/workers/editor/common/fixedArray.js +70 -0
  75. package/dist/workers/editor/common/fontInfo.js +172 -0
  76. package/dist/workers/editor/common/fontInfoFromSettings.js +29 -0
  77. package/dist/workers/editor/common/getIconClasses.js +106 -0
  78. package/dist/workers/editor/common/getPositionOffsetTransformerFromTextModel.js +24 -0
  79. package/dist/workers/editor/common/glyphLanesModel.js +61 -0
  80. package/dist/workers/editor/common/guidesTextModelPart.js +405 -0
  81. package/dist/workers/editor/common/heuristicSequenceOptimizations.js +374 -0
  82. package/dist/workers/editor/common/indentRules.js +63 -0
  83. package/dist/workers/editor/common/indentation.js +39 -0
  84. package/dist/workers/editor/common/indentationGuesser.js +178 -0
  85. package/dist/workers/editor/common/indentationLineProcessor.js +193 -0
  86. package/dist/workers/editor/common/inlineDecorations.js +26 -0
  87. package/dist/workers/editor/common/inplaceReplaceSupport.js +87 -0
  88. package/dist/workers/editor/common/inputMode.js +22 -0
  89. package/dist/workers/editor/common/intervalTree.js +1002 -0
  90. package/dist/workers/editor/common/language.js +9 -0
  91. package/dist/workers/editor/common/languageBracketsConfiguration.js +133 -0
  92. package/dist/workers/editor/common/languageConfiguration.js +138 -0
  93. package/dist/workers/editor/common/languageConfigurationRegistry.js +361 -0
  94. package/dist/workers/editor/common/languageFeatureDebounce.js +137 -0
  95. package/dist/workers/editor/common/languageFeatureRegistry.js +180 -0
  96. package/dist/workers/editor/common/languageFeatures.js +9 -0
  97. package/dist/workers/editor/common/languageFeaturesService.js +47 -0
  98. package/dist/workers/editor/common/languageSelector.js +112 -0
  99. package/dist/workers/editor/common/languageService.js +92 -0
  100. package/dist/workers/editor/common/languages.js +522 -0
  101. package/dist/workers/editor/common/languagesAssociations.js +193 -0
  102. package/dist/workers/editor/common/languagesRegistry.js +237 -0
  103. package/dist/workers/editor/common/legacyLinesDiffComputer.js +468 -0
  104. package/dist/workers/editor/common/length.js +129 -0
  105. package/dist/workers/editor/common/lineDecorations.js +208 -0
  106. package/dist/workers/editor/common/lineEdit.js +75 -0
  107. package/dist/workers/editor/common/lineHeights.js +370 -0
  108. package/dist/workers/editor/common/linePart.js +25 -0
  109. package/dist/workers/editor/common/lineRange.js +312 -0
  110. package/dist/workers/editor/common/lineSequence.js +36 -0
  111. package/dist/workers/editor/common/lineTokens.js +405 -0
  112. package/dist/workers/editor/common/linesDiffComputer.js +29 -0
  113. package/dist/workers/editor/common/linesDiffComputers.js +13 -0
  114. package/dist/workers/editor/common/linesLayout.js +765 -0
  115. package/dist/workers/editor/common/linesSliceCharSequence.js +205 -0
  116. package/dist/workers/editor/common/linkComputer.js +269 -0
  117. package/dist/workers/editor/common/markerDecorations.js +9 -0
  118. package/dist/workers/editor/common/markerDecorationsService.js +248 -0
  119. package/dist/workers/editor/common/minimapTokensColorTracker.js +58 -0
  120. package/dist/workers/editor/common/mirrorTextModel.js +117 -0
  121. package/dist/workers/editor/common/model.js +9 -0
  122. package/dist/workers/editor/common/modelLineProjection.js +350 -0
  123. package/dist/workers/editor/common/modelLineProjectionData.js +297 -0
  124. package/dist/workers/editor/common/modelService.js +413 -0
  125. package/dist/workers/editor/common/modesRegistry.js +75 -0
  126. package/dist/workers/editor/common/monospaceLineBreaksComputer.js +473 -0
  127. package/dist/workers/editor/common/myersDiffAlgorithm.js +159 -0
  128. package/dist/workers/editor/common/nodeReader.js +127 -0
  129. package/dist/workers/editor/common/nullTokenize.js +29 -0
  130. package/dist/workers/editor/common/offsetRange.js +225 -0
  131. package/dist/workers/editor/common/onEnter.js +109 -0
  132. package/dist/workers/editor/common/oneCursor.js +117 -0
  133. package/dist/workers/editor/common/overviewZoneManager.js +176 -0
  134. package/dist/workers/editor/common/parser.js +121 -0
  135. package/dist/workers/editor/common/pieceTreeBase.js +1473 -0
  136. package/dist/workers/editor/common/pieceTreeTextBuffer.js +461 -0
  137. package/dist/workers/editor/common/pieceTreeTextBufferBuilder.js +140 -0
  138. package/dist/workers/editor/common/point.js +50 -0
  139. package/dist/workers/editor/common/position.js +142 -0
  140. package/dist/workers/editor/common/positionToOffset.js +17 -0
  141. package/dist/workers/editor/common/positionToOffsetImpl.js +98 -0
  142. package/dist/workers/editor/common/prefixSumComputer.js +226 -0
  143. package/dist/workers/editor/common/range.js +421 -0
  144. package/dist/workers/editor/common/rangeMapping.js +229 -0
  145. package/dist/workers/editor/common/rangeSingleLine.js +17 -0
  146. package/dist/workers/editor/common/rbTreeBase.js +362 -0
  147. package/dist/workers/editor/common/rect.js +163 -0
  148. package/dist/workers/editor/common/replaceCommand.js +158 -0
  149. package/dist/workers/editor/common/resolverService.js +5 -0
  150. package/dist/workers/editor/common/rgba.js +35 -0
  151. package/dist/workers/editor/common/richEditBrackets.js +356 -0
  152. package/dist/workers/editor/common/selection.js +145 -0
  153. package/dist/workers/editor/common/semanticTokensDto.js +82 -0
  154. package/dist/workers/editor/common/semanticTokensProviderStyling.js +263 -0
  155. package/dist/workers/editor/common/semanticTokensStyling.js +9 -0
  156. package/dist/workers/editor/common/semanticTokensStylingService.js +47 -0
  157. package/dist/workers/editor/common/shiftCommand.js +241 -0
  158. package/dist/workers/editor/common/smallImmutableSet.js +108 -0
  159. package/dist/workers/editor/common/sparseMultilineTokens.js +548 -0
  160. package/dist/workers/editor/common/sparseTokensStore.js +210 -0
  161. package/dist/workers/editor/common/standaloneEnums.js +1017 -0
  162. package/dist/workers/editor/common/standaloneStrings.js +42 -0
  163. package/dist/workers/editor/common/stringBuilder.js +122 -0
  164. package/dist/workers/editor/common/stringEdit.js +165 -0
  165. package/dist/workers/editor/common/supports.js +58 -0
  166. package/dist/workers/editor/common/surroundSelectionCommand.js +44 -0
  167. package/dist/workers/editor/common/textChange.js +248 -0
  168. package/dist/workers/editor/common/textEdit.js +269 -0
  169. package/dist/workers/editor/common/textLength.js +87 -0
  170. package/dist/workers/editor/common/textModel.js +2031 -0
  171. package/dist/workers/editor/common/textModelBracketPairs.js +45 -0
  172. package/dist/workers/editor/common/textModelDefaults.js +18 -0
  173. package/dist/workers/editor/common/textModelEditSource.js +166 -0
  174. package/dist/workers/editor/common/textModelEvents.js +216 -0
  175. package/dist/workers/editor/common/textModelGuides.js +40 -0
  176. package/dist/workers/editor/common/textModelPart.js +23 -0
  177. package/dist/workers/editor/common/textModelSearch.js +455 -0
  178. package/dist/workers/editor/common/textModelStringEdit.js +11 -0
  179. package/dist/workers/editor/common/textModelSync.impl.js +307 -0
  180. package/dist/workers/editor/common/textModelText.js +26 -0
  181. package/dist/workers/editor/common/textModelTokens.js +436 -0
  182. package/dist/workers/editor/common/textResourceConfiguration.js +6 -0
  183. package/dist/workers/editor/common/textToHtmlTokenizer.js +139 -0
  184. package/dist/workers/editor/common/tokenStore.js +407 -0
  185. package/dist/workers/editor/common/tokenWithTextArray.js +73 -0
  186. package/dist/workers/editor/common/tokenization.js +287 -0
  187. package/dist/workers/editor/common/tokenizationRegistry.js +123 -0
  188. package/dist/workers/editor/common/tokenizationTextModelPart.js +275 -0
  189. package/dist/workers/editor/common/tokenizer.js +301 -0
  190. package/dist/workers/editor/common/tokenizerSyntaxTokenBackend.js +261 -0
  191. package/dist/workers/editor/common/treeSitterLibraryService.js +9 -0
  192. package/dist/workers/editor/common/treeSitterSyntaxTokenBackend.js +167 -0
  193. package/dist/workers/editor/common/treeSitterThemeService.js +9 -0
  194. package/dist/workers/editor/common/treeSitterTokenizationImpl.js +713 -0
  195. package/dist/workers/editor/common/treeSitterTree.js +395 -0
  196. package/dist/workers/editor/common/treeViewsDnd.js +24 -0
  197. package/dist/workers/editor/common/treeViewsDndService.js +12 -0
  198. package/dist/workers/editor/common/trimTrailingWhitespaceCommand.js +98 -0
  199. package/dist/workers/editor/common/unicodeTextModelHighlighter.js +188 -0
  200. package/dist/workers/editor/common/utils.js +62 -0
  201. package/dist/workers/editor/common/viewContext.js +22 -0
  202. package/dist/workers/editor/common/viewEventHandler.js +186 -0
  203. package/dist/workers/editor/common/viewEvents.js +180 -0
  204. package/dist/workers/editor/common/viewLayout.js +368 -0
  205. package/dist/workers/editor/common/viewLineRenderer.js +948 -0
  206. package/dist/workers/editor/common/viewLinesViewportData.js +30 -0
  207. package/dist/workers/editor/common/viewModel.js +98 -0
  208. package/dist/workers/editor/common/viewModelDecoration.js +55 -0
  209. package/dist/workers/editor/common/viewModelDecorations.js +132 -0
  210. package/dist/workers/editor/common/viewModelEventDispatcher.js +398 -0
  211. package/dist/workers/editor/common/viewModelImpl.js +1163 -0
  212. package/dist/workers/editor/common/viewModelLines.js +938 -0
  213. package/dist/workers/editor/common/wordCharacterClassifier.js +87 -0
  214. package/dist/workers/editor/common/wordHelper.js +127 -0
  215. package/dist/workers/editor/editor.worker.js +11 -0
  216. package/dist/workers/language/css.worker.js +8 -0
  217. package/dist/workers/language/cssMode.js +198 -0
  218. package/dist/workers/language/cssWorker.js +183 -0
  219. package/dist/workers/language/html.worker.js +8 -0
  220. package/dist/workers/language/htmlMode.js +213 -0
  221. package/dist/workers/language/htmlWorker.js +126 -0
  222. package/dist/workers/language/json.worker.js +8 -0
  223. package/dist/workers/language/jsonMode.js +224 -0
  224. package/dist/workers/language/jsonWorker.js +187 -0
  225. package/dist/workers/language/languageFeatures.js +1009 -0
  226. package/dist/workers/language/lib.index.js +103 -0
  227. package/dist/workers/language/lib.js +1107 -0
  228. package/dist/workers/language/lspLanguageFeatures.js +716 -0
  229. package/dist/workers/language/monaco.contribution.js +144 -0
  230. package/dist/workers/language/tokenization.js +189 -0
  231. package/dist/workers/language/ts.worker.js +14 -0
  232. package/dist/workers/language/tsMode.js +212 -0
  233. package/dist/workers/language/tsWorker.js +352 -0
  234. package/dist/workers/language/typescriptServices.js +210154 -0
  235. package/dist/workers/language/typescriptServicesMetadata.js +3 -0
  236. package/dist/workers/language/workerManager.js +65 -0
  237. package/package.json +3 -2
@@ -0,0 +1,468 @@
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 };
@@ -0,0 +1,129 @@
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 };