216
217
private refineDiff(originalLines: string[], modifiedLines: string[], diff: SequenceDiff, timeout: ITimeout, considerWhitespaceChanges: boolean, options: ILinesDiffComputerOptions): { mappings: RangeMapping[]; hitTimeout: boolean } {
219
>
const rangeMapping = lineRangeMapping.toRangeMapping2(originalLines, modifiedLines);
220
>
221
>
const slice1 = new LinesSliceCharSequence(originalLines, rangeMapping.originalRange, considerWhitespaceChanges);
222
>
const slice2 = new LinesSliceCharSequence(modifiedLines, rangeMapping.modifiedRange, considerWhitespaceChanges);
223
>
224
>
const diffResult = slice1.length + slice2.length < 500
225
? this.dynamicProgrammingDiffing.compute(slice1, slice2, timeout)
226
: this.myersDiffingAlgorithm.compute(slice1, slice2, timeout);
228
>
const check = false;
229
>
230
>
let diffs = diffResult.diffs;
231
>
if (check) { SequenceDiff.assertSorted(diffs); }
232
>
diffs = optimizeSequenceDiffs(slice1, slice2, diffs);
233
>
if (check) { SequenceDiff.assertSorted(diffs); }
234
>
diffs = extendDiffsToEntireWordIfAppropriate(slice1, slice2, diffs, (seq, idx) => seq.findWordContaining(idx));
235
>
if (check) { SequenceDiff.assertSorted(diffs); }
236
>
237
>
if (options.extendToSubwords) {
238
diffs = extendDiffsToEntireWordIfAppropriate(slice1, slice2, diffs, (seq, idx) => seq.findSubWordContaining(idx), true);
239
if (check) { SequenceDiff.assertSorted(diffs); }
240
}
242
>
diffs = removeShortMatches(slice1, slice2, diffs);
243
>
if (check) { SequenceDiff.assertSorted(diffs); }
244
>
diffs = removeVeryShortMatchingTextBetweenLongDiffs(slice1, slice2, diffs);
245
>
if (check) { SequenceDiff.assertSorted(diffs); }
246
>
247
>
const result = diffs.map(
248
>
(d) =>
249
>
new RangeMapping(
250
>
slice1.translateRange(d.seq1Range),
251
>
slice2.translateRange(d.seq2Range)
252
>
)
253
>
);
254
>
255
>
if (check) { RangeMapping.assertSorted(result); }
256
>
257
>
// Assert: result applied on original should be the same as diff applied to original
258
>
259
>
return {
260
>
mappings: result,
261
>
hitTimeout: diffResult.hitTimeout,
262
>
};
263
>
}
264
}
265
267
>
return new LineRangeMapping(
268
>
new LineRange(sequenceDiff.seq1Range.start + 1, sequenceDiff.seq1Range.endExclusive + 1),
269
>
new LineRange(sequenceDiff.seq2Range.start + 1, sequenceDiff.seq2Range.endExclusive + 1),
270
>
);
271
>
}