From f65cf57d307279e7ba07f4c9f16be68b88a418ec Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 17 Mar 2026 17:09:06 -0400 Subject: [PATCH 1/2] fix(parser): support git diff.mnemonicPrefix in diff header Problem: `git diff.mnemonicPrefix = true` produces diff headers like `diff --git c/init.lua i/init.lua` using single-letter mnemonic prefixes (`c/`, `i/`, `w/`) instead of the standard `a/`/`b/`. The parser only matched `a/.+ b/(.+)`, so mnemonic-prefixed diffs produced no highlighting. Solution: Change the pattern to `%a/.+ %a/(.+)` (Lua `%a` matches any letter), accepting any single-letter prefix while correctly rejecting numeric prefixes like `1/`/`2/`. Adds tests for both the accepted mnemonic cases and the rejected numeric case. --- README.md | 1 + lua/diffs/parser.lua | 2 +- spec/parser_spec.lua | 53 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8685ee0..0db28c7 100644 --- a/README.md +++ b/README.md @@ -130,3 +130,4 @@ See the documentation for more information. decoration provider highlighting architecture, gitsigns blame popup highlighting, intra-line bg visibility fix - [@tris203](https://github.com/tris203) - support for transparent backgrounds +- [@letientai299](https://github.com/letientai299) - `diff.mnemonicPrefix` support diff --git a/lua/diffs/parser.lua b/lua/diffs/parser.lua index 6f84b83..09047a2 100644 --- a/lua/diffs/parser.lua +++ b/lua/diffs/parser.lua @@ -248,7 +248,7 @@ function M.parse_buffer(bufnr) end end - local diff_git_file = logical:match('^diff %-%-git a/.+ b/(.+)$') + local diff_git_file = logical:match('^diff %-%-git %a/.+ %a/(.+)$') or logical:match('^diff %-%-combined (.+)$') or logical:match('^diff %-%-cc (.+)$') local neogit_file = logical:match('^modified%s+(.+)$') diff --git a/spec/parser_spec.lua b/spec/parser_spec.lua index adbbd37..815032b 100644 --- a/spec/parser_spec.lua +++ b/spec/parser_spec.lua @@ -262,6 +262,59 @@ describe('parser', function() delete_buffer(bufnr) end) + it('extracts filename with mnemonic prefix c/ i/', function() + local bufnr = create_buffer({ + 'diff --git c/init.lua i/init.lua', + 'index 3e8afa0..018159c 100644', + '--- c/init.lua', + '+++ i/init.lua', + '@@ -1,1 +1,2 @@', + ' local M = {}', + '+local x = 1', + }) + local hunks = parser.parse_buffer(bufnr) + + assert.are.equal(1, #hunks) + assert.are.equal('init.lua', hunks[1].filename) + assert.are.equal('lua', hunks[1].ft) + assert.are.equal('lua', hunks[1].lang) + delete_buffer(bufnr) + end) + + it('extracts filename with mnemonic prefix w/ i/', function() + local bufnr = create_buffer({ + 'diff --git w/src/main.lua i/src/main.lua', + 'index abc1234..def5678 100644', + '--- w/src/main.lua', + '+++ i/src/main.lua', + '@@ -1,1 +1,2 @@', + ' local M = {}', + '+local y = 2', + }) + local hunks = parser.parse_buffer(bufnr) + + assert.are.equal(1, #hunks) + assert.are.equal('src/main.lua', hunks[1].filename) + delete_buffer(bufnr) + end) + + it('rejects non-letter prefix in diff header', function() + local bufnr = create_buffer({ + 'diff --git 1/init.lua 2/init.lua', + 'index 3e8afa0..018159c 100644', + '--- 1/init.lua', + '+++ 2/init.lua', + '@@ -1,1 +1,2 @@', + ' local M = {}', + '+local x = 1', + }) + local hunks = parser.parse_buffer(bufnr) + + assert.are.equal(1, #hunks) + assert.is_nil(hunks[1].filename) + delete_buffer(bufnr) + end) + it('handles fugitive status format with diff headers', function() local bufnr = create_buffer({ 'Head: main', From b6f16dfadf089b938799a2b5fddbc80f10439038 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 17 Mar 2026 17:13:44 -0400 Subject: [PATCH 2/2] ci: format --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0db28c7..cca39c7 100644 --- a/README.md +++ b/README.md @@ -130,4 +130,5 @@ See the documentation for more information. decoration provider highlighting architecture, gitsigns blame popup highlighting, intra-line bg visibility fix - [@tris203](https://github.com/tris203) - support for transparent backgrounds -- [@letientai299](https://github.com/letientai299) - `diff.mnemonicPrefix` support +- [@letientai299](https://github.com/letientai299) - `diff.mnemonicPrefix` + support