concordancejs / concordance

Compare, format, diff and serialize any JavaScript value

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve focus of multi-line string diffs when there are loads of lines

novemberborn opened this issue · comments

See discussion: avajs/ava#2665

When comparing two strings that are many lines long, the diff output should focus on the lines that are actually different, not the potentially dozens or hundreds of lines that are the same.

  1. If the diff is longer than, say, 30 lines, divide it into sections of changes and non-changes.
  2. If the non-change sections are 5 lines or less, merge the surrounding change sections into one larger change section.
  3. For the sections with changes, provide 5 lines of context before and after the actual change. Take 5 lines from the preceding and succeeding non-change sections, if any. Due to step 2, these sections must be larger than 5 lines.
  4. Prefix the change sections with a hunk heading @@ -l, +l @@, where the line numbers l correspond to the - and + sides of the diff.
  5. Print the change sections, prefixed with their heading, and separated with an empty line between them.
commented

I'd like to work on this, where should the changes be made? I would think under StringValue.diffDeep() in lib/primitiveValues/string.js. Or is this part of StringValue.formatDeep()? It seems like there's some tests for the former in the 'diffs multiline strings' test in test/diff.ts.

Honestly you're guess is as good as mine at this point 😄

commented

So it goes lol. Do you have any pointers for developing for this library? No worries if not.

Maybe a note about the tests, if you hadn't spotted it yet. The formatters are tested through snapshots, with identifying strings used in the "theme".