Repository navigation
Conversation
The `diff_buf_read` and `diff_buf_win_enter` hooks only reported the window's layout position, so consumers such as statusline and winbar plugins had to walk Diffview internals to learn which revision a buffer shows. Extend the hook context with the buffer's revision (`type`, `commit`, `stage`, `tracks_head`), its repo-relative `path`, the repository `toplevel` and the `adapter` name. The `DiffviewDiffBufRead` and `DiffviewDiffBufWinEnter` User autocmds carry the same fields in `data`, together with `bufnr` and `winid`.
There was a problem hiding this comment.
🟡 Changes recommended
Hooks and User autocmds expose absolute paths where paths relative to toplevel are documented, leaving the exported path contract inconsistent for arbitrary-file and directory-diff views.
1 open issue
What changed in this PR
This PR exposes revision and file context to diff-buffer hooks and User autocmds, allowing winbar and statusline integrations to identify what each diff window displays.
Changes:
- Adds revision, path, repository root, and adapter fields to the shared hook context.
- Includes context and buffer/window identifiers in User autocmd data.
- Documents the context and adds tests for commit and index-stage revisions.
| File | Description |
|---|---|
lua/diffview/tests/functional/window_spec.lua |
Tests commit and index-stage context fields. |
lua/diffview/scene/window.lua |
Builds shared diff-buffer context for hooks. |
lua/diffview/init.lua |
Adds context data to User autocmds. |
lua/diffview/config.lua |
Defines types for the expanded hook context. |
doc/diffview.txt |
Documents context fields and autocmd payloads. |
Review effort: Balanced
Views without a VCS use absolute file paths, and their files can lie outside any single directory, so there is no root that `path` is relative to. Report `toplevel` as nil there, alongside `adapter`, and document that `path` is absolute in that case.
Author
|
Can this be merged? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The
diff_buf_readanddiff_buf_win_enterhooks only report the window's layout position (symbol,layout_name).This PR extends the hook context with:
rev:type("LOCAL","COMMIT","STAGE"or"CUSTOM"),commit,stageandtracks_headpath: the file path relative totopleveltoplevel: the repository rootadapter:"git","hg","jj"or"p4"(niloutside a repository)The
DiffviewDiffBufReadandDiffviewDiffBufWinEnterUser autocmds carry the same fields indata, together withbufnrandwinid. The existing fields are unchanged.This is especially useful for winbar and statusline plugins, which can now label each diff window with the revision it shows (
LOCAL,INDEX,HEAD, a commit hash) directly from the hook:A statusline component then reads
vim.w.diffview_ctxwhen it draws.