Path: blob/main/src/vs/editor/common/diff/linesDiffComputer.ts
3294 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { DetailedLineRangeMapping, LineRangeMapping } from './rangeMapping.js';67export interface ILinesDiffComputer {8computeDiff(originalLines: string[], modifiedLines: string[], options: ILinesDiffComputerOptions): LinesDiff;9}1011export interface ILinesDiffComputerOptions {12readonly ignoreTrimWhitespace: boolean;13readonly maxComputationTimeMs: number;14readonly computeMoves: boolean;15readonly extendToSubwords?: boolean;16}1718export class LinesDiff {19constructor(20readonly changes: readonly DetailedLineRangeMapping[],2122/**23* Sorted by original line ranges.24* The original line ranges and the modified line ranges must be disjoint (but can be touching).25*/26readonly moves: readonly MovedText[],2728/**29* Indicates if the time out was reached.30* In that case, the diffs might be an approximation and the user should be asked to rerun the diff with more time.31*/32readonly hitTimeout: boolean,33) {34}35}3637export class MovedText {38public readonly lineRangeMapping: LineRangeMapping;3940/**41* The diff from the original text to the moved text.42* Must be contained in the original/modified line range.43* Can be empty if the text didn't change (only moved).44*/45public readonly changes: readonly DetailedLineRangeMapping[];4647constructor(48lineRangeMapping: LineRangeMapping,49changes: readonly DetailedLineRangeMapping[],50) {51this.lineRangeMapping = lineRangeMapping;52this.changes = changes;53}5455public flip(): MovedText {56return new MovedText(this.lineRangeMapping.flip(), this.changes.map(c => c.flip()));57}58}596061