Minga.Core.DiffView (Minga v0.1.0)

Copy Markdown View Source

Pure calculation module for building unified diff views.

Takes base (HEAD) lines and current lines with hunks, produces interleaved text with line metadata for rendering as a read-only buffer with decorations.

Summary

Types

Result of building a diff view: the text content and per-line metadata.

Metadata for a single display line in the diff view.

Functions

Builds a unified diff view from base and current content.

Builds a unified diff view from pre-computed hunks.

Builds a GUI side-by-side diff view from base and current content.

Builds a GUI side-by-side diff view from pre-computed hunks.

Types

diff_view_result()

@type diff_view_result() :: %{
  text: String.t(),
  line_metadata: [line_meta()],
  hunk_lines: [non_neg_integer()]
}

Result of building a diff view: the text content and per-line metadata.

line_meta()

@type line_meta() :: %{
  :type => line_type(),
  :original_line => non_neg_integer() | nil,
  :fold_count => non_neg_integer() | nil,
  :word_changes => [Minga.Core.Diff.char_range()] | nil,
  optional(:left_type) => pane_line_type(),
  optional(:right_type) => pane_line_type(),
  optional(:left_width) => pos_integer(),
  optional(:separator_col) => non_neg_integer(),
  optional(:left_word_changes) => [Minga.Core.Diff.char_range()] | nil,
  optional(:right_word_changes) => [Minga.Core.Diff.char_range()] | nil
}

Metadata for a single display line in the diff view.

line_type()

@type line_type() :: :context | :added | :removed | :header | :fold

pane_line_type()

@type pane_line_type() :: :context | :added | :removed | :blank | :fold

Functions

build(base_content, current_content)

@spec build(String.t(), String.t()) :: diff_view_result()

Builds a unified diff view from base and current content.

Returns a map with:

  • :text - the interleaved unified diff text to inject into a Buffer
  • :line_metadata - per-line metadata for decorations (type, original line number)
  • :hunk_lines - display line indices where hunks end (for hunk position and actions)

build_from_hunks(base_lines, current_lines, hunks)

@spec build_from_hunks([String.t()], [String.t()], [Minga.Core.Diff.hunk()]) ::
  diff_view_result()

Builds a unified diff view from pre-computed hunks.

build_side_by_side(base_content, current_content, pane_width \\ 80)

@spec build_side_by_side(String.t(), String.t(), pos_integer()) :: diff_view_result()

Builds a GUI side-by-side diff view from base and current content.

The result uses one rendered buffer line per aligned row. The left pane carries the old version, the right pane carries the new version, and blank filler rows preserve vertical alignment across additions and deletions. Metadata includes pane-local change ranges so GUI decorations can highlight each pane independently.

build_side_by_side_from_hunks(base_lines, current_lines, hunks, pane_width)

@spec build_side_by_side_from_hunks(
  [String.t()],
  [String.t()],
  [Minga.Core.Diff.hunk()],
  pos_integer()
) ::
  diff_view_result()

Builds a GUI side-by-side diff view from pre-computed hunks.