Skip to content

fix(tui): refine action span priority and in-place line alignment - #62

Merged
HarshK97 merged 1 commit into
mainfrom
fix/tui-span-priority
Aug 6, 2026
Merged

fix(tui): refine action span priority and in-place line alignment#62
HarshK97 merged 1 commit into
mainfrom
fix/tui-span-priority

Conversation

@HarshK97

@HarshK97 HarshK97 commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Problem

  1. When a variable declaration like var fc = func(...) got refactored to fc := func(...), the inner func_literal was parsed as a Move action because its parent changed from var_spec to short_var_declaration. AlignLines flagged the whole block as an unalignable move, creating diagonal filler lines (///) on both sides and splitting the function body into two separated blocks instead of rendering line 850 side-by-side.
  2. In the TUI renderer, outer container highlights (like a wide 138-byte delete of var_declaration) were taking visual priority over inner child highlights (like a 129-byte move of func_literal). mergeAllSpans was also dropping the underlying AST byte span when merging adjacent line highlights, creating fake single-line lengths that swallowed inner action highlights.

What Changed

  • Relative Container Position Alignment: Updated isDisplacedMove in internal/serialize/align.go to calculate line offsets relative to the nearest mapped enclosing container. If a node stays inside the same mapped function or block at the same relative line offset, it is recognized as an in-place structural shift rather than a relocated move, so AlignLines pairs lines side-by-side with zero diagonal filler lines inside the function.
  • Span Priority by Total AST Byte Length: Added totalLen to span in internal/tui/highlight.go, propagating max(curr.totalLen, next.totalLen) when merging adjacent line highlights so wider container spans don't drop their true total length.
  • TUI Action Priority Tie-Breaking: Updated renderStyledLine in internal/tui/view.go to select highlights based on totalLen so narrower inner AST actions override wider outer container spans, with action kind tie-breaking preferring specific move and update actions over container insert and delete.
  • Test Baseline Expectations: Updated golden expected.json files across integration test fixtures to match the improved side-by-side line alignment.

Visual Comparison:

Example :- tests/testdata/go_gin_fix_lint

Before

image

After

image

@HarshK97
HarshK97 merged commit 33d5683 into main Aug 6, 2026
18 of 23 checks passed
@HarshK97
HarshK97 deleted the fix/tui-span-priority branch August 7, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant