Skip to content

HarshK97/diffmantic.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

114 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Diffmantic Logo

Semantic diff for Neovim using Tree-sitter. Understands code structure to detect moved functions, updated blocks, and real changes, not just line differences.

Demo

Features

  • 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

Installation

Using lazy.nvim:

{
    "HarshK97/diffmantic.nvim",
    config = function()
        require("diffmantic").setup()
    end,
}

Usage

Compare two files:

:Diffmantic path/to/file1 path/to/file2

Compare current buffer with another file:

:Diffmantic path/to/other_file

How It Works

The current core follows a multi-phase AST matching pipeline:

  1. Pre-match — Seeds stable mappings from unchanged lines
  2. Top-down matching — Finds identical/high-confidence subtree pairs
  3. Bottom-up matching — Expands matches using mapped descendants
  4. Recovery matching — Iteratively recovers remaining valid mappings
  5. Action generation + analysis — Produces move/update/insert/delete actions and refined hunks

Requirements

  • Neovim 0.9+
  • Tree-sitter parser for the language you're diffing

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

About

Semantic Diff Engine for Neovim Using Tree-sitter

Topics

Resources

License

Stars

Watchers

Forks

Contributors