feat: treesitter highlighting for diff headers

Apply treesitter highlighting to diff metadata lines (diff --git, index,
---, +++) using the diff language parser. Header info is attached only
to the first hunk of each file to avoid duplicate highlighting.

Based on PR #52 by @phanen with fixes:
- header_lines now only contains diff metadata, not hunk content
- header info attached only to first hunk per file
- removed arbitrary hunk count restriction
This commit is contained in:
Barrett Ruth 2026-02-04 14:49:27 -05:00
parent 4008df3558
commit a25f1e9d84
7 changed files with 292 additions and 5 deletions

View file

@ -20,3 +20,11 @@ jobs:
- uses: nvim-neorocks/nvim-busted-action@v1
with:
nvim_version: ${{ matrix.nvim }}
before: |
git clone --depth 1 https://github.com/the-mikedavis/tree-sitter-diff /tmp/tree-sitter-diff
cd /tmp/tree-sitter-diff && cc -shared -fPIC -o diff.so -I./src src/parser.c
PARSER_DIR=$(nvim --headless -c 'lua print(vim.fn.stdpath("data") .. "/site/parser")' -c 'q' 2>&1 | tail -1)
echo "Installing parser to: $PARSER_DIR"
mkdir -p "$PARSER_DIR"
cp diff.so "$PARSER_DIR/"
nvim --headless -c 'lua print("diff parser available:", pcall(vim.treesitter.language.inspect, "diff"))' -c 'q'