Skip to content

feat: add neogit support#117

Merged
barrettruth merged 21 commits intomainfrom
feat/neogit-support
Feb 14, 2026
Merged

feat: add neogit support#117
barrettruth merged 21 commits intomainfrom
feat/neogit-support

Conversation

@barrettruth
Copy link
Owner

@barrettruth barrettruth commented Feb 14, 2026

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.

Problem: diffs.nvim only activates on fugitive/git/gitcommit filetypes.
Neogit uses its own filetypes (NeogitStatus, NeogitCommitView,
NeogitDiffView) and doesn't set b:git_dir, so the plugin never attaches
and repo root resolution fails.

Solution: add the three Neogit filetypes to the default filetypes list,
and add a cwd-based fallback in get_repo_root() that uses git.get_repo_root()
when neither b:diffs_repo_root nor b:git_dir are set.
@CKolkey
Copy link

CKolkey commented Feb 14, 2026

lmk if there's anything that I could add to neogit that would make your life easier here :)

Problem: Neogit's line_hl_group extmarks define foreground colors that
override diffs.nvim's treesitter hl_group syntax regardless of priority,
making syntax invisible on +/- lines.

Solution: on first Neogit buffer attach, set all 17 Neogit diff line
highlight groups to {} (empty) so diffs.nvim has sole control. Reapply
on ColorScheme since Neogit re-defines its groups then.
Problem: line backgrounds used hl_group with hl_eol, which only covers
the text area. Neogit buffers have a sign column that remains uncolored,
creating a visual gap. Also required two separate extmark calls for
background and gutter.

Solution: use line_hl_group instead, which covers text, sign, number,
and fold columns. Merge gutter number_hl_group into the same extmark.
Safe for fugitive since DiffsAdd/DiffsDelete define only bg (no fg).
Problem: Neogit untracked file diffs show a bare filename (e.g.
"newfile.rs") with no status prefix before the @@ header. The parser
did not recognize this pattern.

Solution: add a bare filename match for lines with no whitespace and at
least one dot, guarded by not being inside a hunk.
Problem: disabling a single integration (fugitive or neogit) required
redefining the entire filetypes list and knowing all defaults.

Solution: add fugitive.enabled, neogit.enabled, and extra_filetypes
config keys. compute_filetypes() builds the filetype list from these
toggles at load time. The old filetypes key still works but emits a
vim.deprecate warning (removed in 0.3.0). Boolean shorthands
(fugitive = false, neogit = false) are normalized to tables before
validation.
Problem: config docs referenced the removed filetypes list and lacked
documentation for the new fugitive/neogit/extra_filetypes keys.

Solution: replace {filetypes} field docs with {fugitive}, {neogit},
and {extra_filetypes}. Document fugitive.enabled in FugitiveConfig.
Update neogit section with disable example and deprecation note.
Problem: enabling integrations by default couples diffs.nvim to plugins
the user may not have installed.

Solution: set fugitive.enabled and neogit.enabled to false in
default_config. compute_filetypes now treats nil as disabled (opt-in).
Users enable integrations explicitly with fugitive = true or
neogit = true.
Problem: the filetypes key was kept as a deprecated fallback with a
vim.deprecate warning targeting 0.3.0. No reason to keep it around.

Solution: remove filetypes support entirely from compute_filetypes,
init normalization, and type annotations. Drop deprecation note from
docs.
Problem: the filetypes key was fully removed, but a proper deprecation
period is preferable.

Solution: restore filetypes fallback in compute_filetypes and emit a
vim.deprecate warning in init(). The old key still works but will be
removed in v0.3.0 (#118).
@barrettruth
Copy link
Owner Author

actually @CKolkey there may be. or there may not be, depending on what you deem is best.

Some context: diffs.nvim is kind of like a parasite. Some may even deem this entire plugin a parasite. It hooks into other tools (fugitive, diff buffers, and now neogit) and then CHANGES the highlighting. It does this by disabling THEIR highlights and activating its own.

The only way for me to do this with neogit is to disable a list of hard-coded neogit HL groups. The end product looks pretty cool (note that my colorscheme is not optimized for neogit since I, well, don't use it):

image

Potential asks include:

  1. A config to disable Neogit's diff line highlighting — right now I have to override ~18 highlight groups to {} because fg stomps any treesitter highlights I set, regardless of priority. If there was a way to tell Neogit "don't highlight diff lines" this would clean up 99% of the complexity. Also I hope this wouldn't be that bad to implement on your end.
  2. Something like b:neogit_git_dir or b:neogit_repo_root (vim-fugitive exposes b:git_dir — I need the repo root for filetype detection. Rn, I fall back to getcwd() which isn't always right (small thing).
  3. Structured hunk/file metadata — I'm re-parsing the buffer text to find filenames and hunk boundaries. A buffer variable or API exposing this would let me skip parsing entirely. This is by far the biggest ask and, well, probably the least relevant.

Happy to discuss this further and formalize this into issues on neogit itself if you like.

If I end up merging this pr and closing it please respond here and just @ me.

@barrettruth barrettruth merged commit 3d640c2 into main Feb 14, 2026
7 checks passed
@barrettruth barrettruth deleted the feat/neogit-support branch February 14, 2026 22:12
@CKolkey
Copy link

CKolkey commented Feb 15, 2026

@barrettruth Your biggest ask was, I think, the easiest. Something like this? NeogitOrg/neogit#1897

edit: Turns out it was all pretty easy. Let me know if it's right or if it needs some tweaking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

neogit

2 participants