Semantic diff for Neovim using Tree-sitter. Understands code structure to detect moved functions, updated blocks, and real changes, not just line differences.
- Move detection — Knows when code blocks are moved, not deleted and re-added
- Update detection — Highlights modified code in place
- Insert/Delete detection — Shows new and removed code
- Rename detection — Shows renamed variables and functions
- Language agnostic — Works with languages that have Tree-sitter parsers and diffmantic query support
Using lazy.nvim:
{
"HarshK97/diffmantic.nvim",
config = function()
require("diffmantic").setup()
end,
}Compare two files:
:Diffmantic path/to/file1 path/to/file2Compare current buffer with another file:
:Diffmantic path/to/other_fileThe current core follows a multi-phase AST matching pipeline:
- Pre-match — Seeds stable mappings from unchanged lines
- Top-down matching — Finds identical/high-confidence subtree pairs
- Bottom-up matching — Expands matches using mapped descendants
- Recovery matching — Iteratively recovers remaining valid mappings
- Action generation + analysis — Produces move/update/insert/delete actions and refined hunks
- Neovim 0.9+
- Tree-sitter parser for the language you're diffing
This project is licensed under the MIT License - see the LICENSE file for details.
- GumTree repository: https://github.com/GumTreeDiff/gumtree
- GumTree paper: https://hal.science/hal-04855170v1/file/GumTree_simple__fine_grained__accurate_and_scalable_source_differencing.pdf
- Beyond GumTree paper: https://www.researchgate.net/publication/335498580_Beyond_GumTree_A_Hybrid_Approach_to_Generate_Edit_Scripts
