Repository navigation
Prevent LSP position-conversion panic after content mapper failure - #65554
Daniel Rosenwasser (DanielRosenwasser) merged 4 commits into
Conversation
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>
| assert.Equal(t, positions[1].Position, core.TextPos(2)) | ||
| } | ||
|
|
||
| func TestConvertersFailedContentMapperPosition(t *testing.T) { |
There was a problem hiding this comment.
This need a better explanation. What is failing? Why is it failing? What does this test prove?
|
Copilot fix |
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
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 |
Ryan Cavanaugh (RyanCavanaugh)
left a comment
There was a problem hiding this comment.
Seems OK to me but I'd like Andrew Branch (@andrewbranch) to check too
There was a problem hiding this comment.
🟢 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
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.