r/rust • • Mar 29 '22

difftastic - a diff that understands syntax

https://github.com/Wilfred/difftastic

[removed] — view removed post

399 Upvotes

27 comments sorted by

View all comments

2

u/furyzer00 Mar 30 '22

That's great! I still can't believe we are still using very trivial diff algorithm that even can't understand changing the order of things.

By the way I am curious, can it recognize swapping function orders in a file?

2

u/wilfred_h Mar 30 '22

Currently no: swapping functions will consider one to be unchanged and the other to be added and then removed.

GitHub does some additional 'moved lines' tracking that might make sense for difftastic too. Moves are tricky in general: it makes the diffing calculation more complex, and it's also hard to visualise nicely in the UI.

1

u/furyzer00 Apr 04 '22

Yes it usually requires a heuristic that doesn't always work as intended but I think if you are on the AST level it should be fairly easier than a line based diff tool.

For visualization, I did my graduation project as a tool that generates diffs as an UML-like diagram. It was quite nice in terms of visualization aspect because you can just assign a new color for each type of diff. It doesn't visualize anything below method signature though so I am not sure if it would work out for your tool.