monaco-editor11 1.0.7 → 1.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/css.worker-C7FogG4G.js +93 -0
- package/dist/assets/editor.worker-iXcRX1Tq.js +26 -0
- package/dist/assets/html.worker-C8VxctEJ.js +470 -0
- package/dist/assets/json.worker-CMC9kgPL.js +58 -0
- package/dist/assets/ts.worker-CtTJ3hNN.js +67731 -0
- package/dist/index.d.ts +0 -6
- package/dist/monaco-editor11.es.js +49 -78
- package/dist/monaco-editor11.umd.js +1 -50
- package/dist/monaco.d.ts +8 -0
- package/dist/workers/common/initialize.js +16 -0
- package/dist/workers/common/workers.js +141 -0
- package/dist/workers/editor/common/abstractSyntaxTokenBackend.js +128 -0
- package/dist/workers/editor/common/abstractText.js +89 -0
- package/dist/workers/editor/common/ast.js +485 -0
- package/dist/workers/editor/common/autoIndent.js +390 -0
- package/dist/workers/editor/common/beforeEditPositionMapper.js +110 -0
- package/dist/workers/editor/common/bracketPairsImpl.js +717 -0
- package/dist/workers/editor/common/bracketPairsTree.js +343 -0
- package/dist/workers/editor/common/brackets.js +108 -0
- package/dist/workers/editor/common/characterClassifier.js +59 -0
- package/dist/workers/editor/common/characterPair.js +40 -0
- package/dist/workers/editor/common/colorizedBracketPairsDecorationProvider.js +97 -0
- package/dist/workers/editor/common/columnRange.js +35 -0
- package/dist/workers/editor/common/combineTextEditInfos.js +124 -0
- package/dist/workers/editor/common/common.js +20 -0
- package/dist/workers/editor/common/computeMovedLines.js +249 -0
- package/dist/workers/editor/common/concat23Trees.js +192 -0
- package/dist/workers/editor/common/contiguousMultilineTokens.js +32 -0
- package/dist/workers/editor/common/contiguousMultilineTokensBuilder.js +23 -0
- package/dist/workers/editor/common/contiguousTokensEditing.js +128 -0
- package/dist/workers/editor/common/contiguousTokensStore.js +207 -0
- package/dist/workers/editor/common/coordinatesConverter.js +51 -0
- package/dist/workers/editor/common/cursor.js +899 -0
- package/dist/workers/editor/common/cursorAtomicMoveOperations.js +145 -0
- package/dist/workers/editor/common/cursorCollection.js +194 -0
- package/dist/workers/editor/common/cursorColumnSelection.js +93 -0
- package/dist/workers/editor/common/cursorColumns.js +112 -0
- package/dist/workers/editor/common/cursorCommon.js +250 -0
- package/dist/workers/editor/common/cursorContext.js +15 -0
- package/dist/workers/editor/common/cursorDeleteOperations.js +231 -0
- package/dist/workers/editor/common/cursorMoveCommands.js +676 -0
- package/dist/workers/editor/common/cursorMoveOperations.js +290 -0
- package/dist/workers/editor/common/cursorTypeEditOperations.js +968 -0
- package/dist/workers/editor/common/cursorTypeOperations.js +173 -0
- package/dist/workers/editor/common/cursorUtils.js +75 -0
- package/dist/workers/editor/common/cursorWordOperations.js +720 -0
- package/dist/workers/editor/common/defaultDocumentColorsComputer.js +138 -0
- package/dist/workers/editor/common/defaultLinesDiffComputer.js +188 -0
- package/dist/workers/editor/common/diffAlgorithm.js +139 -0
- package/dist/workers/editor/common/diffEditor.js +38 -0
- package/dist/workers/editor/common/dynamicProgrammingDiffing.js +101 -0
- package/dist/workers/editor/common/edit.js +183 -0
- package/dist/workers/editor/common/editOperation.js +36 -0
- package/dist/workers/editor/common/editStack.js +363 -0
- package/dist/workers/editor/common/editorAction.js +26 -0
- package/dist/workers/editor/common/editorBaseApi.js +43 -0
- package/dist/workers/editor/common/editorColorRegistry.js +102 -0
- package/dist/workers/editor/common/editorCommon.js +13 -0
- package/dist/workers/editor/common/editorConfigurationSchema.js +338 -0
- package/dist/workers/editor/common/editorContextKeys.js +84 -0
- package/dist/workers/editor/common/editorFeatures.js +17 -0
- package/dist/workers/editor/common/editorOptions.js +3440 -0
- package/dist/workers/editor/common/editorTheme.js +23 -0
- package/dist/workers/editor/common/editorWebWorker.js +299 -0
- package/dist/workers/editor/common/editorWorker.js +9 -0
- package/dist/workers/editor/common/editorWorkerHost.js +15 -0
- package/dist/workers/editor/common/editorZoom.js +26 -0
- package/dist/workers/editor/common/electricCharacter.js +55 -0
- package/dist/workers/editor/common/encodedTokenAttributes.js +79 -0
- package/dist/workers/editor/common/enterAction.js +53 -0
- package/dist/workers/editor/common/eolCounter.js +44 -0
- package/dist/workers/editor/common/findSectionHeaders.js +128 -0
- package/dist/workers/editor/common/fixBrackets.js +67 -0
- package/dist/workers/editor/common/fixedArray.js +70 -0
- package/dist/workers/editor/common/fontInfo.js +172 -0
- package/dist/workers/editor/common/fontInfoFromSettings.js +29 -0
- package/dist/workers/editor/common/getIconClasses.js +106 -0
- package/dist/workers/editor/common/getPositionOffsetTransformerFromTextModel.js +24 -0
- package/dist/workers/editor/common/glyphLanesModel.js +61 -0
- package/dist/workers/editor/common/guidesTextModelPart.js +405 -0
- package/dist/workers/editor/common/heuristicSequenceOptimizations.js +374 -0
- package/dist/workers/editor/common/indentRules.js +63 -0
- package/dist/workers/editor/common/indentation.js +39 -0
- package/dist/workers/editor/common/indentationGuesser.js +178 -0
- package/dist/workers/editor/common/indentationLineProcessor.js +193 -0
- package/dist/workers/editor/common/inlineDecorations.js +26 -0
- package/dist/workers/editor/common/inplaceReplaceSupport.js +87 -0
- package/dist/workers/editor/common/inputMode.js +22 -0
- package/dist/workers/editor/common/intervalTree.js +1002 -0
- package/dist/workers/editor/common/language.js +9 -0
- package/dist/workers/editor/common/languageBracketsConfiguration.js +133 -0
- package/dist/workers/editor/common/languageConfiguration.js +138 -0
- package/dist/workers/editor/common/languageConfigurationRegistry.js +361 -0
- package/dist/workers/editor/common/languageFeatureDebounce.js +137 -0
- package/dist/workers/editor/common/languageFeatureRegistry.js +180 -0
- package/dist/workers/editor/common/languageFeatures.js +9 -0
- package/dist/workers/editor/common/languageFeaturesService.js +47 -0
- package/dist/workers/editor/common/languageSelector.js +112 -0
- package/dist/workers/editor/common/languageService.js +92 -0
- package/dist/workers/editor/common/languages.js +522 -0
- package/dist/workers/editor/common/languagesAssociations.js +193 -0
- package/dist/workers/editor/common/languagesRegistry.js +237 -0
- package/dist/workers/editor/common/legacyLinesDiffComputer.js +468 -0
- package/dist/workers/editor/common/length.js +129 -0
- package/dist/workers/editor/common/lineDecorations.js +208 -0
- package/dist/workers/editor/common/lineEdit.js +75 -0
- package/dist/workers/editor/common/lineHeights.js +370 -0
- package/dist/workers/editor/common/linePart.js +25 -0
- package/dist/workers/editor/common/lineRange.js +312 -0
- package/dist/workers/editor/common/lineSequence.js +36 -0
- package/dist/workers/editor/common/lineTokens.js +405 -0
- package/dist/workers/editor/common/linesDiffComputer.js +29 -0
- package/dist/workers/editor/common/linesDiffComputers.js +13 -0
- package/dist/workers/editor/common/linesLayout.js +765 -0
- package/dist/workers/editor/common/linesSliceCharSequence.js +205 -0
- package/dist/workers/editor/common/linkComputer.js +269 -0
- package/dist/workers/editor/common/markerDecorations.js +9 -0
- package/dist/workers/editor/common/markerDecorationsService.js +248 -0
- package/dist/workers/editor/common/minimapTokensColorTracker.js +58 -0
- package/dist/workers/editor/common/mirrorTextModel.js +117 -0
- package/dist/workers/editor/common/model.js +9 -0
- package/dist/workers/editor/common/modelLineProjection.js +350 -0
- package/dist/workers/editor/common/modelLineProjectionData.js +297 -0
- package/dist/workers/editor/common/modelService.js +413 -0
- package/dist/workers/editor/common/modesRegistry.js +75 -0
- package/dist/workers/editor/common/monospaceLineBreaksComputer.js +473 -0
- package/dist/workers/editor/common/myersDiffAlgorithm.js +159 -0
- package/dist/workers/editor/common/nodeReader.js +127 -0
- package/dist/workers/editor/common/nullTokenize.js +29 -0
- package/dist/workers/editor/common/offsetRange.js +225 -0
- package/dist/workers/editor/common/onEnter.js +109 -0
- package/dist/workers/editor/common/oneCursor.js +117 -0
- package/dist/workers/editor/common/overviewZoneManager.js +176 -0
- package/dist/workers/editor/common/parser.js +121 -0
- package/dist/workers/editor/common/pieceTreeBase.js +1473 -0
- package/dist/workers/editor/common/pieceTreeTextBuffer.js +461 -0
- package/dist/workers/editor/common/pieceTreeTextBufferBuilder.js +140 -0
- package/dist/workers/editor/common/point.js +50 -0
- package/dist/workers/editor/common/position.js +142 -0
- package/dist/workers/editor/common/positionToOffset.js +17 -0
- package/dist/workers/editor/common/positionToOffsetImpl.js +98 -0
- package/dist/workers/editor/common/prefixSumComputer.js +226 -0
- package/dist/workers/editor/common/range.js +421 -0
- package/dist/workers/editor/common/rangeMapping.js +229 -0
- package/dist/workers/editor/common/rangeSingleLine.js +17 -0
- package/dist/workers/editor/common/rbTreeBase.js +362 -0
- package/dist/workers/editor/common/rect.js +163 -0
- package/dist/workers/editor/common/replaceCommand.js +158 -0
- package/dist/workers/editor/common/resolverService.js +5 -0
- package/dist/workers/editor/common/rgba.js +35 -0
- package/dist/workers/editor/common/richEditBrackets.js +356 -0
- package/dist/workers/editor/common/selection.js +145 -0
- package/dist/workers/editor/common/semanticTokensDto.js +82 -0
- package/dist/workers/editor/common/semanticTokensProviderStyling.js +263 -0
- package/dist/workers/editor/common/semanticTokensStyling.js +9 -0
- package/dist/workers/editor/common/semanticTokensStylingService.js +47 -0
- package/dist/workers/editor/common/shiftCommand.js +241 -0
- package/dist/workers/editor/common/smallImmutableSet.js +108 -0
- package/dist/workers/editor/common/sparseMultilineTokens.js +548 -0
- package/dist/workers/editor/common/sparseTokensStore.js +210 -0
- package/dist/workers/editor/common/standaloneEnums.js +1017 -0
- package/dist/workers/editor/common/standaloneStrings.js +42 -0
- package/dist/workers/editor/common/stringBuilder.js +122 -0
- package/dist/workers/editor/common/stringEdit.js +165 -0
- package/dist/workers/editor/common/supports.js +58 -0
- package/dist/workers/editor/common/surroundSelectionCommand.js +44 -0
- package/dist/workers/editor/common/textChange.js +248 -0
- package/dist/workers/editor/common/textEdit.js +269 -0
- package/dist/workers/editor/common/textLength.js +87 -0
- package/dist/workers/editor/common/textModel.js +2031 -0
- package/dist/workers/editor/common/textModelBracketPairs.js +45 -0
- package/dist/workers/editor/common/textModelDefaults.js +18 -0
- package/dist/workers/editor/common/textModelEditSource.js +166 -0
- package/dist/workers/editor/common/textModelEvents.js +216 -0
- package/dist/workers/editor/common/textModelGuides.js +40 -0
- package/dist/workers/editor/common/textModelPart.js +23 -0
- package/dist/workers/editor/common/textModelSearch.js +455 -0
- package/dist/workers/editor/common/textModelStringEdit.js +11 -0
- package/dist/workers/editor/common/textModelSync.impl.js +307 -0
- package/dist/workers/editor/common/textModelText.js +26 -0
- package/dist/workers/editor/common/textModelTokens.js +436 -0
- package/dist/workers/editor/common/textResourceConfiguration.js +6 -0
- package/dist/workers/editor/common/textToHtmlTokenizer.js +139 -0
- package/dist/workers/editor/common/tokenStore.js +407 -0
- package/dist/workers/editor/common/tokenWithTextArray.js +73 -0
- package/dist/workers/editor/common/tokenization.js +287 -0
- package/dist/workers/editor/common/tokenizationRegistry.js +123 -0
- package/dist/workers/editor/common/tokenizationTextModelPart.js +275 -0
- package/dist/workers/editor/common/tokenizer.js +301 -0
- package/dist/workers/editor/common/tokenizerSyntaxTokenBackend.js +261 -0
- package/dist/workers/editor/common/treeSitterLibraryService.js +9 -0
- package/dist/workers/editor/common/treeSitterSyntaxTokenBackend.js +167 -0
- package/dist/workers/editor/common/treeSitterThemeService.js +9 -0
- package/dist/workers/editor/common/treeSitterTokenizationImpl.js +713 -0
- package/dist/workers/editor/common/treeSitterTree.js +395 -0
- package/dist/workers/editor/common/treeViewsDnd.js +24 -0
- package/dist/workers/editor/common/treeViewsDndService.js +12 -0
- package/dist/workers/editor/common/trimTrailingWhitespaceCommand.js +98 -0
- package/dist/workers/editor/common/unicodeTextModelHighlighter.js +188 -0
- package/dist/workers/editor/common/utils.js +62 -0
- package/dist/workers/editor/common/viewContext.js +22 -0
- package/dist/workers/editor/common/viewEventHandler.js +186 -0
- package/dist/workers/editor/common/viewEvents.js +180 -0
- package/dist/workers/editor/common/viewLayout.js +368 -0
- package/dist/workers/editor/common/viewLineRenderer.js +948 -0
- package/dist/workers/editor/common/viewLinesViewportData.js +30 -0
- package/dist/workers/editor/common/viewModel.js +98 -0
- package/dist/workers/editor/common/viewModelDecoration.js +55 -0
- package/dist/workers/editor/common/viewModelDecorations.js +132 -0
- package/dist/workers/editor/common/viewModelEventDispatcher.js +398 -0
- package/dist/workers/editor/common/viewModelImpl.js +1163 -0
- package/dist/workers/editor/common/viewModelLines.js +938 -0
- package/dist/workers/editor/common/wordCharacterClassifier.js +87 -0
- package/dist/workers/editor/common/wordHelper.js +127 -0
- package/dist/workers/editor/editor.worker.js +11 -0
- package/dist/workers/language/css.worker.js +8 -0
- package/dist/workers/language/cssMode.js +198 -0
- package/dist/workers/language/cssWorker.js +183 -0
- package/dist/workers/language/html.worker.js +8 -0
- package/dist/workers/language/htmlMode.js +213 -0
- package/dist/workers/language/htmlWorker.js +126 -0
- package/dist/workers/language/json.worker.js +8 -0
- package/dist/workers/language/jsonMode.js +224 -0
- package/dist/workers/language/jsonWorker.js +187 -0
- package/dist/workers/language/languageFeatures.js +1009 -0
- package/dist/workers/language/lib.index.js +103 -0
- package/dist/workers/language/lib.js +1107 -0
- package/dist/workers/language/lspLanguageFeatures.js +716 -0
- package/dist/workers/language/monaco.contribution.js +144 -0
- package/dist/workers/language/tokenization.js +189 -0
- package/dist/workers/language/ts.worker.js +14 -0
- package/dist/workers/language/tsMode.js +212 -0
- package/dist/workers/language/tsWorker.js +352 -0
- package/dist/workers/language/typescriptServices.js +210154 -0
- package/dist/workers/language/typescriptServicesMetadata.js +3 -0
- package/dist/workers/language/workerManager.js +65 -0
- package/package.json +3 -2
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { Color, HSLA } from '../../../base/common/color.js';
|
|
2
|
+
|
|
3
|
+
/*---------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
5
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
6
|
+
*--------------------------------------------------------------------------------------------*/
|
|
7
|
+
function _parseCaptureGroups(captureGroups) {
|
|
8
|
+
const values = [];
|
|
9
|
+
for (const captureGroup of captureGroups) {
|
|
10
|
+
const parsedNumber = Number(captureGroup);
|
|
11
|
+
if (parsedNumber || parsedNumber === 0 && captureGroup.replace(/\s/g, '') !== '') {
|
|
12
|
+
values.push(parsedNumber);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return values;
|
|
16
|
+
}
|
|
17
|
+
function _toIColor(r, g, b, a) {
|
|
18
|
+
return {
|
|
19
|
+
red: r / 255,
|
|
20
|
+
blue: b / 255,
|
|
21
|
+
green: g / 255,
|
|
22
|
+
alpha: a
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function _findRange(model, match) {
|
|
26
|
+
const index = match.index;
|
|
27
|
+
const length = match[0].length;
|
|
28
|
+
if (index === undefined) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const startPosition = model.positionAt(index);
|
|
32
|
+
const range = {
|
|
33
|
+
startLineNumber: startPosition.lineNumber,
|
|
34
|
+
startColumn: startPosition.column,
|
|
35
|
+
endLineNumber: startPosition.lineNumber,
|
|
36
|
+
endColumn: startPosition.column + length
|
|
37
|
+
};
|
|
38
|
+
return range;
|
|
39
|
+
}
|
|
40
|
+
function _findHexColorInformation(range, hexValue) {
|
|
41
|
+
if (!range) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const parsedHexColor = Color.Format.CSS.parseHex(hexValue);
|
|
45
|
+
if (!parsedHexColor) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
range: range,
|
|
50
|
+
color: _toIColor(parsedHexColor.rgba.r, parsedHexColor.rgba.g, parsedHexColor.rgba.b, parsedHexColor.rgba.a)
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function _findRGBColorInformation(range, matches, isAlpha) {
|
|
54
|
+
if (!range || matches.length !== 1) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const match = matches[0];
|
|
58
|
+
const captureGroups = match.values();
|
|
59
|
+
const parsedRegex = _parseCaptureGroups(captureGroups);
|
|
60
|
+
return {
|
|
61
|
+
range: range,
|
|
62
|
+
color: _toIColor(parsedRegex[0], parsedRegex[1], parsedRegex[2], isAlpha ? parsedRegex[3] : 1)
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function _findHSLColorInformation(range, matches, isAlpha) {
|
|
66
|
+
if (!range || matches.length !== 1) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const match = matches[0];
|
|
70
|
+
const captureGroups = match.values();
|
|
71
|
+
const parsedRegex = _parseCaptureGroups(captureGroups);
|
|
72
|
+
const colorEquivalent = new Color(new HSLA(parsedRegex[0], parsedRegex[1] / 100, parsedRegex[2] / 100, isAlpha ? parsedRegex[3] : 1));
|
|
73
|
+
return {
|
|
74
|
+
range: range,
|
|
75
|
+
color: _toIColor(colorEquivalent.rgba.r, colorEquivalent.rgba.g, colorEquivalent.rgba.b, colorEquivalent.rgba.a)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function _findMatches(model, regex) {
|
|
79
|
+
if (typeof model === 'string') {
|
|
80
|
+
return [...model.matchAll(regex)];
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
return model.findMatches(regex);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function computeColors(model) {
|
|
87
|
+
const result = [];
|
|
88
|
+
// Early validation for RGB and HSL
|
|
89
|
+
const initialValidationRegex = /\b(rgb|rgba|hsl|hsla)(\([0-9\s,.\%]*\))|^(#)([A-Fa-f0-9]{3})\b|^(#)([A-Fa-f0-9]{4})\b|^(#)([A-Fa-f0-9]{6})\b|^(#)([A-Fa-f0-9]{8})\b|(?<=['"\s])(#)([A-Fa-f0-9]{3})\b|(?<=['"\s])(#)([A-Fa-f0-9]{4})\b|(?<=['"\s])(#)([A-Fa-f0-9]{6})\b|(?<=['"\s])(#)([A-Fa-f0-9]{8})\b/gm;
|
|
90
|
+
const initialValidationMatches = _findMatches(model, initialValidationRegex);
|
|
91
|
+
// Potential colors have been found, validate the parameters
|
|
92
|
+
if (initialValidationMatches.length > 0) {
|
|
93
|
+
for (const initialMatch of initialValidationMatches) {
|
|
94
|
+
const initialCaptureGroups = initialMatch.filter(captureGroup => captureGroup !== undefined);
|
|
95
|
+
const colorScheme = initialCaptureGroups[1];
|
|
96
|
+
const colorParameters = initialCaptureGroups[2];
|
|
97
|
+
if (!colorParameters) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
let colorInformation;
|
|
101
|
+
if (colorScheme === 'rgb') {
|
|
102
|
+
const regexParameters = /^\(\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*,\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*,\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*\)$/gm;
|
|
103
|
+
colorInformation = _findRGBColorInformation(_findRange(model, initialMatch), _findMatches(colorParameters, regexParameters), false);
|
|
104
|
+
}
|
|
105
|
+
else if (colorScheme === 'rgba') {
|
|
106
|
+
const regexParameters = /^\(\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*,\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*,\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\s*,\s*(0[.][0-9]+|[.][0-9]+|[01][.]|[01])\s*\)$/gm;
|
|
107
|
+
colorInformation = _findRGBColorInformation(_findRange(model, initialMatch), _findMatches(colorParameters, regexParameters), true);
|
|
108
|
+
}
|
|
109
|
+
else if (colorScheme === 'hsl') {
|
|
110
|
+
const regexParameters = /^\(\s*((?:360(?:\.0+)?|(?:36[0]|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9])(?:\.\d+)?))\s*[\s,]\s*(100|\d{1,2}[.]\d*|\d{1,2})%\s*[\s,]\s*(100|\d{1,2}[.]\d*|\d{1,2})%\s*\)$/gm;
|
|
111
|
+
colorInformation = _findHSLColorInformation(_findRange(model, initialMatch), _findMatches(colorParameters, regexParameters), false);
|
|
112
|
+
}
|
|
113
|
+
else if (colorScheme === 'hsla') {
|
|
114
|
+
const regexParameters = /^\(\s*((?:360(?:\.0+)?|(?:36[0]|3[0-5][0-9]|[12][0-9][0-9]|[1-9]?[0-9])(?:\.\d+)?))\s*[\s,]\s*(100|\d{1,2}[.]\d*|\d{1,2})%\s*[\s,]\s*(100|\d{1,2}[.]\d*|\d{1,2})%\s*[\s,]\s*(0[.][0-9]+|[.][0-9]+|[01][.]0*|[01])\s*\)$/gm;
|
|
115
|
+
colorInformation = _findHSLColorInformation(_findRange(model, initialMatch), _findMatches(colorParameters, regexParameters), true);
|
|
116
|
+
}
|
|
117
|
+
else if (colorScheme === '#') {
|
|
118
|
+
colorInformation = _findHexColorInformation(_findRange(model, initialMatch), colorScheme + colorParameters);
|
|
119
|
+
}
|
|
120
|
+
if (colorInformation) {
|
|
121
|
+
result.push(colorInformation);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Returns an array of all default document colors in the provided document
|
|
129
|
+
*/
|
|
130
|
+
function computeDefaultDocumentColors(model) {
|
|
131
|
+
if (!model || typeof model.getValue !== 'function' || typeof model.positionAt !== 'function') {
|
|
132
|
+
// Unknown caller!
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
return computeColors(model);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export { computeDefaultDocumentColors };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { equals } from '../../../../base/common/arrays.js';
|
|
2
|
+
import { assertFn } from '../../../../base/common/assert.js';
|
|
3
|
+
import { LineRange } from '../../core/ranges/lineRange.js';
|
|
4
|
+
import { OffsetRange } from '../../core/ranges/offsetRange.js';
|
|
5
|
+
import { Range } from '../../core/range.js';
|
|
6
|
+
import { ArrayText } from '../../core/text/abstractText.js';
|
|
7
|
+
import { LinesDiff, MovedText } from '../linesDiffComputer.js';
|
|
8
|
+
import { DetailedLineRangeMapping, RangeMapping, lineRangeMappingFromRangeMappings, LineRangeMapping } from '../rangeMapping.js';
|
|
9
|
+
import { InfiniteTimeout, DateTimeout, SequenceDiff } from './algorithms/diffAlgorithm.js';
|
|
10
|
+
import { DynamicProgrammingDiffing } from './algorithms/dynamicProgrammingDiffing.js';
|
|
11
|
+
import { MyersDiffAlgorithm } from './algorithms/myersDiffAlgorithm.js';
|
|
12
|
+
import { computeMovedLines } from './computeMovedLines.js';
|
|
13
|
+
import { optimizeSequenceDiffs, removeVeryShortMatchingLinesBetweenDiffs, extendDiffsToEntireWordIfAppropriate, removeShortMatches, removeVeryShortMatchingTextBetweenLongDiffs } from './heuristicSequenceOptimizations.js';
|
|
14
|
+
import { LineSequence } from './lineSequence.js';
|
|
15
|
+
import { LinesSliceCharSequence } from './linesSliceCharSequence.js';
|
|
16
|
+
|
|
17
|
+
/*---------------------------------------------------------------------------------------------
|
|
18
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
19
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
20
|
+
*--------------------------------------------------------------------------------------------*/
|
|
21
|
+
class DefaultLinesDiffComputer {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.dynamicProgrammingDiffing = new DynamicProgrammingDiffing();
|
|
24
|
+
this.myersDiffingAlgorithm = new MyersDiffAlgorithm();
|
|
25
|
+
}
|
|
26
|
+
computeDiff(originalLines, modifiedLines, options) {
|
|
27
|
+
if (originalLines.length <= 1 && equals(originalLines, modifiedLines, (a, b) => a === b)) {
|
|
28
|
+
return new LinesDiff([], [], false);
|
|
29
|
+
}
|
|
30
|
+
if (originalLines.length === 1 && originalLines[0].length === 0 || modifiedLines.length === 1 && modifiedLines[0].length === 0) {
|
|
31
|
+
return new LinesDiff([
|
|
32
|
+
new DetailedLineRangeMapping(new LineRange(1, originalLines.length + 1), new LineRange(1, modifiedLines.length + 1), [
|
|
33
|
+
new RangeMapping(new Range(1, 1, originalLines.length, originalLines[originalLines.length - 1].length + 1), new Range(1, 1, modifiedLines.length, modifiedLines[modifiedLines.length - 1].length + 1))
|
|
34
|
+
])
|
|
35
|
+
], [], false);
|
|
36
|
+
}
|
|
37
|
+
const timeout = options.maxComputationTimeMs === 0 ? InfiniteTimeout.instance : new DateTimeout(options.maxComputationTimeMs);
|
|
38
|
+
const considerWhitespaceChanges = !options.ignoreTrimWhitespace;
|
|
39
|
+
const perfectHashes = new Map();
|
|
40
|
+
function getOrCreateHash(text) {
|
|
41
|
+
let hash = perfectHashes.get(text);
|
|
42
|
+
if (hash === undefined) {
|
|
43
|
+
hash = perfectHashes.size;
|
|
44
|
+
perfectHashes.set(text, hash);
|
|
45
|
+
}
|
|
46
|
+
return hash;
|
|
47
|
+
}
|
|
48
|
+
const originalLinesHashes = originalLines.map((l) => getOrCreateHash(l.trim()));
|
|
49
|
+
const modifiedLinesHashes = modifiedLines.map((l) => getOrCreateHash(l.trim()));
|
|
50
|
+
const sequence1 = new LineSequence(originalLinesHashes, originalLines);
|
|
51
|
+
const sequence2 = new LineSequence(modifiedLinesHashes, modifiedLines);
|
|
52
|
+
const lineAlignmentResult = (() => {
|
|
53
|
+
if (sequence1.length + sequence2.length < 1700) {
|
|
54
|
+
// Use the improved algorithm for small files
|
|
55
|
+
return this.dynamicProgrammingDiffing.compute(sequence1, sequence2, timeout, (offset1, offset2) => originalLines[offset1] === modifiedLines[offset2]
|
|
56
|
+
? modifiedLines[offset2].length === 0
|
|
57
|
+
? 0.1
|
|
58
|
+
: 1 + Math.log(1 + modifiedLines[offset2].length)
|
|
59
|
+
: 0.99);
|
|
60
|
+
}
|
|
61
|
+
return this.myersDiffingAlgorithm.compute(sequence1, sequence2, timeout);
|
|
62
|
+
})();
|
|
63
|
+
let lineAlignments = lineAlignmentResult.diffs;
|
|
64
|
+
let hitTimeout = lineAlignmentResult.hitTimeout;
|
|
65
|
+
lineAlignments = optimizeSequenceDiffs(sequence1, sequence2, lineAlignments);
|
|
66
|
+
lineAlignments = removeVeryShortMatchingLinesBetweenDiffs(sequence1, sequence2, lineAlignments);
|
|
67
|
+
const alignments = [];
|
|
68
|
+
const scanForWhitespaceChanges = (equalLinesCount) => {
|
|
69
|
+
if (!considerWhitespaceChanges) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
for (let i = 0; i < equalLinesCount; i++) {
|
|
73
|
+
const seq1Offset = seq1LastStart + i;
|
|
74
|
+
const seq2Offset = seq2LastStart + i;
|
|
75
|
+
if (originalLines[seq1Offset] !== modifiedLines[seq2Offset]) {
|
|
76
|
+
// This is because of whitespace changes, diff these lines
|
|
77
|
+
const characterDiffs = this.refineDiff(originalLines, modifiedLines, new SequenceDiff(new OffsetRange(seq1Offset, seq1Offset + 1), new OffsetRange(seq2Offset, seq2Offset + 1)), timeout, considerWhitespaceChanges, options);
|
|
78
|
+
for (const a of characterDiffs.mappings) {
|
|
79
|
+
alignments.push(a);
|
|
80
|
+
}
|
|
81
|
+
if (characterDiffs.hitTimeout) {
|
|
82
|
+
hitTimeout = true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
let seq1LastStart = 0;
|
|
88
|
+
let seq2LastStart = 0;
|
|
89
|
+
for (const diff of lineAlignments) {
|
|
90
|
+
assertFn(() => diff.seq1Range.start - seq1LastStart === diff.seq2Range.start - seq2LastStart);
|
|
91
|
+
const equalLinesCount = diff.seq1Range.start - seq1LastStart;
|
|
92
|
+
scanForWhitespaceChanges(equalLinesCount);
|
|
93
|
+
seq1LastStart = diff.seq1Range.endExclusive;
|
|
94
|
+
seq2LastStart = diff.seq2Range.endExclusive;
|
|
95
|
+
const characterDiffs = this.refineDiff(originalLines, modifiedLines, diff, timeout, considerWhitespaceChanges, options);
|
|
96
|
+
if (characterDiffs.hitTimeout) {
|
|
97
|
+
hitTimeout = true;
|
|
98
|
+
}
|
|
99
|
+
for (const a of characterDiffs.mappings) {
|
|
100
|
+
alignments.push(a);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
scanForWhitespaceChanges(originalLines.length - seq1LastStart);
|
|
104
|
+
const original = new ArrayText(originalLines);
|
|
105
|
+
const modified = new ArrayText(modifiedLines);
|
|
106
|
+
const changes = lineRangeMappingFromRangeMappings(alignments, original, modified);
|
|
107
|
+
let moves = [];
|
|
108
|
+
if (options.computeMoves) {
|
|
109
|
+
moves = this.computeMoves(changes, originalLines, modifiedLines, originalLinesHashes, modifiedLinesHashes, timeout, considerWhitespaceChanges, options);
|
|
110
|
+
}
|
|
111
|
+
// Make sure all ranges are valid
|
|
112
|
+
assertFn(() => {
|
|
113
|
+
function validatePosition(pos, lines) {
|
|
114
|
+
if (pos.lineNumber < 1 || pos.lineNumber > lines.length) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
const line = lines[pos.lineNumber - 1];
|
|
118
|
+
if (pos.column < 1 || pos.column > line.length + 1) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
function validateRange(range, lines) {
|
|
124
|
+
if (range.startLineNumber < 1 || range.startLineNumber > lines.length + 1) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
if (range.endLineNumberExclusive < 1 || range.endLineNumberExclusive > lines.length + 1) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
for (const c of changes) {
|
|
133
|
+
if (!c.innerChanges) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
for (const ic of c.innerChanges) {
|
|
137
|
+
const valid = validatePosition(ic.modifiedRange.getStartPosition(), modifiedLines) && validatePosition(ic.modifiedRange.getEndPosition(), modifiedLines) &&
|
|
138
|
+
validatePosition(ic.originalRange.getStartPosition(), originalLines) && validatePosition(ic.originalRange.getEndPosition(), originalLines);
|
|
139
|
+
if (!valid) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!validateRange(c.modified, modifiedLines) || !validateRange(c.original, originalLines)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
});
|
|
149
|
+
return new LinesDiff(changes, moves, hitTimeout);
|
|
150
|
+
}
|
|
151
|
+
computeMoves(changes, originalLines, modifiedLines, hashedOriginalLines, hashedModifiedLines, timeout, considerWhitespaceChanges, options) {
|
|
152
|
+
const moves = computeMovedLines(changes, originalLines, modifiedLines, hashedOriginalLines, hashedModifiedLines, timeout);
|
|
153
|
+
const movesWithDiffs = moves.map(m => {
|
|
154
|
+
const moveChanges = this.refineDiff(originalLines, modifiedLines, new SequenceDiff(m.original.toOffsetRange(), m.modified.toOffsetRange()), timeout, considerWhitespaceChanges, options);
|
|
155
|
+
const mappings = lineRangeMappingFromRangeMappings(moveChanges.mappings, new ArrayText(originalLines), new ArrayText(modifiedLines), true);
|
|
156
|
+
return new MovedText(m, mappings);
|
|
157
|
+
});
|
|
158
|
+
return movesWithDiffs;
|
|
159
|
+
}
|
|
160
|
+
refineDiff(originalLines, modifiedLines, diff, timeout, considerWhitespaceChanges, options) {
|
|
161
|
+
const lineRangeMapping = toLineRangeMapping(diff);
|
|
162
|
+
const rangeMapping = lineRangeMapping.toRangeMapping2(originalLines, modifiedLines);
|
|
163
|
+
const slice1 = new LinesSliceCharSequence(originalLines, rangeMapping.originalRange, considerWhitespaceChanges);
|
|
164
|
+
const slice2 = new LinesSliceCharSequence(modifiedLines, rangeMapping.modifiedRange, considerWhitespaceChanges);
|
|
165
|
+
const diffResult = slice1.length + slice2.length < 500
|
|
166
|
+
? this.dynamicProgrammingDiffing.compute(slice1, slice2, timeout)
|
|
167
|
+
: this.myersDiffingAlgorithm.compute(slice1, slice2, timeout);
|
|
168
|
+
let diffs = diffResult.diffs;
|
|
169
|
+
diffs = optimizeSequenceDiffs(slice1, slice2, diffs);
|
|
170
|
+
diffs = extendDiffsToEntireWordIfAppropriate(slice1, slice2, diffs, (seq, idx) => seq.findWordContaining(idx));
|
|
171
|
+
if (options.extendToSubwords) {
|
|
172
|
+
diffs = extendDiffsToEntireWordIfAppropriate(slice1, slice2, diffs, (seq, idx) => seq.findSubWordContaining(idx), true);
|
|
173
|
+
}
|
|
174
|
+
diffs = removeShortMatches(slice1, slice2, diffs);
|
|
175
|
+
diffs = removeVeryShortMatchingTextBetweenLongDiffs(slice1, slice2, diffs);
|
|
176
|
+
const result = diffs.map((d) => new RangeMapping(slice1.translateRange(d.seq1Range), slice2.translateRange(d.seq2Range)));
|
|
177
|
+
// Assert: result applied on original should be the same as diff applied to original
|
|
178
|
+
return {
|
|
179
|
+
mappings: result,
|
|
180
|
+
hitTimeout: diffResult.hitTimeout,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function toLineRangeMapping(sequenceDiff) {
|
|
185
|
+
return new LineRangeMapping(new LineRange(sequenceDiff.seq1Range.start + 1, sequenceDiff.seq1Range.endExclusive + 1), new LineRange(sequenceDiff.seq2Range.start + 1, sequenceDiff.seq2Range.endExclusive + 1));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export { DefaultLinesDiffComputer };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { forEachAdjacent } from '../../../../../base/common/arrays.js';
|
|
2
|
+
import { BugIndicatingError } from '../../../../../base/common/errors.js';
|
|
3
|
+
import { OffsetRange } from '../../../core/ranges/offsetRange.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
|
+
class DiffAlgorithmResult {
|
|
10
|
+
static trivial(seq1, seq2) {
|
|
11
|
+
return new DiffAlgorithmResult([new SequenceDiff(OffsetRange.ofLength(seq1.length), OffsetRange.ofLength(seq2.length))], false);
|
|
12
|
+
}
|
|
13
|
+
static trivialTimedOut(seq1, seq2) {
|
|
14
|
+
return new DiffAlgorithmResult([new SequenceDiff(OffsetRange.ofLength(seq1.length), OffsetRange.ofLength(seq2.length))], true);
|
|
15
|
+
}
|
|
16
|
+
constructor(diffs,
|
|
17
|
+
/**
|
|
18
|
+
* Indicates if the time out was reached.
|
|
19
|
+
* In that case, the diffs might be an approximation and the user should be asked to rerun the diff with more time.
|
|
20
|
+
*/
|
|
21
|
+
hitTimeout) {
|
|
22
|
+
this.diffs = diffs;
|
|
23
|
+
this.hitTimeout = hitTimeout;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class SequenceDiff {
|
|
27
|
+
static invert(sequenceDiffs, doc1Length) {
|
|
28
|
+
const result = [];
|
|
29
|
+
forEachAdjacent(sequenceDiffs, (a, b) => {
|
|
30
|
+
result.push(SequenceDiff.fromOffsetPairs(a ? a.getEndExclusives() : OffsetPair.zero, b ? b.getStarts() : new OffsetPair(doc1Length, (a ? a.seq2Range.endExclusive - a.seq1Range.endExclusive : 0) + doc1Length)));
|
|
31
|
+
});
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
static fromOffsetPairs(start, endExclusive) {
|
|
35
|
+
return new SequenceDiff(new OffsetRange(start.offset1, endExclusive.offset1), new OffsetRange(start.offset2, endExclusive.offset2));
|
|
36
|
+
}
|
|
37
|
+
static assertSorted(sequenceDiffs) {
|
|
38
|
+
let last = undefined;
|
|
39
|
+
for (const cur of sequenceDiffs) {
|
|
40
|
+
if (last) {
|
|
41
|
+
if (!(last.seq1Range.endExclusive <= cur.seq1Range.start && last.seq2Range.endExclusive <= cur.seq2Range.start)) {
|
|
42
|
+
throw new BugIndicatingError('Sequence diffs must be sorted');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
last = cur;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
constructor(seq1Range, seq2Range) {
|
|
49
|
+
this.seq1Range = seq1Range;
|
|
50
|
+
this.seq2Range = seq2Range;
|
|
51
|
+
}
|
|
52
|
+
swap() {
|
|
53
|
+
return new SequenceDiff(this.seq2Range, this.seq1Range);
|
|
54
|
+
}
|
|
55
|
+
toString() {
|
|
56
|
+
return `${this.seq1Range} <-> ${this.seq2Range}`;
|
|
57
|
+
}
|
|
58
|
+
join(other) {
|
|
59
|
+
return new SequenceDiff(this.seq1Range.join(other.seq1Range), this.seq2Range.join(other.seq2Range));
|
|
60
|
+
}
|
|
61
|
+
delta(offset) {
|
|
62
|
+
if (offset === 0) {
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
return new SequenceDiff(this.seq1Range.delta(offset), this.seq2Range.delta(offset));
|
|
66
|
+
}
|
|
67
|
+
deltaStart(offset) {
|
|
68
|
+
if (offset === 0) {
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
return new SequenceDiff(this.seq1Range.deltaStart(offset), this.seq2Range.deltaStart(offset));
|
|
72
|
+
}
|
|
73
|
+
deltaEnd(offset) {
|
|
74
|
+
if (offset === 0) {
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
return new SequenceDiff(this.seq1Range.deltaEnd(offset), this.seq2Range.deltaEnd(offset));
|
|
78
|
+
}
|
|
79
|
+
intersect(other) {
|
|
80
|
+
const i1 = this.seq1Range.intersect(other.seq1Range);
|
|
81
|
+
const i2 = this.seq2Range.intersect(other.seq2Range);
|
|
82
|
+
if (!i1 || !i2) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
return new SequenceDiff(i1, i2);
|
|
86
|
+
}
|
|
87
|
+
getStarts() {
|
|
88
|
+
return new OffsetPair(this.seq1Range.start, this.seq2Range.start);
|
|
89
|
+
}
|
|
90
|
+
getEndExclusives() {
|
|
91
|
+
return new OffsetPair(this.seq1Range.endExclusive, this.seq2Range.endExclusive);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
class OffsetPair {
|
|
95
|
+
static { this.zero = new OffsetPair(0, 0); }
|
|
96
|
+
static { this.max = new OffsetPair(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER); }
|
|
97
|
+
constructor(offset1, offset2) {
|
|
98
|
+
this.offset1 = offset1;
|
|
99
|
+
this.offset2 = offset2;
|
|
100
|
+
}
|
|
101
|
+
toString() {
|
|
102
|
+
return `${this.offset1} <-> ${this.offset2}`;
|
|
103
|
+
}
|
|
104
|
+
delta(offset) {
|
|
105
|
+
if (offset === 0) {
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
return new OffsetPair(this.offset1 + offset, this.offset2 + offset);
|
|
109
|
+
}
|
|
110
|
+
equals(other) {
|
|
111
|
+
return this.offset1 === other.offset1 && this.offset2 === other.offset2;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
class InfiniteTimeout {
|
|
115
|
+
static { this.instance = new InfiniteTimeout(); }
|
|
116
|
+
isValid() {
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
class DateTimeout {
|
|
121
|
+
constructor(timeout) {
|
|
122
|
+
this.timeout = timeout;
|
|
123
|
+
this.startTime = Date.now();
|
|
124
|
+
this.valid = true;
|
|
125
|
+
if (timeout <= 0) {
|
|
126
|
+
throw new BugIndicatingError('timeout must be positive');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Recommendation: Set a log-point `{this.disable()}` in the body
|
|
130
|
+
isValid() {
|
|
131
|
+
const valid = Date.now() - this.startTime < this.timeout;
|
|
132
|
+
if (!valid && this.valid) {
|
|
133
|
+
this.valid = false; // timeout reached
|
|
134
|
+
}
|
|
135
|
+
return this.valid;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export { DateTimeout, DiffAlgorithmResult, InfiniteTimeout, OffsetPair, SequenceDiff };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
const diffEditorDefaultOptions = {
|
|
6
|
+
enableSplitViewResizing: true,
|
|
7
|
+
renderSideBySide: true,
|
|
8
|
+
renderMarginRevertIcon: true,
|
|
9
|
+
renderGutterMenu: true,
|
|
10
|
+
maxComputationTime: 5000,
|
|
11
|
+
maxFileSize: 50,
|
|
12
|
+
ignoreTrimWhitespace: true,
|
|
13
|
+
renderIndicators: true,
|
|
14
|
+
originalEditable: false,
|
|
15
|
+
diffCodeLens: false,
|
|
16
|
+
renderOverviewRuler: true,
|
|
17
|
+
diffWordWrap: 'inherit',
|
|
18
|
+
diffAlgorithm: 'advanced',
|
|
19
|
+
accessibilityVerbose: false,
|
|
20
|
+
experimental: {
|
|
21
|
+
showMoves: false,
|
|
22
|
+
showEmptyDecorations: true,
|
|
23
|
+
useTrueInlineView: false,
|
|
24
|
+
},
|
|
25
|
+
hideUnchangedRegions: {
|
|
26
|
+
enabled: false,
|
|
27
|
+
contextLineCount: 3,
|
|
28
|
+
minimumLineCount: 3,
|
|
29
|
+
revealLineCount: 20,
|
|
30
|
+
},
|
|
31
|
+
isInEmbeddedEditor: false,
|
|
32
|
+
onlyShowAccessibleDiffViewer: false,
|
|
33
|
+
renderSideBySideInlineBreakpoint: 900,
|
|
34
|
+
useInlineViewWhenSpaceIsLimited: true,
|
|
35
|
+
compactMode: false,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export { diffEditorDefaultOptions };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { OffsetRange } from '../../../core/ranges/offsetRange.js';
|
|
2
|
+
import { InfiniteTimeout, DiffAlgorithmResult, SequenceDiff } from './diffAlgorithm.js';
|
|
3
|
+
import { Array2D } from '../utils.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
|
+
* A O(MN) diffing algorithm that supports a score function.
|
|
11
|
+
* The algorithm can be improved by processing the 2d array diagonally.
|
|
12
|
+
*/
|
|
13
|
+
class DynamicProgrammingDiffing {
|
|
14
|
+
compute(sequence1, sequence2, timeout = InfiniteTimeout.instance, equalityScore) {
|
|
15
|
+
if (sequence1.length === 0 || sequence2.length === 0) {
|
|
16
|
+
return DiffAlgorithmResult.trivial(sequence1, sequence2);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* lcsLengths.get(i, j): Length of the longest common subsequence of sequence1.substring(0, i + 1) and sequence2.substring(0, j + 1).
|
|
20
|
+
*/
|
|
21
|
+
const lcsLengths = new Array2D(sequence1.length, sequence2.length);
|
|
22
|
+
const directions = new Array2D(sequence1.length, sequence2.length);
|
|
23
|
+
const lengths = new Array2D(sequence1.length, sequence2.length);
|
|
24
|
+
// ==== Initializing lcsLengths ====
|
|
25
|
+
for (let s1 = 0; s1 < sequence1.length; s1++) {
|
|
26
|
+
for (let s2 = 0; s2 < sequence2.length; s2++) {
|
|
27
|
+
if (!timeout.isValid()) {
|
|
28
|
+
return DiffAlgorithmResult.trivialTimedOut(sequence1, sequence2);
|
|
29
|
+
}
|
|
30
|
+
const horizontalLen = s1 === 0 ? 0 : lcsLengths.get(s1 - 1, s2);
|
|
31
|
+
const verticalLen = s2 === 0 ? 0 : lcsLengths.get(s1, s2 - 1);
|
|
32
|
+
let extendedSeqScore;
|
|
33
|
+
if (sequence1.getElement(s1) === sequence2.getElement(s2)) {
|
|
34
|
+
if (s1 === 0 || s2 === 0) {
|
|
35
|
+
extendedSeqScore = 0;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
extendedSeqScore = lcsLengths.get(s1 - 1, s2 - 1);
|
|
39
|
+
}
|
|
40
|
+
if (s1 > 0 && s2 > 0 && directions.get(s1 - 1, s2 - 1) === 3) {
|
|
41
|
+
// Prefer consecutive diagonals
|
|
42
|
+
extendedSeqScore += lengths.get(s1 - 1, s2 - 1);
|
|
43
|
+
}
|
|
44
|
+
extendedSeqScore += (equalityScore ? equalityScore(s1, s2) : 1);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
extendedSeqScore = -1;
|
|
48
|
+
}
|
|
49
|
+
const newValue = Math.max(horizontalLen, verticalLen, extendedSeqScore);
|
|
50
|
+
if (newValue === extendedSeqScore) {
|
|
51
|
+
// Prefer diagonals
|
|
52
|
+
const prevLen = s1 > 0 && s2 > 0 ? lengths.get(s1 - 1, s2 - 1) : 0;
|
|
53
|
+
lengths.set(s1, s2, prevLen + 1);
|
|
54
|
+
directions.set(s1, s2, 3);
|
|
55
|
+
}
|
|
56
|
+
else if (newValue === horizontalLen) {
|
|
57
|
+
lengths.set(s1, s2, 0);
|
|
58
|
+
directions.set(s1, s2, 1);
|
|
59
|
+
}
|
|
60
|
+
else if (newValue === verticalLen) {
|
|
61
|
+
lengths.set(s1, s2, 0);
|
|
62
|
+
directions.set(s1, s2, 2);
|
|
63
|
+
}
|
|
64
|
+
lcsLengths.set(s1, s2, newValue);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// ==== Backtracking ====
|
|
68
|
+
const result = [];
|
|
69
|
+
let lastAligningPosS1 = sequence1.length;
|
|
70
|
+
let lastAligningPosS2 = sequence2.length;
|
|
71
|
+
function reportDecreasingAligningPositions(s1, s2) {
|
|
72
|
+
if (s1 + 1 !== lastAligningPosS1 || s2 + 1 !== lastAligningPosS2) {
|
|
73
|
+
result.push(new SequenceDiff(new OffsetRange(s1 + 1, lastAligningPosS1), new OffsetRange(s2 + 1, lastAligningPosS2)));
|
|
74
|
+
}
|
|
75
|
+
lastAligningPosS1 = s1;
|
|
76
|
+
lastAligningPosS2 = s2;
|
|
77
|
+
}
|
|
78
|
+
let s1 = sequence1.length - 1;
|
|
79
|
+
let s2 = sequence2.length - 1;
|
|
80
|
+
while (s1 >= 0 && s2 >= 0) {
|
|
81
|
+
if (directions.get(s1, s2) === 3) {
|
|
82
|
+
reportDecreasingAligningPositions(s1, s2);
|
|
83
|
+
s1--;
|
|
84
|
+
s2--;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
if (directions.get(s1, s2) === 1) {
|
|
88
|
+
s1--;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
s2--;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
reportDecreasingAligningPositions(-1, -1);
|
|
96
|
+
result.reverse();
|
|
97
|
+
return new DiffAlgorithmResult(result, false);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export { DynamicProgrammingDiffing };
|