Skip to content

feat(view): expose revision and file context to diff buffer hooks - #373

Open
tummetott wants to merge 1 commit into
dlyongemallo:mainfrom
tummetott:feat/diff-buf-ctx
Open

tummetott wants to merge 1 commit into
dlyongemallo:mainfrom
tummetott:feat/diff-buf-ctx

Conversation

@tummetott

Copy link
Copy Markdown

The diff_buf_read and diff_buf_win_enter hooks 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, stage and tracks_head
  • path: the file path relative to toplevel
  • toplevel: the repository root
  • adapter: "git", "hg", "jj" or "p4" (nil outside a repository)

The DiffviewDiffBufRead and DiffviewDiffBufWinEnter User autocmds carry the same fields in data, together with bufnr and winid. 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:

hooks = {
  diff_buf_win_enter = function(bufnr, winid, ctx)
    vim.w[winid].diffview_ctx = ctx
  end,
}

A statusline component then reads vim.w.diffview_ctx when it draws.

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`.
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.

1 participant