Skip to content

Respect the exclusive TextRange.end in add_messages_for_semantic_ref (#372) - #376

Open
Kevin Turcios (KRRT7) wants to merge 1 commit into
microsoft:mainfrom
KRRT7:semantic-ref-range-exclusive-end
Open

Kevin Turcios (KRRT7) wants to merge 1 commit into
microsoft:mainfrom
KRRT7:semantic-ref-range-exclusive-end

Conversation

@KRRT7

Copy link
Copy Markdown
Contributor

Fixes #372.

Behavior

MessageAccumulator.add_messages_for_semantic_ref looped over range(start.message_ordinal, end.message_ordinal + 1), treating TextRange.end as inclusive. The end is exclusive (its chunk_ordinal is 1 + the last chunk in the range), so when end.chunk_ordinal == 0 the message end.message_ordinal holds none of the range's text but was still added to the matches. For example, TextRange(TextLocation(0), TextLocation(1)) covers exactly message 0 but also added message 1. text_range_from_message_range produces ranges of this shape.

Now end.message_ordinal is included only when end.chunk_ordinal > 0. Ranges ending inside a message, and ranges within a single message, keep including that message as before.

Validation

  • New test_add_messages_for_semantic_ref_exclusive_end covers a point range, a range of exactly one message, an end at chunk 0, an end inside a message, and a range within one message. The first two range cases fail on main.
  • New test_add_messages_for_semantic_ref_matches_text_range_containment checks every well-formed range with endpoints in messages 0–3, chunks 0–3: the accumulator adds exactly the messages that have a chunk contained in the range per TextRange.__contains__. It fails on main.
  • make format check test passes: 939 passed, 12 skipped.

…icrosoft#372)

The loop ran through end.message_ordinal inclusive, so a range ending at
chunk 0 of a message also added that message, which holds none of the
range's text. Include end.message_ordinal only when end.chunk_ordinal > 0.
@KRRT7
Kevin Turcios (KRRT7) marked this pull request as ready for review October 25, 2026 09:29

This branch has not been deployed

No deployments
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.

MessageAccumulator.add_messages_for_semantic_ref treats the exclusive TextRange.end as inclusive

1 participant