https://github.com/afnanenayet/diffsitter Skip to content Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Issues - + Integrations - + GitHub Sponsors - + Customer stories- * Team * Enterprise * Explore + Explore GitHub - Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Education - [ ] [search-key] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} afnanenayet / diffsitter * Notifications * Star 272 * Fork 4 A tree-sitter based AST difftool to get meaningful semantic diffs MIT License 272 stars 4 forks Star Notifications * Code * Issues 2 * Pull requests 0 * Discussions * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Discussions * Actions * Projects * Wiki * Security * Insights main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags 22 branches 23 tags Code Clone HTTPS GitHub CLI [https://github.com/a] Use Git or checkout with SVN using the web URL. [gh repo clone afnane] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @afnanenayet afnanenayet chore: bump anyhow to latest (#151) ... 2b5fbfe Jul 17, 2021 chore: bump anyhow to latest (#151) 2b5fbfe Git stats * 260 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github Conditional compilation for build-info (#145) Jul 7, 2021 assets Generate homebrew file as part of release (#113) May 1, 2021 deployment Fix version string in release template May 2, 2021 grammars Use forks for submodules (#115) May 2, 2021 src Conditional compilation for build-info (#145) Jul 7, 2021 test_data Add formatting (#16) Jan 8, 2021 .gitignore Initial commit Jun 26, 2020 .gitmodules Use forks for submodules (#115) May 2, 2021 CODE_OF_CONDUCT.md Create code of conduct Feb 7, 2021 Cargo.lock chore: bump anyhow to latest (#151) Jul 18, 2021 Cargo.toml chore: bump anyhow to latest (#151) Jul 18, 2021 Cross.toml Default config bug fix, cross test compatibility (#104) Apr 2, 2021 LICENSE Update copyright Jan 25, 2021 README.md docs: add information about new AUR package (#146). (#148) Jul 12, 2021 build.rs Conditional compilation for build-info (#145) Jul 7, 2021 clippy.toml Add clippy and rustfmt manifests (#147) Jul 12, 2021 rustfmt.toml Add clippy and rustfmt manifests (#147) Jul 12, 2021 View code diffsitter Summary Examples Installation Published binaries Cargo Homebrew Arch Linux (AUR) Usage Development README.md diffsitter CI CD crates version latest tag downloads license asciicast Summary diffsitter creates semantically meaningful diffs that ignore formatting differences like spacing. It does so by computing a diff on the AST (abstract syntax tree) of a file rather than computing the diff on the text contents of the file. diffstter uses the parsers from the tree-sitter project to parse source code. As such, the languages supported by this tool are restricted to the languages supported by tree-sitter. diffsitter supports the following languages: * Bash * C# * C++ * CSS * Go * Java * OCaml * PHP * Python * Ruby * Rust Examples Take the following files: a.rs fn main() { let x = 1; } fn add_one { } 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: test_data/test_1_a.rs -> test_data/test_1_b.rs ============================================== 1: -- - let x = 1; 4: -- - fn add_one { 9: -- + } 11: --- + fn addition() { 14: --- + fn add_two() { Note: the numbers correspond to line numbers from the original files. 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 It also has extensive logging if you want to debug or see timing information: screenshot of rust diff with logs Installation Published binaries This project uses Github actions to build and publish binaries for each tagged release. You can download binaries from there if your platform is listed. Cargo You can install using cargo the standard way with cargo install diffsitter. Homebrew You can use my tap to install diffsitter: brew tap afnanenayet/tap brew install diffsitter # brew install afnanenayet/tap/diffsitter Arch Linux (AUR) @samhh has packaged diffsitter for arch on the AUR. Use your favorite AUR helper to install diffsitter-bin. Usage For detailed help you can run diffsitter --help (diffsitter -h provides brief help messages). You can configure file associations and formatting options for diffsitter using a config file. If a config is not supplied, the app will use the default config, which you can see with diffsitter --cmd dump_default_config. It will look for a config at $XDG_HOME/.config on macOS and Linux, and the standard directory for Windows. You can also refer to the sample config. Note: the tests for this crate check to make sure the provided sample config is a valid config. Development You need a Rust toolchain, which you can install from here: https:// rustup.rs. You will also need a C and C++ compiler, any standard-compliant one should be fine (GCC, Clang, or Visual Studio). If you're on Mac and have Homebrew installed: brew install llvm # or brew install gcc The built-in Apple clang that comes with XCode is also fine. If you're on Ubuntu: sudo apt install gcc If you're on Arch Linux: sudo pacman -S gcc Once you have the requisite toolchains installed, you'll want to clone the project and initialize submodules: git clone git submodule --init --recursive This project targets the latest stable version of rustc, it may work on older versions, but support is only guaranteed for the latest stable version. About A tree-sitter based AST difftool to get meaningful semantic diffs Topics rust tree-sitter parser diff ast Resources Readme License MIT License Releases 23 v0.6.6 Latest May 2, 2021 + 22 releases Contributors 4 * @afnanenayet afnanenayet Afnan Enayet * @dependabot-preview dependabot-preview[bot] * @dependabot dependabot[bot] * @Byron Byron Sebastian Thiel Languages * Rust 95.7% * Python 3.9% * Shell 0.4% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.