Skip to content

fix(tui): show real file line numbers in Edit tool diffs (#870)#873

Merged
edenreich merged 1 commit into
mainfrom
fix/edit-diff-real-line-numbers
Jul 12, 2026
Merged

fix(tui): show real file line numbers in Edit tool diffs (#870)#873
edenreich merged 1 commit into
mainfrom
fix/edit-diff-real-line-numbers

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

The Edit tool rendered its diff from the old_stringnew_string snippet, so diffview numbered the changed lines 1, 2, 3… instead of their actual positions in the file (issue #870).

Root cause: the snippet has no knowledge of where it sits in the file, and after the edit runs the file no longer contains old_string, so the renderer can't re-derive positions. The approval preview already diffs whole-file content (correct numbers), but the completed result card and the pending approval card render the snippet.

Fix

Thread the edit's start line through as a gutter offset:

  • diffview: new LineNumberOffset(n) shifts hunk FromLine/ToLine once in computeDiff, so digit width, hunk header, and both unified/split layouts all pick it up.
  • DiffRenderer.SetStartLine(n) applies LineNumberOffset(n-1).
  • EditToolResult.StartLine is recorded in executeEdit (line of the first replaced occurrence) and passed by FormatForLLM for the completed card.
  • The pending card computes the start line from the still-unedited file via snippetStartLine.

Tests

  • TestLineNumberOffsetShiftsGutter (diffview) — gutter and hunk header reflect the offset.
  • New FormatResult case asserting the completed Edit diff shows real file line numbers.

Notes

  • Not applied to MultiEdit: its per-edit snippets shift as edits apply, so a single offset isn't correct there.
  • Internal-only UI fix — no docs ticket needed.

The Edit tool rendered its diff from the old_string/new_string snippet,
so diffview numbered the changed lines from 1 instead of their actual
file positions. Thread the edit's start line through as a gutter offset:
diffview gains LineNumberOffset, DiffRenderer gains SetStartLine, and
EditToolResult records StartLine so both the completed result card and
the pending approval card show real line numbers.
@edenreich edenreich requested a review from a team as a code owner July 12, 2026 02:17
@edenreich edenreich moved this to QA in Roadmap 2026 Jul 12, 2026
@edenreich edenreich merged commit 2006046 into main Jul 12, 2026
10 checks passed
@edenreich edenreich deleted the fix/edit-diff-real-line-numbers branch July 12, 2026 10:45
@edenreich edenreich linked an issue Jul 12, 2026 that may be closed by this pull request
@edenreich edenreich moved this from QA to Done in Roadmap 2026 Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] The Edit tool doesn't tell which lines the edit was made

1 participant