Skip to content

Split lua/code-preview/diff.lua into focused modules #61

@Cannon07

Description

@Cannon07

Motivation

lua/code-preview/diff.lua is 599 lines covering four loosely related concerns:

  1. The side-by-side renderer (show_diff after the layout == "inline" branch).
  2. The inline renderer (show_inline_diff, build_inline_diff, char_diff_ranges, inline_statuscolumn, apply_inline_highlights).
  3. The active-previews registry (active_diffs, is_open, close_for_file, close_diff_and_clear, _active_diffs).
  4. Cross-cutting neo-tree coordination (mark_change_and_reveal) — already tracked separately.

This mixing makes the file hard to extend and impossible to test in pieces. Per ADR-0003, the inline renderer is the strategic direction, so the seam between renderers is also a natural extension point.

Proposed direction

Extract along these lines (final names up for discussion):

  • lua/code-preview/diff/init.lua — public entry (show_diff, close_for_file, etc.). Owns the active-previews registry.
  • lua/code-preview/diff/inline.lua — inline renderer (build, highlight, statuscolumn, keymaps).
  • lua/code-preview/diff/side_by_side.lua:diffthis-based renderer.
  • lua/code-preview/diff/util.lua — shared helpers (read_file_lines, char_diff_ranges if both renderers end up using it after Port character-level diff highlights to the side-by-side renderer #56).

Renderers expose render(...) → {tab, bufs, augroup, inline_win?}; the registry doesn't care which one ran.

Scope

  • Pure refactor. No behaviour change. No public API change (require('code-preview.diff').show_diff etc. continue to work).
  • Existing tests (tests/plugin/diff_lifecycle_spec.lua) must pass unchanged.

Out of scope

Dependencies / ordering

Sequence with the rest of the refactor backlog:

  1. Refactor: clean up path parameter naming in diff.show_diff #55 (path rename) — clean names first.
  2. This split.
  3. Port character-level diff highlights to the side-by-side renderer #56 (char highlights for side-by-side) — easier to land after the inline renderer is its own module.
  4. The neo-tree decoupling issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions