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:
parent
5d3bbc3631
commit
3d640c207b
8 changed files with 314 additions and 56 deletions
22
README.md
22
README.md
|
|
@ -2,14 +2,15 @@
|
|||
|
||||
**Syntax highlighting for diffs in Neovim**
|
||||
|
||||
Enhance `vim-fugitive` and Neovim's built-in diff mode with language-aware
|
||||
syntax highlighting.
|
||||
Enhance [vim-fugitive](https://github.com/tpope/vim-fugitive),
|
||||
[Neogit](https://github.com/NeogitOrg/neogit), and Neovim's built-in diff mode
|
||||
with language-aware syntax highlighting.
|
||||
|
||||
<video src="https://github.com/user-attachments/assets/24574916-ecb2-478e-a0ea-e4cdc971e310" width="100%" controls></video>
|
||||
|
||||
## Features
|
||||
|
||||
- Treesitter syntax highlighting in fugitive diffs and commit views
|
||||
- Treesitter syntax highlighting in vim-fugitive, Neogit, and `diff` filetype
|
||||
- Character-level intra-line diff highlighting (with optional
|
||||
[vscode-diff](https://github.com/esmuellert/codediff.nvim) FFI backend for
|
||||
word-level accuracy)
|
||||
|
|
@ -37,6 +38,21 @@ luarocks install diffs.nvim
|
|||
:help diffs.nvim
|
||||
```
|
||||
|
||||
## FAQ
|
||||
|
||||
**Does diffs.nvim support vim-fugitive/Neogit?**
|
||||
|
||||
Yes. Enable it in your config:
|
||||
|
||||
```lua
|
||||
vim.g.diffs = {
|
||||
fugitive = true,
|
||||
neogit = true,
|
||||
}
|
||||
```
|
||||
|
||||
See the documentation for more information.
|
||||
|
||||
## Known Limitations
|
||||
|
||||
- **Incomplete syntax context**: Treesitter parses each diff hunk in isolation.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue