Skip to content

Add gutter signs support - #451

Open
richardgill wants to merge 18 commits into
esmuellert:mainfrom
richardgill:native-gutter-signs
Open

Add gutter signs support#451
richardgill wants to merge 18 commits into
esmuellert:mainfrom
richardgill:native-gutter-signs

Conversation

@richardgill

@richardgill richardgill commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

This PR adds configurable gutter signs and changed-line number highlighting.

gutter_signs = {
  insert_text = "",
  delete_text = "",
  highlight_numbers = true,
  changed_priority = 100,
  unchanged_priority = nil,
}

This allows users to:

  • Show configurable + and - signs in the sign column.
    • Note: nvim only has two cols to position these so you can do "+ " or " +", both are a bit clunky.
  • Highlight changed line numbers.
  • Optionally hide lower-priority signs from plugins such as Gitsigns on changed and unchanged lines.

This PR uses ordinary persistent ranged extmarks. Changed signs and optional blank blocker signs can hide lower-priority signs from other plugins without modifying their settings or extmarks.

Persistent signs belong to the buffer and are visible in every window displaying the buffer. This implementation clears the signs when its tab is left or the diff is closed, then renders them again when its tab is re-entered.

Screenshots

Both screenshots compare the same BASE revision to the working tree with an identical fixture, viewport, colorscheme, and cursor position. The unchanged getStatus line differs from HEAD, so Gitsigns marks it even though CodeDiff considers it unchanged. The getMessage replacement demonstrates the changed-line gutter formatting.

Before

The lower-priority Gitsigns marker remains visible in the right pane.

before-annotated-v3.png

After

The unchanged-line blocker hides the Gitsigns marker. The replacement hunk shows the insert/delete signs, sign-column backgrounds, and changed line-number foregrounds.

after-annotated-v3.png

⚠️ Inline diff limitation

None of these approaches can attach a sign to an individual virt_lines row because virtual rows do not have their own buffer coordinates. I've filed an issue in neovim/neovim#40987. The PR therefore does not render gutter signs in inline diff layouts.

Other options considered

Ephemeral extmarks

A decoration provider could create extmarks only for the current redraw, making signs window-local without storing or clearing them.

This approach cannot implement the requested gutter behavior today. Neovim ignores sign_text, sign_hl_group, line_hl_group, and number_hl_group on ephemeral extmarks, so it cannot render the signs and number highlights requested by #454 or the blank blocker signs used to override lower-priority signs for #473. This is tracked in neovim/neovim#32936 and was reproduced on Neovim 0.11.5 and 0.12.2.

Fixing #32936 would make ephemeral extmarks suitable for real buffer lines, including blocker signs. It would still not allow signs on individual virtual lines.

Window-scoped extmark namespaces

Neovim 0.11 introduced nvim__ns_set(namespace, { wins = { winid } }), which can restrict persistent extmarks to selected windows. Combined with persistent signs and blockers, this could implement #454 and #473 on real buffer lines without displaying CodeDiff signs in unrelated windows.

CodeDiff does not use this approach because the API is explicitly experimental and unstable, and depending on it would raise CodeDiff's current Neovim 0.9 requirement. Namespace scoping also does not suppress signs from other plugins by itself: #473 still requires higher-priority CodeDiff signs and blank blocker signs. It also cannot place signs on individual virtual lines.

This approach can be reconsidered if Neovim exposes a stable supported mechanism.


Fixes #454
Fixes #473

@richardgill richardgill added the Size/L Large - Refactor code, new algorithm (one weekend) label Jul 22, 2026
# Conflicts:
#	doc/tags
#	lua/codediff/ui/core.lua
#	lua/codediff/ui/move.lua
#	lua/codediff/ui/view/side_by_side.lua
@richardgill richardgill changed the title Added native gutter signs support Add gutter signs support Jul 26, 2026
@richardgill
richardgill marked this pull request as ready for review July 27, 2026 05:44
@richardgill
richardgill requested a review from esmuellert as a code owner July 27, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Size/L Large - Refactor code, new algorithm (one weekend)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Disable/override other gutter plugins when codediff is open Feature: show added and deleted lines in the Neovim gutter

1 participant