Skip to content

fix(serialize): partition overlapping highlight spans into disjoint segments - #170

Merged
HarshK97 merged 1 commit into
mainfrom
fix/serialize-disjoint-spans
Sep 20, 2026
Merged

HarshK97 merged 1 commit into
mainfrom
fix/serialize-disjoint-spans

Conversation

@HarshK97

Copy link
Copy Markdown
Owner

Problem

  1. When AST actions nested (such as an update inside a moved block), BuildHighlightSpans emitted overlapping column ranges on the same line.
  2. Downstream consumers like the UI renderer and JSON API expect highlight spans to be pairwise disjoint on each line, otherwise token styling either clashes or requires redundant resolution logic in the renderer.

What Changed

  • Added partitionLineSpans in internal/serialize/spans.go to split overlapping spans at column boundaries and pick one winner per atomic segment.
  • Resolved ties by picking the narrowest AST byte range first (most specific node), then narrowest column width, then action priority (move_update > update > move > insert > delete).
  • Coalesced adjacent segments with identical actions back into unified spans.
  • Promoted updates carved out of an enclosing move directly to move_update.
  • Added unit tests in internal/serialize/spans_test.go covering coextensive duplicates, nested updates inside moves, three-way ties, and fallback ordering.
  • Added TestNoOverlappingSpans in tests/integration/pipeline_test.go to verify that all highlight spans are pairwise disjoint across all 150 golden test fixtures.
  • Updated affected UI golden fixtures to reflect the partitioned span boundaries.

…egments

Spans could overlap when actions nested (e.g. update inside a move),
breaking consumers that assume disjoint spans per line.

Add partitionLineSpans: splits overlapping spans at boundary columns,
picks one winner per segment (narrowest AST range, then narrowest
span width, then action priority), coalesces adjacent same-action
segments, and promotes updates carved out of a move back to
move_update.
@HarshK97
HarshK97 merged commit f2c7647 into main Sep 20, 2026
17 checks passed
@HarshK97
HarshK97 deleted the fix/serialize-disjoint-spans branch September 20, 2026 13:54
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