Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/editor/common/diff/documentDiffProvider.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 { CancellationToken } from '../../../base/common/cancellation.js';
7
import { Event } from '../../../base/common/event.js';
8
import { MovedText } from './linesDiffComputer.js';
9
import { DetailedLineRangeMapping } from './rangeMapping.js';
10
import { ITextModel } from '../model.js';
11
12
/**
13
* A document diff provider computes the diff between two text models.
14
* @internal
15
*/
16
export interface IDocumentDiffProvider {
17
/**
18
* Computes the diff between the text models `original` and `modified`.
19
*/
20
computeDiff(original: ITextModel, modified: ITextModel, options: IDocumentDiffProviderOptions, cancellationToken: CancellationToken): Promise<IDocumentDiff>;
21
22
/**
23
* Is fired when settings of the diff algorithm change that could alter the result of the diffing computation.
24
* Any user of this provider should recompute the diff when this event is fired.
25
*/
26
onDidChange: Event<void>;
27
}
28
29
/**
30
* Options for the diff computation.
31
* @internal
32
*/
33
export interface IDocumentDiffProviderOptions {
34
/**
35
* When set to true, the diff should ignore whitespace changes.
36
*/
37
ignoreTrimWhitespace: boolean;
38
39
/**
40
* A diff computation should throw if it takes longer than this value.
41
*/
42
maxComputationTimeMs: number;
43
44
/**
45
* If set, the diff computation should compute moves in addition to insertions and deletions.
46
*/
47
computeMoves: boolean;
48
49
extendToSubwords?: boolean;
50
}
51
52
/**
53
* Represents a diff between two text models.
54
* @internal
55
*/
56
export interface IDocumentDiff {
57
/**
58
* If true, both text models are identical (byte-wise).
59
*/
60
readonly identical: boolean;
61
62
/**
63
* If true, the diff computation timed out and the diff might not be accurate.
64
*/
65
readonly quitEarly: boolean;
66
67
/**
68
* Maps all modified line ranges in the original to the corresponding line ranges in the modified text model.
69
*/
70
readonly changes: readonly DetailedLineRangeMapping[];
71
72
/**
73
* Sorted by original line ranges.
74
* The original line ranges and the modified line ranges must be disjoint (but can be touching).
75
*/
76
readonly moves: readonly MovedText[];
77
}
78
79
80
export const nullDocumentDiff: IDocumentDiff = Object.freeze({
81
identical: true,
82
quitEarly: false,
83
changes: Object.freeze([]),
84
moves: Object.freeze([])
85
});
86
87