Wilfred / difftastic

a structural diff that understands syntax 🟥🟩
https://difftastic.wilfred.me.uk/
MIT License
21.25k stars 348 forks source link

Rust attribute changes are not ideally associated #35

Open cuviper opened 3 years ago

cuviper commented 3 years ago

Using the indexmap repo, I tried the following command:

GIT_EXTERNAL_DIFF=difftastic git show --ext-diff 49d430808ced6d1824ec15d621acd6b0e8367c19

and got this output near the end:

image

Notice how the #[test] attribute is interpreted, where the following one is considered to be an insertion, instead of the one that's on the new function. This kind of thing is very common with line-based diffs, although plain git show actually does get this right!

image

Wilfred commented 3 years ago

Yeah, this is sometimes called a "slider", and difftastic isn't completely immune.

I have been thinking about trying to nudge the diff logic to avoid blank lines, but it might increase complexity. The best solution for Rust here is probably to improve the tree-sitter parser to include the attribute with the function definition.

gthb commented 2 years ago

I'm seeing the exact slider behavior described above, in Difftastic 0.31.0, in my codebase (redacting the test function body, private and probably not relevant):

image

However, it does get the above indexmap example right:

image

Not sure what the difference is. Maybe these just fall on either side of some heuristic threshold?