computeMovedLines.ts ×14

Frontier kind: Code frontier

unlabeled · c_ccef038d9297

7 tests · 9540 LOC · 52 files · introduces 0 tests · 116 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
25 ranges116 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1728 ranges9540 lines · 52 files · Browse complete extent
All tests (intent)
7 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.

3 files ranked by introduced lines: 116 introduced LOC across 25 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/editor/common/diff/defaultLinesDiffComputer/computeMovedLines.ts 69 introduced LOC · 14 ranges

Open complete file

132 const nextMappings: PossibleMapping[] = [];
133 original3LineHashes.forEach(key, ({ range }) => {
134 > for (const lastMapping of lastMappings) { computeMovedLines.ts
135 // does this match extend some last match?
136 if (lastMapping.originalLineRange.endLineNumberExclusive + 1 === range.endLineNumberExclusive &&
142 }
143 }
145 > const mapping: PossibleMapping = {
146 > modifiedLineRange: currentModifiedRange,
147 > originalLineRange: range,
148 > };
149 > possibleMappings.push(mapping);
150 > nextMappings.push(mapping);
151 });
152 lastMappings = nextMappings;
164
165 for (const mapping of possibleMappings) {
167 > const diffOrigToMod = mapping.modifiedLineRange.startLineNumber - mapping.originalLineRange.startLineNumber;
168 > const modifiedSections = modifiedSet.subtractFrom(mapping.modifiedLineRange);
169 > const originalTranslatedSections = originalSet.subtractFrom(mapping.originalLineRange).getWithDelta(diffOrigToMod);
170 >
171 > const modifiedIntersectedSections = modifiedSections.getIntersection(originalTranslatedSections);
172 >
173 > for (const s of modifiedIntersectedSections.ranges) {
174 > if (s.length < 3) {
175 continue;
176 }
177 > const modifiedLineRange = s; computeMovedLines.ts
178 > const originalLineRange = s.delta(-diffOrigToMod);
179 >
180 > moves.push(new LineRangeMapping(originalLineRange, modifiedLineRange));
181 >
182 > modifiedSet.addRange(modifiedLineRange);
183 > originalSet.addRange(originalLineRange);
184 > }
185 > }
186
187 moves.sort(compareBy(m => m.original.startLineNumber, numberComparator));
189 const monotonousChanges = new MonotonousArray(changes);
190 for (let i = 0; i < moves.length; i++) {
191 > const move = moves[i]; computeMovedLines.ts
192 > const firstTouchingChangeOrig = monotonousChanges.findLastMonotonous(c => c.original.startLineNumber <= move.original.startLineNumber)!;
193 > const firstTouchingChangeMod = findLastMonotonous(changes, c => c.modified.startLineNumber <= move.modified.startLineNumber)!;
194 > const linesAbove = Math.max(
195 > move.original.startLineNumber - firstTouchingChangeOrig.original.startLineNumber,
196 > move.modified.startLineNumber - firstTouchingChangeMod.modified.startLineNumber
197 > );
198 >
199 > const lastTouchingChangeOrig = monotonousChanges.findLastMonotonous(c => c.original.startLineNumber < move.original.endLineNumberExclusive)!;
200 > const lastTouchingChangeMod = findLastMonotonous(changes, c => c.modified.startLineNumber < move.modified.endLineNumberExclusive)!;
201 > const linesBelow = Math.max(
202 > lastTouchingChangeOrig.original.endLineNumberExclusive - move.original.endLineNumberExclusive,
203 > lastTouchingChangeMod.modified.endLineNumberExclusive - move.modified.endLineNumberExclusive
204 > );
205 >
206 > let extendToTop: number;
207 > for (extendToTop = 0; extendToTop < linesAbove; extendToTop++) {
208 const origLine = move.original.startLineNumber - extendToTop - 1;
209 const modLine = move.modified.startLineNumber - extendToTop - 1;
218 }
219 }
221 > if (extendToTop > 0) {
222 originalSet.addRange(new LineRange(move.original.startLineNumber - extendToTop, move.original.startLineNumber));
223 modifiedSet.addRange(new LineRange(move.modified.startLineNumber - extendToTop, move.modified.startLineNumber));
224 }
226 > let extendToBottom: number;
227 > for (extendToBottom = 0; extendToBottom < linesBelow; extendToBottom++) {
228 > const origLine = move.original.endLineNumberExclusive + extendToBottom;
229 > const modLine = move.modified.endLineNumberExclusive + extendToBottom;
230 > if (origLine > originalLines.length || modLine > modifiedLines.length) {
231 break;
232 }
233 > if (modifiedSet.contains(modLine) || originalSet.contains(origLine)) { computeMovedLines.ts
234 break;
235 }
236 > if (!areLinesSimilar(originalLines[origLine - 1], modifiedLines[modLine - 1], timeout)) { computeMovedLines.ts
237 break;
238 }
240 >
241 > if (extendToBottom > 0) {
242 originalSet.addRange(new LineRange(move.original.endLineNumberExclusive, move.original.endLineNumberExclusive + extendToBottom));
243 modifiedSet.addRange(new LineRange(move.modified.endLineNumberExclusive, move.modified.endLineNumberExclusive + extendToBottom));
244 }
246 > if (extendToTop > 0 || extendToBottom > 0) {
247 moves[i] = new LineRangeMapping(
248 new LineRange(move.original.startLineNumber - extendToTop, move.original.endLineNumberExclusive + extendToBottom),
250 );
251 }
253 >
254 > return moves;
255 > }
256
257 > function areLinesSimilar(line1: string, line2: string, timeout: ITimeout): boolean { computeMovedLines.ts
258 > if (line1.trim() === line2.trim()) { return true; }
259 > if (line1.length > 300 && line2.length > 300) { return false; }
260
261 const myersDiffingAlgorithm = new MyersDiffAlgorithm();
285 }
286
287 > const longerLineLength = countNonWsChars(line1.length > line2.length ? line1 : line2); computeMovedLines.ts
288 > const r = commonNonSpaceCharCount / longerLineLength > 0.6 && longerLineLength > 10;
289 > return r;
290 > }
291
292 function joinCloseConsecutiveMoves(moves: LineRangeMapping[]): LineRangeMapping[] {
src/vs/editor/common/core/ranges/lineRange.ts 45 introduced LOC · 10 ranges

Open complete file

123 */
124 public delta(offset: number): LineRange {
125 > return new LineRange(this.startLineNumber + offset, this.endLineNumberExclusive + offset); lineRange.ts
126 > }
127
128 public deltaLength(offset: number): LineRange {
156 */
157 public intersect(other: LineRange): LineRange | undefined {
158 > const startLineNumber = Math.max(this.startLineNumber, other.startLineNumber); lineRange.ts
159 > const endLineNumberExclusive = Math.min(this.endLineNumberExclusive, other.endLineNumberExclusive);
160 > if (startLineNumber <= endLineNumberExclusive) {
161 > return new LineRange(startLineNumber, endLineNumberExclusive);
162 > }
163 return undefined;
164 > } lineRange.ts
165
166 public intersectsStrict(other: LineRange): boolean {
261
262 get ranges(): readonly LineRange[] {
263 > return this._normalizedRanges; lineRange.ts
264 > }
265
266 addRange(range: LineRange): void {
292
293 contains(lineNumber: number): boolean {
294 > const rangeThatStartsBeforeEnd = findLastMonotonous(this._normalizedRanges, r => r.startLineNumber <= lineNumber); lineRange.ts
295 > return !!rangeThatStartsBeforeEnd && rangeThatStartsBeforeEnd.endLineNumberExclusive > lineNumber;
296 > }
297
298 intersects(range: LineRange): boolean {
356 */
357 subtractFrom(range: LineRange): LineRangeSet {
358 > // idx of first element that touches range or that is after range lineRange.ts
359 > const joinRangeStartIdx = findFirstIdxMonotonousOrArrLen(this._normalizedRanges, r => r.endLineNumberExclusive >= range.startLineNumber);
360 > // idx of element after { last element that touches range or that is before range }
361 > const joinRangeEndIdxExclusive = findLastIdxMonotonous(this._normalizedRanges, r => r.startLineNumber <= range.endLineNumberExclusive) + 1;
362 >
363 > if (joinRangeStartIdx === joinRangeEndIdxExclusive) {
364 > return new LineRangeSet([range]);
365 > }
366
367 const result: LineRange[] = [];
379
380 return new LineRangeSet(result);
381 > } lineRange.ts
382
383 toString() {
386
387 getIntersection(other: LineRangeSet): LineRangeSet {
388 > const result: LineRange[] = []; lineRange.ts
389 >
390 > let i1 = 0;
391 > let i2 = 0;
392 > while (i1 < this._normalizedRanges.length && i2 < other._normalizedRanges.length) {
393 > const r1 = this._normalizedRanges[i1];
394 > const r2 = other._normalizedRanges[i2];
395 >
396 > const i = r1.intersect(r2);
397 > if (i && !i.isEmpty) {
398 > result.push(i);
399 > }
400 >
401 > if (r1.endLineNumberExclusive < r2.endLineNumberExclusive) {
402 i1++;
403 > } else { lineRange.ts
404 > i2++;
405 > }
406 > }
407 >
408 > return new LineRangeSet(result);
409 > }
410
411 getWithDelta(value: number): LineRangeSet {
412 > return new LineRangeSet(this._normalizedRanges.map(r => r.delta(value))); lineRange.ts
413 > }
414 }
src/vs/base/common/arrays.ts 2 introduced LOC · 1 range

Open complete file

563 export function pushMany<T>(arr: T[], items: ReadonlyArray<T>): void {
564 for (const item of items) {
565 > arr.push(item); arrays.ts
566 > }
567 }
568