From a28e0491153cf9b4d861941e50026ca0a3690942 Mon Sep 17 00:00:00 2001 From: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com> Date: Tue, 17 Nov 2026 21:01:11 +0000 Subject: [PATCH 1/4] Initial plan From 0a120a6c49d9bc5afa9b40e50b097675b3276ae1 Mon Sep 17 00:00:00 2001 From: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com> Date: Tue, 17 Nov 2026 21:04:39 +0000 Subject: [PATCH 2/4] Add regression test for failed content mapper position Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- tsc/internal/ls/lsconv/converters_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tsc/internal/ls/lsconv/converters_test.go b/tsc/internal/ls/lsconv/converters_test.go index 6a2e9d3d639e5..e420a5efbc6ba 100644 --- a/tsc/internal/ls/lsconv/converters_test.go +++ b/tsc/internal/ls/lsconv/converters_test.go @@ -271,6 +271,20 @@ func TestConvertersSourceFileProjectionExpansion(t *testing.T) { assert.Equal(t, positions[1].Position, core.TextPos(2)) } +func TestConvertersFailedContentMapperPosition(t *testing.T) { + t.Parallel() + original := "é\nhover here\n" + file := parser.ParseSourceFile(ast.SourceFileParseOptions{FileName: "/component.box", PathKey: "/component.box"}, "", core.ScriptKindTS) + file.SetContentMapperInfo(ast.ContentMapperSourceFileInfo{OriginalText: original, ContentMapper: "mapper"}) + assert.Assert(t, file.IsContentMapperFailureStub()) + + lineMap := lsconv.ComputeLSPLineStarts(original) + converters := lsconv.NewConverters(lsproto.PositionEncodingKindUTF16, func(_ tspath.RootedFilePath) *lsconv.LSPLineMap { return lineMap }) + positions := converters.FromLSPPositionForSourceFile(file, lsproto.Position{Line: 1, Character: 2}, spanmap.FeatureHover) + assert.Equal(t, len(positions), 1) + assert.Equal(t, positions[0].Position, core.TextPos(0)) +} + // TestConvertersInvalidUTF8 verifies behavior on text containing invalid UTF-8 // sequences (e.g. lone continuation bytes). Node's TextDecoder substitutes such // bytes with U+FFFD, so the JS-reference test cannot cover this; we assert the From 3296e3c8af49892033d1ff07c99256f58356901f Mon Sep 17 00:00:00 2001 From: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com> Date: Tue, 17 Nov 2026 21:05:17 +0000 Subject: [PATCH 3/4] Clamp failed-mapper positions to available virtual text Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- tsc/internal/ls/lsconv/converters.go | 3 ++- tsc/internal/ls/lsconv/converters_test.go | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tsc/internal/ls/lsconv/converters.go b/tsc/internal/ls/lsconv/converters.go index de4c34a2ad25b..614fab48b08f0 100644 --- a/tsc/internal/ls/lsconv/converters.go +++ b/tsc/internal/ls/lsconv/converters.go @@ -373,7 +373,7 @@ func (c *Converters) lineAndCharacterToPosition(script Script, lineAndCharacter return textLen } - start := lineMap.LineStarts[line] + start := min(lineMap.LineStarts[line], textLen) // Determine the end of this line (start of next line, or end of text). var lineEnd core.TextPos @@ -382,6 +382,7 @@ func (c *Converters) lineAndCharacterToPosition(script Script, lineAndCharacter } else { lineEnd = textLen } + lineEnd = min(lineEnd, textLen) if lineMap.AsciiOnly || c.positionEncoding == lsproto.PositionEncodingKindUTF8 { return max(start, min(start+char, lineEnd)) diff --git a/tsc/internal/ls/lsconv/converters_test.go b/tsc/internal/ls/lsconv/converters_test.go index e420a5efbc6ba..bdee6c12dc1ba 100644 --- a/tsc/internal/ls/lsconv/converters_test.go +++ b/tsc/internal/ls/lsconv/converters_test.go @@ -283,6 +283,13 @@ func TestConvertersFailedContentMapperPosition(t *testing.T) { positions := converters.FromLSPPositionForSourceFile(file, lsproto.Position{Line: 1, Character: 2}, spanmap.FeatureHover) assert.Equal(t, len(positions), 1) assert.Equal(t, positions[0].Position, core.TextPos(0)) + + ranges := converters.FromLSPRangeIntersectingForSourceFile(file, lsproto.Range{ + Start: lsproto.Position{Line: 1}, + End: lsproto.Position{Line: 1, Character: 5}, + }, spanmap.FeatureInlayHints) + assert.Equal(t, len(ranges), 1) + assert.Equal(t, ranges[0].Span, core.NewTextRange(0, 0)) } // TestConvertersInvalidUTF8 verifies behavior on text containing invalid UTF-8 From 2bb773470746d4c9d553a36afa58035425acddb3 Mon Sep 17 00:00:00 2001 From: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com> Date: Tue, 17 Nov 2026 22:01:09 +0000 Subject: [PATCH 4/4] Explain failed-mapper regression test and panic path Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> --- tsc/internal/ls/lsconv/converters_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tsc/internal/ls/lsconv/converters_test.go b/tsc/internal/ls/lsconv/converters_test.go index bdee6c12dc1ba..1502cd466f469 100644 --- a/tsc/internal/ls/lsconv/converters_test.go +++ b/tsc/internal/ls/lsconv/converters_test.go @@ -271,6 +271,10 @@ func TestConvertersSourceFileProjectionExpansion(t *testing.T) { assert.Equal(t, positions[1].Position, core.TextPos(2)) } +// A failed mapper leaves an empty virtual file without a span map, while the line map still +// describes the non-ASCII original text. Its second line starts at byte 3, so converting +// hover positions and inlay-hint ranges previously tried to scan the empty file from +// offset 3 and panicked. Both requests must instead clamp to the virtual file's offset 0. func TestConvertersFailedContentMapperPosition(t *testing.T) { t.Parallel() original := "é\nhover here\n"