mirror of
https://github.com/Microsoft/vscode
synced 2024-07-05 01:08:57 +00:00
Diff Algorithm refactoring
This commit is contained in:
parent
d5b7644d9b
commit
0f816a3513
|
@ -14,7 +14,7 @@ import { LinesSliceCharSequence } from 'vs/editor/common/diff/defaultLinesDiffCo
|
|||
import { LineRangeFragment, isSpace } from 'vs/editor/common/diff/defaultLinesDiffComputer/utils';
|
||||
import { MyersDiffAlgorithm } from 'vs/editor/common/diff/defaultLinesDiffComputer/algorithms/myersDiffAlgorithm';
|
||||
|
||||
export function computeMoves(
|
||||
export function computeMovedLines(
|
||||
changes: DetailedLineRangeMapping[],
|
||||
originalLines: string[],
|
||||
modifiedLines: string[],
|
|
@ -12,8 +12,8 @@ import { Range } from 'vs/editor/common/core/range';
|
|||
import { DateTimeout, ITimeout, InfiniteTimeout, SequenceDiff } from 'vs/editor/common/diff/defaultLinesDiffComputer/algorithms/diffAlgorithm';
|
||||
import { DynamicProgrammingDiffing } from 'vs/editor/common/diff/defaultLinesDiffComputer/algorithms/dynamicProgrammingDiffing';
|
||||
import { MyersDiffAlgorithm } from 'vs/editor/common/diff/defaultLinesDiffComputer/algorithms/myersDiffAlgorithm';
|
||||
import { computeMoves } from 'vs/editor/common/diff/defaultLinesDiffComputer/computeMoves';
|
||||
import { extendDiffsToEntireWordIfAppropriate, optimizeSequenceDiffs, removeRandomLineMatches, removeRandomMatches, smoothenSequenceDiffs } from 'vs/editor/common/diff/defaultLinesDiffComputer/heuristicSequenceOptimizations';
|
||||
import { computeMovedLines } from 'vs/editor/common/diff/defaultLinesDiffComputer/computeMovedLines';
|
||||
import { extendDiffsToEntireWordIfAppropriate, optimizeSequenceDiffs, removeVeryShortMatchingLinesBetweenDiffs, removeVeryShortMatchingTextBetweenLongDiffs, removeShortMatches } from 'vs/editor/common/diff/defaultLinesDiffComputer/heuristicSequenceOptimizations';
|
||||
import { ILinesDiffComputer, ILinesDiffComputerOptions, LinesDiff, MovedText } from 'vs/editor/common/diff/linesDiffComputer';
|
||||
import { DetailedLineRangeMapping, RangeMapping } from '../rangeMapping';
|
||||
import { LinesSliceCharSequence } from 'vs/editor/common/diff/defaultLinesDiffComputer/linesSliceCharSequence';
|
||||
|
@ -87,7 +87,7 @@ export class DefaultLinesDiffComputer implements ILinesDiffComputer {
|
|||
let lineAlignments = lineAlignmentResult.diffs;
|
||||
let hitTimeout = lineAlignmentResult.hitTimeout;
|
||||
lineAlignments = optimizeSequenceDiffs(sequence1, sequence2, lineAlignments);
|
||||
lineAlignments = removeRandomLineMatches(sequence1, sequence2, lineAlignments);
|
||||
lineAlignments = removeVeryShortMatchingLinesBetweenDiffs(sequence1, sequence2, lineAlignments);
|
||||
|
||||
const alignments: RangeMapping[] = [];
|
||||
|
||||
|
@ -187,7 +187,7 @@ export class DefaultLinesDiffComputer implements ILinesDiffComputer {
|
|||
timeout: ITimeout,
|
||||
considerWhitespaceChanges: boolean,
|
||||
): MovedText[] {
|
||||
const moves = computeMoves(
|
||||
const moves = computeMovedLines(
|
||||
changes,
|
||||
originalLines,
|
||||
modifiedLines,
|
||||
|
@ -217,8 +217,8 @@ export class DefaultLinesDiffComputer implements ILinesDiffComputer {
|
|||
let diffs = diffResult.diffs;
|
||||
diffs = optimizeSequenceDiffs(slice1, slice2, diffs);
|
||||
diffs = extendDiffsToEntireWordIfAppropriate(slice1, slice2, diffs);
|
||||
diffs = smoothenSequenceDiffs(slice1, slice2, diffs);
|
||||
diffs = removeRandomMatches(slice1, slice2, diffs);
|
||||
diffs = removeShortMatches(slice1, slice2, diffs);
|
||||
diffs = removeVeryShortMatchingTextBetweenLongDiffs(slice1, slice2, diffs);
|
||||
|
||||
const result = diffs.map(
|
||||
(d) =>
|
||||
|
|
|
@ -196,7 +196,7 @@ function shiftDiffToBetterPosition(diff: SequenceDiff, sequence1: ISequence, seq
|
|||
return diff.delta(bestDelta);
|
||||
}
|
||||
|
||||
export function smoothenSequenceDiffs(sequence1: ISequence, sequence2: ISequence, sequenceDiffs: SequenceDiff[]): SequenceDiff[] {
|
||||
export function removeShortMatches(sequence1: ISequence, sequence2: ISequence, sequenceDiffs: SequenceDiff[]): SequenceDiff[] {
|
||||
const result: SequenceDiff[] = [];
|
||||
for (const s of sequenceDiffs) {
|
||||
const last = result[result.length - 1];
|
||||
|
@ -310,7 +310,7 @@ function mergeSequenceDiffs(sequenceDiffs1: SequenceDiff[], sequenceDiffs2: Sequ
|
|||
return result;
|
||||
}
|
||||
|
||||
export function removeRandomLineMatches(sequence1: LineSequence, _sequence2: LineSequence, sequenceDiffs: SequenceDiff[]): SequenceDiff[] {
|
||||
export function removeVeryShortMatchingLinesBetweenDiffs(sequence1: LineSequence, _sequence2: LineSequence, sequenceDiffs: SequenceDiff[]): SequenceDiff[] {
|
||||
let diffs = sequenceDiffs;
|
||||
if (diffs.length === 0) {
|
||||
return diffs;
|
||||
|
@ -357,7 +357,7 @@ export function removeRandomLineMatches(sequence1: LineSequence, _sequence2: Lin
|
|||
return diffs;
|
||||
}
|
||||
|
||||
export function removeRandomMatches(sequence1: LinesSliceCharSequence, sequence2: LinesSliceCharSequence, sequenceDiffs: SequenceDiff[]): SequenceDiff[] {
|
||||
export function removeVeryShortMatchingTextBetweenLongDiffs(sequence1: LinesSliceCharSequence, sequence2: LinesSliceCharSequence, sequenceDiffs: SequenceDiff[]): SequenceDiff[] {
|
||||
let diffs = sequenceDiffs;
|
||||
if (diffs.length === 0) {
|
||||
return diffs;
|
||||
|
|
Loading…
Reference in New Issue
Block a user