Skip to content

Decouple neo-tree concerns from diff.lua (mark_change_and_reveal) #57

Description

@Cannon07

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions