diffsitter 0.3.0

An AST based difftool for meaningful diffs
diffsitter-0.3.0 is not a library.
Visit the last successful build: diffsitter-0.9.0

diffsitter

Rust Publish

asciicast

Summary

diffsitter performs diffs on text files using the AST to compute the diff instead of using a naive text-based diff. This can give you more semantically meaningful diff information, which will prevent diffs from getting polluted by formatting differences, for example.

diffstter uses the parsers from the tree-sitter project to parse source code. As such, the languages supported by this tool are limited by the languages supported by the tree-sitter project.

Examples

Take the following files:

a.rs:

fn main() {
    let x = 1;
}

b.rs

fn 



main

()

{
}

fn addition() {
}

fn add_two() {
}

The standard output from diff will get you:

1,2c1,12
< fn main() {
<     let x = 1;
---
> fn
>
>
>
> main
>
> ()
>
> {
> }
>
> fn addition() {
5c15
< fn add_one {
---
> fn add_two() {

You can see that it picks up the formatting differences for the main function, even though they aren't semantically different.

Check out the output from diffsitter:

-     let x = 1;
- fn add_one {
+ }
+ fn addition() {
+ fn add_two() {

Since it uses the AST to calculate the difference, it knows that the formatting differences in main between the two files isn't a meaningful difference, so it doesn't show up in the diff.

diffsitter has some nice (terminal aware) formatting too:

screenshot of rust diff

Development

In order to develop for this project, you need to clone the project and initialize all submodules (each tree-sitter grammar is added as a subdirectory).

git clone
git submodule --init --recursive

This uses cargo with the cc crate, so you need to install rust and have a working C and C++ compiler.