feat: add neogit support (#117)

## TODO

1. docs (vimdoc + readme) - this is a non-trivial feature
2. push luarocks version

## Problem

diffs.nvim only activates on `fugitive`, `git`, and `gitcommit`
filetypes.
Neogit uses its own custom filetypes (`NeogitStatus`,
`NeogitCommitView`,
`NeogitDiffView`) and doesn't set `b:git_dir`, so the plugin never
attaches
and repo root resolution fails for filetype detection within diff hunks.

## Solution

Two changes:

1. **`lua/diffs/init.lua`** — Add the three Neogit filetypes to the
default
`filetypes` list. The `FileType` autocmd in `plugin/diffs.lua` already
handles them correctly since the `is_fugitive_buffer` guard only applies
   to the `git` filetype.

2. **`lua/diffs/parser.lua`** — Add a CWD-based fallback in
`get_repo_root()`.
After the existing `b:diffs_repo_root` and `b:git_dir` checks, fall back
to
`vim.fn.getcwd()` via `git.get_repo_root()` (already cached). Without
this,
   the parser can't resolve filetypes for files in Neogit buffers.

Neogit's expanded diffs use standard unified diff format, so the parser
handles
them without modification.

Closes #110.
This commit is contained in:
Barrett Ruth 2026-02-14 17:12:01 -05:00 committed by GitHub
parent 5d3bbc3631
commit 3d640c207b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 314 additions and 56 deletions

View file

@ -287,7 +287,7 @@ describe('highlight', function()
local extmarks = get_extmarks(bufnr)
local has_diff_add = false
for _, mark in ipairs(extmarks) do
if mark[4] and mark[4].hl_group == 'DiffsAdd' then
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
has_diff_add = true
break
end
@ -320,7 +320,7 @@ describe('highlight', function()
local extmarks = get_extmarks(bufnr)
local has_diff_delete = false
for _, mark in ipairs(extmarks) do
if mark[4] and mark[4].hl_group == 'DiffsDelete' then
if mark[4] and mark[4].line_hl_group == 'DiffsDelete' then
has_diff_delete = true
break
end
@ -386,7 +386,7 @@ describe('highlight', function()
local extmarks = get_extmarks(bufnr)
local has_diff_add = false
for _, mark in ipairs(extmarks) do
if mark[4] and mark[4].hl_group == 'DiffsAdd' then
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
has_diff_add = true
break
end
@ -500,7 +500,7 @@ describe('highlight', function()
local extmarks = get_extmarks(bufnr)
local has_diff_add = false
for _, mark in ipairs(extmarks) do
if mark[4] and mark[4].hl_group == 'DiffsAdd' then
if mark[4] and mark[4].line_hl_group == 'DiffsAdd' then
has_diff_add = true
break
end
@ -560,7 +560,7 @@ describe('highlight', function()
delete_buffer(bufnr)
end)
it('uses hl_group not line_hl_group for line backgrounds', function()
it('uses line_hl_group for line backgrounds', function()
local bufnr = create_buffer({
'@@ -1,2 +1,1 @@',
'-local x = 1',
@ -582,17 +582,19 @@ describe('highlight', function()
)
local extmarks = get_extmarks(bufnr)
local found = false
for _, mark in ipairs(extmarks) do
local d = mark[4]
if d and (d.hl_group == 'DiffsAdd' or d.hl_group == 'DiffsDelete') then
assert.is_true(d.hl_eol == true)
assert.is_nil(d.line_hl_group)
if d and (d.line_hl_group == 'DiffsAdd' or d.line_hl_group == 'DiffsDelete') then
found = true
assert.is_nil(d.hl_eol)
end
end
assert.is_true(found)
delete_buffer(bufnr)
end)
it('hl_eol background extmarks are multiline so hl_eol takes effect', function()
it('line_hl_group background extmarks are single-line', function()
local bufnr = create_buffer({
'@@ -1,2 +1,1 @@',
'-local x = 1',
@ -616,8 +618,8 @@ describe('highlight', function()
local extmarks = get_extmarks(bufnr)
for _, mark in ipairs(extmarks) do
local d = mark[4]
if d and (d.hl_group == 'DiffsAdd' or d.hl_group == 'DiffsDelete') then
assert.is_true(d.end_row > mark[2])
if d and (d.line_hl_group == 'DiffsAdd' or d.line_hl_group == 'DiffsDelete') then
assert.is_nil(d.end_row)
end
end
delete_buffer(bufnr)
@ -771,7 +773,7 @@ describe('highlight', function()
if d then
if d.hl_group == 'DiffsClear' then
table.insert(priorities.clear, d.priority)
elseif d.hl_group == 'DiffsAdd' or d.hl_group == 'DiffsDelete' then
elseif d.line_hl_group == 'DiffsAdd' or d.line_hl_group == 'DiffsDelete' then
table.insert(priorities.line_bg, d.priority)
elseif d.hl_group == 'DiffsAddText' or d.hl_group == 'DiffsDeleteText' then
table.insert(priorities.char_bg, d.priority)
@ -871,8 +873,8 @@ describe('highlight', function()
local extmarks = get_extmarks(bufnr)
local line_bgs = {}
for _, mark in ipairs(extmarks) do
if mark[4] and mark[4].hl_eol then
line_bgs[mark[2]] = mark[4].hl_group
if mark[4] and mark[4].line_hl_group then
line_bgs[mark[2]] = mark[4].line_hl_group
end
end
assert.is_nil(line_bgs[1])
@ -1063,8 +1065,8 @@ describe('highlight', function()
local marker_text = {}
for _, mark in ipairs(extmarks) do
local d = mark[4]
if d and d.hl_eol then
line_bgs[mark[2]] = d.hl_group
if d and d.line_hl_group then
line_bgs[mark[2]] = d.line_hl_group
end
if d and d.number_hl_group then
gutter_hls[mark[2]] = d.number_hl_group