Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/diff/linesDiffComputer.ts
3294 views
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
6
import { DetailedLineRangeMapping, LineRangeMapping } from './rangeMapping.js';
7
8
export interface ILinesDiffComputer {
9
computeDiff(originalLines: string[], modifiedLines: string[], options: ILinesDiffComputerOptions): LinesDiff;
10
}
11
12
export interface ILinesDiffComputerOptions {
13
readonly ignoreTrimWhitespace: boolean;
14
readonly maxComputationTimeMs: number;
15
readonly computeMoves: boolean;
16
readonly extendToSubwords?: boolean;
17
}
18
19
export class LinesDiff {
20
constructor(
21
readonly changes: readonly DetailedLineRangeMapping[],
22
23
/**
24
* Sorted by original line ranges.
25
* The original line ranges and the modified line ranges must be disjoint (but can be touching).
26
*/
27
readonly moves: readonly MovedText[],
28
29
/**
30
* Indicates if the time out was reached.
31
* In that case, the diffs might be an approximation and the user should be asked to rerun the diff with more time.
32
*/
33
readonly hitTimeout: boolean,
34
) {
35
}
36
}
37
38
export class MovedText {
39
public readonly lineRangeMapping: LineRangeMapping;
40
41
/**
42
* The diff from the original text to the moved text.
43
* Must be contained in the original/modified line range.
44
* Can be empty if the text didn't change (only moved).
45
*/
46
public readonly changes: readonly DetailedLineRangeMapping[];
47
48
constructor(
49
lineRangeMapping: LineRangeMapping,
50
changes: readonly DetailedLineRangeMapping[],
51
) {
52
this.lineRangeMapping = lineRangeMapping;
53
this.changes = changes;
54
}
55
56
public flip(): MovedText {
57
return new MovedText(this.lineRangeMapping.flip(), this.changes.map(c => c.flip()));
58
}
59
}
60
61