MCPcopy
hub / github.com/continuedev/continue / myersDiff

Function myersDiff

core/diff/myers.ts:29–57  ·  view source on GitHub ↗
(oldContent: string, newContent: string)

Source from the content-addressed store, hash-verified

27// [ { type: "old", line: "foo" }, { type: "new", line: "foo" } ], we
28// pass ignoreNewlineAtEof: true.
29export function myersDiff(oldContent: string, newContent: string): DiffLine[] {
30 const theirFormat = diffLines(oldContent, newContent, {
31 ignoreNewlineAtEof: true,
32 });
33 let ourFormat = theirFormat.flatMap(convertMyersChangeToDiffLines);
34
35 // Combine consecutive old/new pairs that are identical after trimming
36 for (let i = 0; i < ourFormat.length - 1; i++) {
37 if (
38 ourFormat[i]?.type === "old" &&
39 ourFormat[i + 1]?.type === "new" &&
40 ourFormat[i].line.trim() === ourFormat[i + 1].line.trim()
41 ) {
42 ourFormat[i] = { type: "same", line: ourFormat[i].line };
43 ourFormat.splice(i + 1, 1);
44 }
45 }
46
47 // Remove trailing empty old lines
48 while (
49 ourFormat.length > 0 &&
50 ourFormat[ourFormat.length - 1].type === "old" &&
51 ourFormat[ourFormat.length - 1].line === ""
52 ) {
53 ourFormat.pop();
54 }
55
56 return ourFormat;
57}
58
59export function myersCharDiff(
60 oldContent: string,

Callers 11

myers.vitest.tsFile · 0.90
collectDiffsFunction · 0.90
processDiffFunction · 0.90
instantApplyDiffMethod · 0.90
reapplyWithMyersDiffMethod · 0.90
handleNonInstantDiffMethod · 0.90
collectDiffsFunction · 0.85
handleFullFileDiffFunction · 0.85

Calls 1

popMethod · 0.45

Tested by 1

collectDiffsFunction · 0.72