computeMovedLines.ts ×11

Frontier kind: Code frontier

unlabeled · c_be2e770196b3

56 tests · 8586 LOC · 52 files · introduces 0 tests · 119 LOC · 4 files

Introduces — evidence that enters the hierarchy at this concept

Code
19 ranges119 lines · 4 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1438 ranges8586 lines · 52 files · Browse complete extent
All tests (intent)
56 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

4 files ranked by introduced lines: 119 introduced LOC across 19 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/diff/defaultLinesDiffComputer/computeMovedLines.ts 88 introduced LOC · 11 ranges

Open complete file

16
17 export function computeMovedLines(
18 > changes: DetailedLineRangeMapping[], computeMovedLines.ts
19 > originalLines: string[],
20 > modifiedLines: string[],
21 > hashedOriginalLines: number[],
22 > hashedModifiedLines: number[],
23 > timeout: ITimeout
24 > ): LineRangeMapping[] {
25 > let { moves, excludedChanges } = computeMovesFromSimpleDeletionsToSimpleInsertions(changes, originalLines, modifiedLines, timeout);
26 >
27 > if (!timeout.isValid()) { return []; }
28 >
29 > const filteredChanges = changes.filter(c => !excludedChanges.has(c));
30 > const unchangedMoves = computeUnchangedMoves(filteredChanges, hashedOriginalLines, hashedModifiedLines, originalLines, modifiedLines, timeout);
31 > pushMany(moves, unchangedMoves);
32 >
33 > moves = joinCloseConsecutiveMoves(moves);
34 > // Ignore too short moves
35 > moves = moves.filter(current => {
36 const lines = current.original.toOffsetRange().slice(originalLines).map(l => l.trim());
37 const originalText = lines.join('\n');
38 return originalText.length >= 15 && countWhere(lines, l => l.length >= 2) >= 2;
40 > moves = removeMovesInSameDiff(changes, moves);
41 >
42 > return moves;
43 > }
44
45 function countWhere<T>(arr: T[], predicate: (t: T) => boolean): number {
53 }
54
55 > function computeMovesFromSimpleDeletionsToSimpleInsertions( computeMovedLines.ts
56 > changes: DetailedLineRangeMapping[],
57 > originalLines: string[],
58 > modifiedLines: string[],
59 > timeout: ITimeout,
60 > ) {
61 > const moves: LineRangeMapping[] = [];
62 >
63 > const deletions = changes
64 > .filter(c => c.modified.isEmpty && c.original.length >= 3)
65 > .map(d => new LineRangeFragment(d.original, originalLines, d));
66 > const insertions = new Set(changes
67 > .filter(c => c.original.isEmpty && c.modified.length >= 3)
68 > .map(d => new LineRangeFragment(d.modified, modifiedLines, d)));
69 >
70 > const excludedChanges = new Set<DetailedLineRangeMapping>();
71 >
72 > for (const deletion of deletions) {
73 let highestSimilarity = -1;
74 let best: LineRangeFragment | undefined;
92 }
93 }
95 > return { moves, excludedChanges };
96 > }
97
98 > function computeUnchangedMoves( computeMovedLines.ts
99 > changes: DetailedLineRangeMapping[],
100 > hashedOriginalLines: number[],
101 > hashedModifiedLines: number[],
102 > originalLines: string[],
103 > modifiedLines: string[],
104 > timeout: ITimeout,
105 > ) {
106 > const moves: LineRangeMapping[] = [];
107 >
108 > const original3LineHashes = new SetMap<string, { range: LineRange }>();
109 >
110 > for (const change of changes) {
111 for (let i = change.original.startLineNumber; i < change.original.endLineNumberExclusive - 2; i++) {
112 const key = `${hashedOriginalLines[i - 1]}:${hashedOriginalLines[i + 1 - 1]}:${hashedOriginalLines[i + 2 - 1]}`;
114 }
115 }
117 > interface PossibleMapping {
118 > modifiedLineRange: LineRange;
119 > originalLineRange: LineRange;
120 > }
121 >
122 > const possibleMappings: PossibleMapping[] = [];
123 >
124 > changes.sort(compareBy(c => c.modified.startLineNumber, numberComparator));
125 >
126 > for (const change of changes) {
127 let lastMappings: PossibleMapping[] = [];
128 for (let i = change.modified.startLineNumber; i < change.modified.endLineNumberExclusive - 2; i++) {
157 }
158 }
160 > possibleMappings.sort(reverseOrder(compareBy(m => m.modifiedLineRange.length, numberComparator)));
161 >
162 > const modifiedSet = new LineRangeSet();
163 > const originalSet = new LineRangeSet();
164 >
165 > for (const mapping of possibleMappings) {
166
167 const diffOrigToMod = mapping.modifiedLineRange.startLineNumber - mapping.originalLineRange.startLineNumber;
184 }
185 }
187 > moves.sort(compareBy(m => m.original.startLineNumber, numberComparator));
188 >
189 > const monotonousChanges = new MonotonousArray(changes);
190 > for (let i = 0; i < moves.length; i++) {
191 const move = moves[i];
192 const firstTouchingChangeOrig = monotonousChanges.findLastMonotonous(c => c.original.startLineNumber <= move.original.startLineNumber)!;
290 }
291
292 > function joinCloseConsecutiveMoves(moves: LineRangeMapping[]): LineRangeMapping[] { computeMovedLines.ts
293 > if (moves.length === 0) {
294 return moves;
295 }
316 }
317
318 > function removeMovesInSameDiff(changes: DetailedLineRangeMapping[], moves: LineRangeMapping[]) { computeMovedLines.ts
319 > const changesMonotonous = new MonotonousArray(changes);
320 > moves = moves.filter(m => {
321 const diffBeforeEndOfMoveOriginal = changesMonotonous.findLastMonotonous(c => c.original.startLineNumber < m.original.endLineNumberExclusive)
322 || new LineRangeMapping(new LineRange(1, 1), new LineRange(1, 1));
325 const differentDiffs = diffBeforeEndOfMoveOriginal !== diffBeforeEndOfMoveModified;
326 return differentDiffs;
328 > return moves;
329 > }
src/vs/editor/common/diff/defaultLinesDiffComputer/defaultLinesDiffComputer.ts 23 introduced LOC · 3 ranges

Open complete file

149 let moves: MovedText[] = [];
150 if (options.computeMoves) {
151 > moves = this.computeMoves(changes, originalLines, modifiedLines, originalLinesHashes, modifiedLinesHashes, timeout, considerWhitespaceChanges, options); defaultLinesDiffComputer.ts
152 > }
153
154 // Make sure all ranges are valid
187
188 private computeMoves(
189 > changes: DetailedLineRangeMapping[], defaultLinesDiffComputer.ts
190 > originalLines: string[],
191 > modifiedLines: string[],
192 > hashedOriginalLines: number[],
193 > hashedModifiedLines: number[],
194 > timeout: ITimeout,
195 > considerWhitespaceChanges: boolean,
196 > options: ILinesDiffComputerOptions,
197 > ): MovedText[] {
198 > const moves = computeMovedLines(
199 > changes,
200 > originalLines,
201 > modifiedLines,
202 > hashedOriginalLines,
203 > hashedModifiedLines,
204 > timeout,
205 > );
206 > const movesWithDiffs = moves.map(m => {
207 const moveChanges = this.refineDiff(originalLines, modifiedLines, new SequenceDiff(
208 m.original.toOffsetRange(),
211 const mappings = lineRangeMappingFromRangeMappings(moveChanges.mappings, new ArrayText(originalLines), new ArrayText(modifiedLines), true);
212 return new MovedText(m, mappings);
214 > return movesWithDiffs;
215 > }
216
217 private refineDiff(originalLines: string[], modifiedLines: string[], diff: SequenceDiff, timeout: ITimeout, considerWhitespaceChanges: boolean, options: ILinesDiffComputerOptions): { mappings: RangeMapping[]; hitTimeout: boolean } {
src/vs/editor/common/diff/defaultLinesDiffComputer/algorithms/diffAlgorithm.ts 6 introduced LOC · 4 ranges

Open complete file

187
188 constructor(private timeout: number) {
189 > if (timeout <= 0) { diffAlgorithm.ts
190 throw new BugIndicatingError('timeout must be positive');
191 }
193
194 // Recommendation: Set a log-point `{this.disable()}` in the body
195 public isValid(): boolean {
196 > const valid = Date.now() - this.startTime < this.timeout; diffAlgorithm.ts
197 > if (!valid && this.valid) {
198 this.valid = false; // timeout reached
199 }
200 > return this.valid; diffAlgorithm.ts
201 > }
202
203 public disable() {
src/vs/base/common/arrays.ts 2 introduced LOC · 1 range

Open complete file

713
714 export function reverseOrder<TItem>(comparator: Comparator<TItem>): Comparator<TItem> {
715 > return (a, b) => -comparator(a, b); arrays.ts
716 > }
717
718 /**