difftastic icon indicating copy to clipboard operation
difftastic copied to clipboard

Rust attribute changes are not ideally associated

Open cuviper opened this issue 2 years ago • 2 comments

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

cuviper avatar Sep 16 '21 18:09 cuviper

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.

Wilfred avatar Sep 18 '21 05:09 Wilfred

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?

gthb avatar Jul 21 '22 12:07 gthb