Skip to content

Prevent LSP position-conversion panic after content mapper failure - #65554

Merged
Daniel Rosenwasser (DanielRosenwasser) merged 4 commits into
mainfrom
copilot/fix-lsp-panics-slice-bounds
Nov 18, 2026
Merged

Daniel Rosenwasser (DanielRosenwasser) merged 4 commits into
mainfrom
copilot/fix-lsp-panics-slice-bounds

Conversation

@DanielRosenwasser

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

When a content mapper fails, its empty virtual file retains the original document’s line map. In a non-ASCII document, hover and inlay-hint requests can then scan beyond the virtual text and panic.

  • Change: Clamp line boundaries to the available virtual text before converting LSP positions.
  • Regression coverage: Exercise hover-position and inlay-hint range conversion against a failed-mapper placeholder.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) changed the title [WIP] Fix LSP panic with slice bounds out of range Prevent LSP position-conversion panic after content mapper failure Nov 17, 2026
assert.Equal(t, positions[1].Position, core.TextPos(2))
}

func TestConvertersFailedContentMapperPosition(t *testing.T) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This need a better explanation. What is failing? Why is it failing? What does this test prove?

@DanielRosenwasser

Copy link
Copy Markdown
Member Author

Copilot fix

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Copilot fix

Added an explanation above the regression test: failed mapping leaves empty virtual text with the original non-ASCII line map, so the second line's byte-3 start previously caused an out-of-bounds scan. The test verifies hover and inlay-hint conversions clamp to offset 0. Addressed in 2bb773470; targeted test and npx hereby validate pass.

@RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh) marked this pull request as ready for review November 18, 2026 18:25
Copilot AI balanced review requested due to automatic review settings November 18, 2026 18:25

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems OK to me but I'd like Andrew Branch (@andrewbranch) to check too

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 remain for the position-conversion bounds fix.

No open issues 🎉

What changed in this PR

Addresses #65547 by preventing TypeScript language-server position conversion from reading beyond an empty virtual file after a content mapper fails.

Changes:

  • Clamp line-start and line-end offsets to the available text length.
  • Add regression coverage for hover-position and inlay-hint range conversion with non-ASCII original text and a failed-mapper placeholder.
File Description
tsc/​internal/​ls/​lsconv/​converters.go Bounds line offsets before converting LSP positions.
tsc/​internal/​ls/​lsconv/​converters_test.go Verifies failed-mapper positions and ranges clamp to offset zero.

Review effort: Balanced

Merged via the queue into main with commit 665c1eb Nov 18, 2026
35 checks passed
@DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) deleted the copilot/fix-lsp-panics-slice-bounds branch November 18, 2026 19:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LSP panics with "slice bounds out of range" after a content mapper fails

5 participants