Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
novemberborn opened this issue Feb 6, 2021 · 4 comments

Comments

@novemberborn
Copy link
Member

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.
@tommy-mitchell
Copy link

tommy-mitchell commented Mar 13, 2023

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.

@novemberborn
Copy link
Member Author

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

@tommy-mitchell
Copy link

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

@novemberborn
Copy link
Member Author

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants