Skip to content

Clamp incremental update lines to the end of the document - #1927

Open
Trivikram Kamat (trivikr) wants to merge 1 commit into
microsoft:mainfrom
trivikr:textDocument-clamp-update-lines-end-doc
Open

Trivikram Kamat (trivikr) wants to merge 1 commit into
microsoft:mainfrom
trivikr:textDocument-clamp-update-lines-end-doc

Conversation

@trivikr

Copy link
Copy Markdown
Contributor

FullTextDocument.update clamped startLine/endLine to 0 but not to the last line. An incremental change starting past the end of the document could leave holes in the line offsets, so lineCount came out wrong and positionAt/offsetAt returned NaN/undefined.

const d = TextDocument.create('file:///a', 'txt', 0, 'a\nb');
TextDocument.update(d, [{ range: { start: { line: 5, character: 0 }, end: { line: 6, character: 0 } }, text: 'x\n' }], 1);
d.lineCount; // 7, expected 3

This PR clamps both lines to the last line index, the same way offsetAt handles out-of-range positions, and adds a regression test.

Copilot AI balanced review requested due to automatic review settings October 28, 2026 05:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

FullTextDocument.update clamped startLine and endLine to 0 but not to
the last line. An incremental change whose range starts past the end
of the document wrote line offsets at indexes beyond the array,
leaving holes. lineCount was then wrong, and positionAt/offsetAt
returned NaN/undefined until the next full update.

Clamp both lines to the last line index, the same way offsetAt
already treats out-of-range positions.
@trivikr
Trivikram Kamat (trivikr) force-pushed the textDocument-clamp-update-lines-end-doc branch from aea981d to 7d735b1 Compare November 2, 2026 20:53
Copilot AI balanced review requested due to automatic review settings November 2, 2026 20:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the change addressing incremental updates beyond the document’s end.

No open issues 🎉

Review effort: Balanced

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.

2 participants