Motivation
lua/code-preview/diff.lua contains mark_change_and_reveal, which:
- Sets a status in
code-preview.changes registry.
- Calls
code-preview.neo_tree.refresh().
- Computes a reveal target (falling back to nearest existing ancestor for
created files).
- Shells out to
git rev-parse --show-toplevel when reveal_root = "git".
- Calls
code-preview.neo_tree.reveal(...) via vim.defer_fn.
The diff renderer should not know any of this. Today, modifying neo-tree reveal behaviour means editing diff.lua; testing the reveal logic in isolation is impossible because it's invoked as a side effect of show_diff.
Proposed direction
Move the neo-tree coordination into either:
lua/code-preview/neo_tree.lua — expose a single high-level entrypoint like neo_tree.mark_and_reveal(file_path, action, cfg) that handles status mapping + refresh + reveal target computation internally; or
- A new thin coordinator module (
lua/code-preview/coordinator.lua or similar) — if neo-tree should stay agnostic about when it's called.
diff.show_diff then just calls that one entrypoint and stops knowing about reveal targets, git roots, or vim.defer_fn timing.
Scope
- Pure refactor. No behaviour change visible to the user.
- Touches
lua/code-preview/diff.lua, lua/code-preview/neo_tree.lua, and possibly a new module.
- Add a unit test for the reveal-target fallback logic (the
created → nearest-existing-ancestor walk).
Out of scope
- Changing the reveal behaviour itself (defer-300ms, rm-wins precedence, git/cwd choice).
- The wider
diff.lua split.
Motivation
lua/code-preview/diff.luacontainsmark_change_and_reveal, which:code-preview.changesregistry.code-preview.neo_tree.refresh().createdfiles).git rev-parse --show-toplevelwhenreveal_root = "git".code-preview.neo_tree.reveal(...)viavim.defer_fn.The diff renderer should not know any of this. Today, modifying neo-tree reveal behaviour means editing
diff.lua; testing the reveal logic in isolation is impossible because it's invoked as a side effect ofshow_diff.Proposed direction
Move the neo-tree coordination into either:
lua/code-preview/neo_tree.lua— expose a single high-level entrypoint likeneo_tree.mark_and_reveal(file_path, action, cfg)that handles status mapping + refresh + reveal target computation internally; orlua/code-preview/coordinator.luaor similar) — if neo-tree should stay agnostic about when it's called.diff.show_diffthen just calls that one entrypoint and stops knowing about reveal targets, git roots, orvim.defer_fntiming.Scope
lua/code-preview/diff.lua,lua/code-preview/neo_tree.lua, and possibly a new module.created→ nearest-existing-ancestor walk).Out of scope
diff.luasplit.