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,390 @@
1
+ import { getLeadingWhitespace } from '../../../base/common/strings.js';
2
+ import { IndentAction } from './languageConfiguration.js';
3
+ import { IndentationContextProcessor, isLanguageDifferentFromLineStart, ProcessedIndentRulesSupport } from './supports/indentationLineProcessor.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
+ * Get nearest preceding line which doesn't match unIndentPattern or contains all whitespace.
11
+ * Result:
12
+ * -1: run into the boundary of embedded languages
13
+ * 0: every line above are invalid
14
+ * else: nearest preceding line of the same language
15
+ */
16
+ function getPrecedingValidLine(model, lineNumber, processedIndentRulesSupport) {
17
+ const languageId = model.tokenization.getLanguageIdAtPosition(lineNumber, 0);
18
+ if (lineNumber > 1) {
19
+ let lastLineNumber;
20
+ let resultLineNumber = -1;
21
+ for (lastLineNumber = lineNumber - 1; lastLineNumber >= 1; lastLineNumber--) {
22
+ if (model.tokenization.getLanguageIdAtPosition(lastLineNumber, 0) !== languageId) {
23
+ return resultLineNumber;
24
+ }
25
+ const text = model.getLineContent(lastLineNumber);
26
+ if (processedIndentRulesSupport.shouldIgnore(lastLineNumber) || /^\s+$/.test(text) || text === '') {
27
+ resultLineNumber = lastLineNumber;
28
+ continue;
29
+ }
30
+ return lastLineNumber;
31
+ }
32
+ }
33
+ return -1;
34
+ }
35
+ /**
36
+ * Get inherited indentation from above lines.
37
+ * 1. Find the nearest preceding line which doesn't match unIndentedLinePattern.
38
+ * 2. If this line matches indentNextLinePattern or increaseIndentPattern, it means that the indent level of `lineNumber` should be 1 greater than this line.
39
+ * 3. If this line doesn't match any indent rules
40
+ * a. check whether the line above it matches indentNextLinePattern
41
+ * b. If not, the indent level of this line is the result
42
+ * c. If so, it means the indent of this line is *temporary*, go upward utill we find a line whose indent is not temporary (the same workflow a -> b -> c).
43
+ * 4. Otherwise, we fail to get an inherited indent from aboves. Return null and we should not touch the indent of `lineNumber`
44
+ *
45
+ * This function only return the inherited indent based on above lines, it doesn't check whether current line should decrease or not.
46
+ */
47
+ function getInheritIndentForLine(autoIndent, model, lineNumber, honorIntentialIndent = true, languageConfigurationService) {
48
+ if (autoIndent < 4 /* EditorAutoIndentStrategy.Full */) {
49
+ return null;
50
+ }
51
+ const indentRulesSupport = languageConfigurationService.getLanguageConfiguration(model.tokenization.getLanguageId()).indentRulesSupport;
52
+ if (!indentRulesSupport) {
53
+ return null;
54
+ }
55
+ const processedIndentRulesSupport = new ProcessedIndentRulesSupport(model, indentRulesSupport, languageConfigurationService);
56
+ if (lineNumber <= 1) {
57
+ return {
58
+ indentation: '',
59
+ action: null
60
+ };
61
+ }
62
+ // Use no indent if this is the first non-blank line
63
+ for (let priorLineNumber = lineNumber - 1; priorLineNumber > 0; priorLineNumber--) {
64
+ if (model.getLineContent(priorLineNumber) !== '') {
65
+ break;
66
+ }
67
+ if (priorLineNumber === 1) {
68
+ return {
69
+ indentation: '',
70
+ action: null
71
+ };
72
+ }
73
+ }
74
+ const precedingUnIgnoredLine = getPrecedingValidLine(model, lineNumber, processedIndentRulesSupport);
75
+ if (precedingUnIgnoredLine < 0) {
76
+ return null;
77
+ }
78
+ else if (precedingUnIgnoredLine < 1) {
79
+ return {
80
+ indentation: '',
81
+ action: null
82
+ };
83
+ }
84
+ if (processedIndentRulesSupport.shouldIncrease(precedingUnIgnoredLine) || processedIndentRulesSupport.shouldIndentNextLine(precedingUnIgnoredLine)) {
85
+ const precedingUnIgnoredLineContent = model.getLineContent(precedingUnIgnoredLine);
86
+ return {
87
+ indentation: getLeadingWhitespace(precedingUnIgnoredLineContent),
88
+ action: IndentAction.Indent,
89
+ line: precedingUnIgnoredLine
90
+ };
91
+ }
92
+ else if (processedIndentRulesSupport.shouldDecrease(precedingUnIgnoredLine)) {
93
+ const precedingUnIgnoredLineContent = model.getLineContent(precedingUnIgnoredLine);
94
+ return {
95
+ indentation: getLeadingWhitespace(precedingUnIgnoredLineContent),
96
+ action: null,
97
+ line: precedingUnIgnoredLine
98
+ };
99
+ }
100
+ else {
101
+ // precedingUnIgnoredLine can not be ignored.
102
+ // it doesn't increase indent of following lines
103
+ // it doesn't increase just next line
104
+ // so current line is not affect by precedingUnIgnoredLine
105
+ // and then we should get a correct inheritted indentation from above lines
106
+ if (precedingUnIgnoredLine === 1) {
107
+ return {
108
+ indentation: getLeadingWhitespace(model.getLineContent(precedingUnIgnoredLine)),
109
+ action: null,
110
+ line: precedingUnIgnoredLine
111
+ };
112
+ }
113
+ const previousLine = precedingUnIgnoredLine - 1;
114
+ const previousLineIndentMetadata = indentRulesSupport.getIndentMetadata(model.getLineContent(previousLine));
115
+ if (!(previousLineIndentMetadata & (1 /* IndentConsts.INCREASE_MASK */ | 2 /* IndentConsts.DECREASE_MASK */)) &&
116
+ (previousLineIndentMetadata & 4 /* IndentConsts.INDENT_NEXTLINE_MASK */)) {
117
+ let stopLine = 0;
118
+ for (let i = previousLine - 1; i > 0; i--) {
119
+ if (processedIndentRulesSupport.shouldIndentNextLine(i)) {
120
+ continue;
121
+ }
122
+ stopLine = i;
123
+ break;
124
+ }
125
+ return {
126
+ indentation: getLeadingWhitespace(model.getLineContent(stopLine + 1)),
127
+ action: null,
128
+ line: stopLine + 1
129
+ };
130
+ }
131
+ if (honorIntentialIndent) {
132
+ return {
133
+ indentation: getLeadingWhitespace(model.getLineContent(precedingUnIgnoredLine)),
134
+ action: null,
135
+ line: precedingUnIgnoredLine
136
+ };
137
+ }
138
+ else {
139
+ // search from precedingUnIgnoredLine until we find one whose indent is not temporary
140
+ for (let i = precedingUnIgnoredLine; i > 0; i--) {
141
+ if (processedIndentRulesSupport.shouldIncrease(i)) {
142
+ return {
143
+ indentation: getLeadingWhitespace(model.getLineContent(i)),
144
+ action: IndentAction.Indent,
145
+ line: i
146
+ };
147
+ }
148
+ else if (processedIndentRulesSupport.shouldIndentNextLine(i)) {
149
+ let stopLine = 0;
150
+ for (let j = i - 1; j > 0; j--) {
151
+ if (processedIndentRulesSupport.shouldIndentNextLine(i)) {
152
+ continue;
153
+ }
154
+ stopLine = j;
155
+ break;
156
+ }
157
+ return {
158
+ indentation: getLeadingWhitespace(model.getLineContent(stopLine + 1)),
159
+ action: null,
160
+ line: stopLine + 1
161
+ };
162
+ }
163
+ else if (processedIndentRulesSupport.shouldDecrease(i)) {
164
+ return {
165
+ indentation: getLeadingWhitespace(model.getLineContent(i)),
166
+ action: null,
167
+ line: i
168
+ };
169
+ }
170
+ }
171
+ return {
172
+ indentation: getLeadingWhitespace(model.getLineContent(1)),
173
+ action: null,
174
+ line: 1
175
+ };
176
+ }
177
+ }
178
+ }
179
+ function getGoodIndentForLine(autoIndent, virtualModel, languageId, lineNumber, indentConverter, languageConfigurationService) {
180
+ if (autoIndent < 4 /* EditorAutoIndentStrategy.Full */) {
181
+ return null;
182
+ }
183
+ const richEditSupport = languageConfigurationService.getLanguageConfiguration(languageId);
184
+ if (!richEditSupport) {
185
+ return null;
186
+ }
187
+ const indentRulesSupport = languageConfigurationService.getLanguageConfiguration(languageId).indentRulesSupport;
188
+ if (!indentRulesSupport) {
189
+ return null;
190
+ }
191
+ const processedIndentRulesSupport = new ProcessedIndentRulesSupport(virtualModel, indentRulesSupport, languageConfigurationService);
192
+ const indent = getInheritIndentForLine(autoIndent, virtualModel, lineNumber, undefined, languageConfigurationService);
193
+ if (indent) {
194
+ const inheritLine = indent.line;
195
+ if (inheritLine !== undefined) {
196
+ // Apply enter action as long as there are only whitespace lines between inherited line and this line.
197
+ let shouldApplyEnterRules = true;
198
+ for (let inBetweenLine = inheritLine; inBetweenLine < lineNumber - 1; inBetweenLine++) {
199
+ if (!/^\s*$/.test(virtualModel.getLineContent(inBetweenLine))) {
200
+ shouldApplyEnterRules = false;
201
+ break;
202
+ }
203
+ }
204
+ if (shouldApplyEnterRules) {
205
+ const enterResult = richEditSupport.onEnter(autoIndent, '', virtualModel.getLineContent(inheritLine), '');
206
+ if (enterResult) {
207
+ let indentation = getLeadingWhitespace(virtualModel.getLineContent(inheritLine));
208
+ if (enterResult.removeText) {
209
+ indentation = indentation.substring(0, indentation.length - enterResult.removeText);
210
+ }
211
+ if ((enterResult.indentAction === IndentAction.Indent) ||
212
+ (enterResult.indentAction === IndentAction.IndentOutdent)) {
213
+ indentation = indentConverter.shiftIndent(indentation);
214
+ }
215
+ else if (enterResult.indentAction === IndentAction.Outdent) {
216
+ indentation = indentConverter.unshiftIndent(indentation);
217
+ }
218
+ if (processedIndentRulesSupport.shouldDecrease(lineNumber)) {
219
+ indentation = indentConverter.unshiftIndent(indentation);
220
+ }
221
+ if (enterResult.appendText) {
222
+ indentation += enterResult.appendText;
223
+ }
224
+ return getLeadingWhitespace(indentation);
225
+ }
226
+ }
227
+ }
228
+ if (processedIndentRulesSupport.shouldDecrease(lineNumber)) {
229
+ if (indent.action === IndentAction.Indent) {
230
+ return indent.indentation;
231
+ }
232
+ else {
233
+ return indentConverter.unshiftIndent(indent.indentation);
234
+ }
235
+ }
236
+ else {
237
+ if (indent.action === IndentAction.Indent) {
238
+ return indentConverter.shiftIndent(indent.indentation);
239
+ }
240
+ else {
241
+ return indent.indentation;
242
+ }
243
+ }
244
+ }
245
+ return null;
246
+ }
247
+ function getIndentForEnter(autoIndent, model, range, indentConverter, languageConfigurationService) {
248
+ if (autoIndent < 4 /* EditorAutoIndentStrategy.Full */) {
249
+ return null;
250
+ }
251
+ const languageId = model.getLanguageIdAtPosition(range.startLineNumber, range.startColumn);
252
+ const indentRulesSupport = languageConfigurationService.getLanguageConfiguration(languageId).indentRulesSupport;
253
+ if (!indentRulesSupport) {
254
+ return null;
255
+ }
256
+ model.tokenization.forceTokenization(range.startLineNumber);
257
+ const indentationContextProcessor = new IndentationContextProcessor(model, languageConfigurationService);
258
+ const processedContextTokens = indentationContextProcessor.getProcessedTokenContextAroundRange(range);
259
+ const afterEnterProcessedTokens = processedContextTokens.afterRangeProcessedTokens;
260
+ const beforeEnterProcessedTokens = processedContextTokens.beforeRangeProcessedTokens;
261
+ const beforeEnterIndent = getLeadingWhitespace(beforeEnterProcessedTokens.getLineContent());
262
+ const virtualModel = createVirtualModelWithModifiedTokensAtLine(model, range.startLineNumber, beforeEnterProcessedTokens);
263
+ const languageIsDifferentFromLineStart = isLanguageDifferentFromLineStart(model, range.getStartPosition());
264
+ const currentLine = model.getLineContent(range.startLineNumber);
265
+ const currentLineIndent = getLeadingWhitespace(currentLine);
266
+ const afterEnterAction = getInheritIndentForLine(autoIndent, virtualModel, range.startLineNumber + 1, undefined, languageConfigurationService);
267
+ if (!afterEnterAction) {
268
+ const beforeEnter = languageIsDifferentFromLineStart ? currentLineIndent : beforeEnterIndent;
269
+ return {
270
+ beforeEnter: beforeEnter,
271
+ afterEnter: beforeEnter
272
+ };
273
+ }
274
+ let afterEnterIndent = languageIsDifferentFromLineStart ? currentLineIndent : afterEnterAction.indentation;
275
+ if (afterEnterAction.action === IndentAction.Indent) {
276
+ afterEnterIndent = indentConverter.shiftIndent(afterEnterIndent);
277
+ }
278
+ if (indentRulesSupport.shouldDecrease(afterEnterProcessedTokens.getLineContent())) {
279
+ afterEnterIndent = indentConverter.unshiftIndent(afterEnterIndent);
280
+ }
281
+ return {
282
+ beforeEnter: languageIsDifferentFromLineStart ? currentLineIndent : beforeEnterIndent,
283
+ afterEnter: afterEnterIndent
284
+ };
285
+ }
286
+ /**
287
+ * We should always allow intentional indentation. It means, if users change the indentation of `lineNumber` and the content of
288
+ * this line doesn't match decreaseIndentPattern, we should not adjust the indentation.
289
+ */
290
+ function getIndentActionForType(cursorConfig, model, range, ch, indentConverter, languageConfigurationService) {
291
+ const autoIndent = cursorConfig.autoIndent;
292
+ if (autoIndent < 4 /* EditorAutoIndentStrategy.Full */) {
293
+ return null;
294
+ }
295
+ const languageIsDifferentFromLineStart = isLanguageDifferentFromLineStart(model, range.getStartPosition());
296
+ if (languageIsDifferentFromLineStart) {
297
+ // this line has mixed languages and indentation rules will not work
298
+ return null;
299
+ }
300
+ const languageId = model.getLanguageIdAtPosition(range.startLineNumber, range.startColumn);
301
+ const indentRulesSupport = languageConfigurationService.getLanguageConfiguration(languageId).indentRulesSupport;
302
+ if (!indentRulesSupport) {
303
+ return null;
304
+ }
305
+ const indentationContextProcessor = new IndentationContextProcessor(model, languageConfigurationService);
306
+ const processedContextTokens = indentationContextProcessor.getProcessedTokenContextAroundRange(range);
307
+ const beforeRangeText = processedContextTokens.beforeRangeProcessedTokens.getLineContent();
308
+ const afterRangeText = processedContextTokens.afterRangeProcessedTokens.getLineContent();
309
+ const textAroundRange = beforeRangeText + afterRangeText;
310
+ const textAroundRangeWithCharacter = beforeRangeText + ch + afterRangeText;
311
+ // If previous content already matches decreaseIndentPattern, it means indentation of this line should already be adjusted
312
+ // Users might change the indentation by purpose and we should honor that instead of readjusting.
313
+ if (!indentRulesSupport.shouldDecrease(textAroundRange) && indentRulesSupport.shouldDecrease(textAroundRangeWithCharacter)) {
314
+ // after typing `ch`, the content matches decreaseIndentPattern, we should adjust the indent to a good manner.
315
+ // 1. Get inherited indent action
316
+ const r = getInheritIndentForLine(autoIndent, model, range.startLineNumber, false, languageConfigurationService);
317
+ if (!r) {
318
+ return null;
319
+ }
320
+ let indentation = r.indentation;
321
+ if (r.action !== IndentAction.Indent) {
322
+ indentation = indentConverter.unshiftIndent(indentation);
323
+ }
324
+ return indentation;
325
+ }
326
+ const previousLineNumber = range.startLineNumber - 1;
327
+ if (previousLineNumber > 0) {
328
+ const previousLine = model.getLineContent(previousLineNumber);
329
+ if (indentRulesSupport.shouldIndentNextLine(previousLine) && indentRulesSupport.shouldIncrease(textAroundRangeWithCharacter)) {
330
+ const inheritedIndentationData = getInheritIndentForLine(autoIndent, model, range.startLineNumber, false, languageConfigurationService);
331
+ const inheritedIndentation = inheritedIndentationData?.indentation;
332
+ if (inheritedIndentation !== undefined) {
333
+ const currentLine = model.getLineContent(range.startLineNumber);
334
+ const actualCurrentIndentation = getLeadingWhitespace(currentLine);
335
+ const inferredCurrentIndentation = indentConverter.shiftIndent(inheritedIndentation);
336
+ // If the inferred current indentation is not equal to the actual current indentation, then the indentation has been intentionally changed, in that case keep it
337
+ const inferredIndentationEqualsActual = inferredCurrentIndentation === actualCurrentIndentation;
338
+ const textAroundRangeContainsOnlyWhitespace = /^\s*$/.test(textAroundRange);
339
+ const autoClosingPairs = cursorConfig.autoClosingPairs.autoClosingPairsOpenByEnd.get(ch);
340
+ const autoClosingPairExists = autoClosingPairs && autoClosingPairs.length > 0;
341
+ const isChFirstNonWhitespaceCharacterAndInAutoClosingPair = autoClosingPairExists && textAroundRangeContainsOnlyWhitespace;
342
+ if (inferredIndentationEqualsActual && isChFirstNonWhitespaceCharacterAndInAutoClosingPair) {
343
+ return inheritedIndentation;
344
+ }
345
+ }
346
+ }
347
+ }
348
+ return null;
349
+ }
350
+ function getIndentMetadata(model, lineNumber, languageConfigurationService) {
351
+ const indentRulesSupport = languageConfigurationService.getLanguageConfiguration(model.getLanguageId()).indentRulesSupport;
352
+ if (!indentRulesSupport) {
353
+ return null;
354
+ }
355
+ if (lineNumber < 1 || lineNumber > model.getLineCount()) {
356
+ return null;
357
+ }
358
+ return indentRulesSupport.getIndentMetadata(model.getLineContent(lineNumber));
359
+ }
360
+ function createVirtualModelWithModifiedTokensAtLine(model, modifiedLineNumber, modifiedTokens) {
361
+ const virtualModel = {
362
+ tokenization: {
363
+ getLineTokens: (lineNumber) => {
364
+ if (lineNumber === modifiedLineNumber) {
365
+ return modifiedTokens;
366
+ }
367
+ else {
368
+ return model.tokenization.getLineTokens(lineNumber);
369
+ }
370
+ },
371
+ getLanguageId: () => {
372
+ return model.getLanguageId();
373
+ },
374
+ getLanguageIdAtPosition: (lineNumber, column) => {
375
+ return model.getLanguageIdAtPosition(lineNumber, column);
376
+ },
377
+ },
378
+ getLineContent: (lineNumber) => {
379
+ if (lineNumber === modifiedLineNumber) {
380
+ return modifiedTokens.getLineContent();
381
+ }
382
+ else {
383
+ return model.getLineContent(lineNumber);
384
+ }
385
+ }
386
+ };
387
+ return virtualModel;
388
+ }
389
+
390
+ export { getGoodIndentForLine, getIndentActionForType, getIndentForEnter, getIndentMetadata, getInheritIndentForLine };
@@ -0,0 +1,110 @@
1
+ import { Range } from '../../../core/range.js';
2
+ import { positionToLength, lengthOfString, lengthToObj, lengthDiffNonNegative, toLength, lengthLessThanEqual, lengthAdd } from './length.js';
3
+
4
+ /*---------------------------------------------------------------------------------------------
5
+ * Copyright (c) Microsoft Corporation. All rights reserved.
6
+ * Licensed under the MIT License. See License.txt in the project root for license information.
7
+ *--------------------------------------------------------------------------------------------*/
8
+ class TextEditInfo {
9
+ static fromModelContentChanges(changes) {
10
+ // Must be sorted in ascending order
11
+ const edits = changes.map(c => {
12
+ const range = Range.lift(c.range);
13
+ return new TextEditInfo(positionToLength(range.getStartPosition()), positionToLength(range.getEndPosition()), lengthOfString(c.text));
14
+ }).reverse();
15
+ return edits;
16
+ }
17
+ constructor(startOffset, endOffset, newLength) {
18
+ this.startOffset = startOffset;
19
+ this.endOffset = endOffset;
20
+ this.newLength = newLength;
21
+ }
22
+ toString() {
23
+ return `[${lengthToObj(this.startOffset)}...${lengthToObj(this.endOffset)}) -> ${lengthToObj(this.newLength)}`;
24
+ }
25
+ }
26
+ class BeforeEditPositionMapper {
27
+ /**
28
+ * @param edits Must be sorted by offset in ascending order.
29
+ */
30
+ constructor(edits) {
31
+ this.nextEditIdx = 0;
32
+ this.deltaOldToNewLineCount = 0;
33
+ this.deltaOldToNewColumnCount = 0;
34
+ this.deltaLineIdxInOld = -1;
35
+ this.edits = edits.map(edit => TextEditInfoCache.from(edit));
36
+ }
37
+ /**
38
+ * @param offset Must be equal to or greater than the last offset this method has been called with.
39
+ */
40
+ getOffsetBeforeChange(offset) {
41
+ this.adjustNextEdit(offset);
42
+ return this.translateCurToOld(offset);
43
+ }
44
+ /**
45
+ * @param offset Must be equal to or greater than the last offset this method has been called with.
46
+ * Returns null if there is no edit anymore.
47
+ */
48
+ getDistanceToNextChange(offset) {
49
+ this.adjustNextEdit(offset);
50
+ const nextEdit = this.edits[this.nextEditIdx];
51
+ const nextChangeOffset = nextEdit ? this.translateOldToCur(nextEdit.offsetObj) : null;
52
+ if (nextChangeOffset === null) {
53
+ return null;
54
+ }
55
+ return lengthDiffNonNegative(offset, nextChangeOffset);
56
+ }
57
+ translateOldToCur(oldOffsetObj) {
58
+ if (oldOffsetObj.lineCount === this.deltaLineIdxInOld) {
59
+ return toLength(oldOffsetObj.lineCount + this.deltaOldToNewLineCount, oldOffsetObj.columnCount + this.deltaOldToNewColumnCount);
60
+ }
61
+ else {
62
+ return toLength(oldOffsetObj.lineCount + this.deltaOldToNewLineCount, oldOffsetObj.columnCount);
63
+ }
64
+ }
65
+ translateCurToOld(newOffset) {
66
+ const offsetObj = lengthToObj(newOffset);
67
+ if (offsetObj.lineCount - this.deltaOldToNewLineCount === this.deltaLineIdxInOld) {
68
+ return toLength(offsetObj.lineCount - this.deltaOldToNewLineCount, offsetObj.columnCount - this.deltaOldToNewColumnCount);
69
+ }
70
+ else {
71
+ return toLength(offsetObj.lineCount - this.deltaOldToNewLineCount, offsetObj.columnCount);
72
+ }
73
+ }
74
+ adjustNextEdit(offset) {
75
+ while (this.nextEditIdx < this.edits.length) {
76
+ const nextEdit = this.edits[this.nextEditIdx];
77
+ // After applying the edit, what is its end offset (considering all previous edits)?
78
+ const nextEditEndOffsetInCur = this.translateOldToCur(nextEdit.endOffsetAfterObj);
79
+ if (lengthLessThanEqual(nextEditEndOffsetInCur, offset)) {
80
+ // We are after the edit, skip it
81
+ this.nextEditIdx++;
82
+ const nextEditEndOffsetInCurObj = lengthToObj(nextEditEndOffsetInCur);
83
+ // Before applying the edit, what is its end offset (considering all previous edits)?
84
+ const nextEditEndOffsetBeforeInCurObj = lengthToObj(this.translateOldToCur(nextEdit.endOffsetBeforeObj));
85
+ const lineDelta = nextEditEndOffsetInCurObj.lineCount - nextEditEndOffsetBeforeInCurObj.lineCount;
86
+ this.deltaOldToNewLineCount += lineDelta;
87
+ const previousColumnDelta = this.deltaLineIdxInOld === nextEdit.endOffsetBeforeObj.lineCount ? this.deltaOldToNewColumnCount : 0;
88
+ const columnDelta = nextEditEndOffsetInCurObj.columnCount - nextEditEndOffsetBeforeInCurObj.columnCount;
89
+ this.deltaOldToNewColumnCount = previousColumnDelta + columnDelta;
90
+ this.deltaLineIdxInOld = nextEdit.endOffsetBeforeObj.lineCount;
91
+ }
92
+ else {
93
+ // We are in or before the edit.
94
+ break;
95
+ }
96
+ }
97
+ }
98
+ }
99
+ class TextEditInfoCache {
100
+ static from(edit) {
101
+ return new TextEditInfoCache(edit.startOffset, edit.endOffset, edit.newLength);
102
+ }
103
+ constructor(startOffset, endOffset, textLength) {
104
+ this.endOffsetBeforeObj = lengthToObj(endOffset);
105
+ this.endOffsetAfterObj = lengthToObj(lengthAdd(startOffset, textLength));
106
+ this.offsetObj = lengthToObj(startOffset);
107
+ }
108
+ }
109
+
110
+ export { BeforeEditPositionMapper, TextEditInfo };