forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces diffing infrastructure & experimental diffing algorithm. (m…
…icrosoft#157646) * Introduces diffing infrastructure & experimental diffing algorithm. * Fixes CI * Fixes unit test * Fixes CI tests.
- Loading branch information
Showing
38 changed files
with
1,072 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/vs/editor/browser/widget/workerBasedDocumentDiffProvider.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { LineRange, LineRangeMapping, RangeMapping } from 'vs/editor/common/diff/linesDiffComputer'; | ||
import { Range } from 'vs/editor/common/core/range'; | ||
import { IDocumentDiff, IDocumentDiffProvider, IDocumentDiffProviderOptions } from 'vs/editor/common/diff/documentDiffProvider'; | ||
import { IEditorWorkerService } from 'vs/editor/common/services/editorWorker'; | ||
import { ITextModel } from 'vs/editor/common/model'; | ||
|
||
export class WorkerBasedDocumentDiffProvider implements IDocumentDiffProvider { | ||
constructor( | ||
@IEditorWorkerService private readonly editorWorkerService: IEditorWorkerService, | ||
) { | ||
} | ||
|
||
async computeDiff(original: ITextModel, modified: ITextModel, options: IDocumentDiffProviderOptions): Promise<IDocumentDiff> { | ||
const result = await this.editorWorkerService.computeDiff(original.uri, modified.uri, options); | ||
if (!result) { | ||
throw new Error('no diff result available'); | ||
} | ||
|
||
// Convert from space efficient JSON data to rich objects. | ||
return { | ||
identical: result.identical, | ||
quitEarly: result.quitEarly, | ||
changes: result.changes.map( | ||
(c) => | ||
new LineRangeMapping( | ||
new LineRange(c[0], c[1]), | ||
new LineRange(c[2], c[3]), | ||
c[4]?.map( | ||
(c) => | ||
new RangeMapping( | ||
new Range(c[0], c[1], c[2], c[3]), | ||
new Range(c[4], c[5], c[6], c[7]) | ||
) | ||
) | ||
) | ||
), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
/** | ||
* Represents a synchronous diff algorithm. Should be executed in a worker. | ||
*/ | ||
export interface IDiffAlgorithm { | ||
compute(sequence1: ISequence, sequence2: ISequence): SequenceDiff[]; | ||
} | ||
|
||
export class SequenceDiff { | ||
constructor( | ||
public readonly seq1Range: OffsetRange, | ||
public readonly seq2Range: OffsetRange | ||
) { } | ||
} | ||
|
||
/** | ||
* Todo move this class to some top level utils. | ||
*/ | ||
export class OffsetRange { | ||
constructor(public readonly start: number, public readonly endExclusive: number) { } | ||
|
||
get isEmpty(): boolean { | ||
return this.start === this.endExclusive; | ||
} | ||
|
||
public delta(offset: number): OffsetRange { | ||
return new OffsetRange(this.start + offset, this.endExclusive + offset); | ||
} | ||
|
||
public get length(): number { | ||
return this.endExclusive - this.start; | ||
} | ||
} | ||
|
||
export interface ISequence { | ||
getElement(offset: number): number; | ||
get length(): number; | ||
} | ||
|
||
export class SequenceFromIntArray implements ISequence { | ||
constructor(private readonly arr: number[]) { } | ||
|
||
getElement(offset: number): number { | ||
return this.arr[offset]; | ||
} | ||
|
||
get length(): number { | ||
return this.arr.length; | ||
} | ||
} |
Oops, something went wrong.