@@ -7,7 +7,7 @@ import { assertFn, checkAdjacentItems } from 'vs/base/common/assert';
7
7
import { CharCode } from 'vs/base/common/charCode' ;
8
8
import { Position } from 'vs/editor/common/core/position' ;
9
9
import { Range } from 'vs/editor/common/core/range' ;
10
- import { SequenceFromIntArray , OffsetRange , SequenceDiff , ISequence } from 'vs/editor/common/diff/algorithms/diffAlgorithm' ;
10
+ import { OffsetRange , SequenceDiff , ISequence } from 'vs/editor/common/diff/algorithms/diffAlgorithm' ;
11
11
import { DynamicProgrammingDiffing } from 'vs/editor/common/diff/algorithms/dynamicProgrammingDiffing' ;
12
12
import { optimizeSequenceDiffs } from 'vs/editor/common/diff/algorithms/joinSequenceDiffs' ;
13
13
import { MyersDiffAlgorithm } from 'vs/editor/common/diff/algorithms/myersDiffAlgorithm' ;
@@ -34,10 +34,10 @@ export class StandardLinesDiffComputer implements ILinesDiffComputer {
34
34
const srcDocLines = originalLines . map ( ( l ) => getOrCreateHash ( l . trim ( ) ) ) ;
35
35
const tgtDocLines = modifiedLines . map ( ( l ) => getOrCreateHash ( l . trim ( ) ) ) ;
36
36
37
- const sequence1 = new SequenceFromIntArray ( srcDocLines ) ;
38
- const sequence2 = new SequenceFromIntArray ( tgtDocLines ) ;
37
+ const sequence1 = new LineSequence ( srcDocLines , originalLines ) ;
38
+ const sequence2 = new LineSequence ( tgtDocLines , modifiedLines ) ;
39
39
40
- const lineAlignments = ( ( ) => {
40
+ let lineAlignments = ( ( ) => {
41
41
if ( sequence1 . length + sequence2 . length < 1500 ) {
42
42
// Use the improved algorithm for small files
43
43
return this . dynamicProgrammingDiffing . compute (
@@ -58,6 +58,8 @@ export class StandardLinesDiffComputer implements ILinesDiffComputer {
58
58
) ;
59
59
} ) ( ) ;
60
60
61
+ lineAlignments = optimizeSequenceDiffs ( sequence1 , sequence2 , lineAlignments ) ;
62
+
61
63
const alignments : RangeMapping [ ] = [ ] ;
62
64
63
65
const scanForWhitespaceChanges = ( equalLinesCount : number ) => {
@@ -182,6 +184,35 @@ function* group<T>(items: Iterable<T>, shouldBeGrouped: (item1: T, item2: T) =>
182
184
}
183
185
}
184
186
187
+ export class LineSequence implements ISequence {
188
+ constructor (
189
+ private readonly trimmedHash : number [ ] ,
190
+ private readonly lines : string [ ]
191
+ ) { }
192
+
193
+ getElement ( offset : number ) : number {
194
+ return this . trimmedHash [ offset ] ;
195
+ }
196
+
197
+ get length ( ) : number {
198
+ return this . trimmedHash . length ;
199
+ }
200
+
201
+ getBoundaryScore ( length : number ) : number {
202
+ const indentationBefore = length === 0 ? 0 : getIndentation ( this . lines [ length - 1 ] ) ;
203
+ const indentationAfter = length === this . lines . length ? 0 : getIndentation ( this . lines [ length ] ) ;
204
+ return 1000 - ( indentationBefore + indentationAfter ) ;
205
+ }
206
+ }
207
+
208
+ function getIndentation ( str : string ) : number {
209
+ let i = 0 ;
210
+ while ( i < str . length && ( str . charCodeAt ( i ) === CharCode . Space || str . charCodeAt ( i ) === CharCode . Tab ) ) {
211
+ i ++ ;
212
+ }
213
+ return i ;
214
+ }
215
+
185
216
class Slice implements ISequence {
186
217
private readonly elements : Int32Array ;
187
218
private readonly firstCharOnLineOffsets : Int32Array ;
0 commit comments