- Notifications
You must be signed in to change notification settings - Fork664
Open
Description
A panic occurs when formatting a file from VSCode if the file contains multi-byte characters (e.g.,→
,🐈
or Japanese characters like日本語
) and ends with 2+ newlines.
Emitting the file via the command line (tsgo foo.ts
) works correctly without any panic.
Minimal repro:
- Enable TypeScript (Native Preview) in VSCode
- Create
foo.ts
with the following content. Ensure there are at least two newlines at the end.
"→" ;
- Open the Command Palette, select "Format Document With..." → "TypeScript (Native Preview)".
My environment:
- VSCode 1.102.0 on Windows 11
- Remote WSL (Ubuntu 24.04.2 LTS amd64)
typescriptteam.native-preview
extension version: 0.20250710.1
Error Log:
panic handling request textDocument/formatting runtime error: slice bounds out of range [:10] with length 9 goroutine 1172 [running]:runtime/debug.Stack()runtime/debug/stack.go:26 +0x5egithub.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1.1()github.com/microsoft/typescript-go/internal/lsp/server.go:351 +0x5dpanic({0xab9e40?, 0xc0027f71d0?})runtime/panic.go:792 +0x132github.com/microsoft/typescript-go/internal/ls.(*Converters).PositionToLineAndCharacter(0xc0002742a0, {0xd216d0, 0xc0000de008}, 0xa)github.com/microsoft/typescript-go/internal/ls/converters.go:236 +0x1adgithub.com/microsoft/typescript-go/internal/ls.(*Converters).ToLSPRange(0xc0002742a0, {0xd216d0, 0xc0000de008}, {0xa80e60?, 0x0?})github.com/microsoft/typescript-go/internal/ls/converters.go:36 +0x46github.com/microsoft/typescript-go/internal/ls.(*LanguageService).createLspRangeFromBounds(0xc00382eb10, 0x9, 0xa, 0xc0000de008)github.com/microsoft/typescript-go/internal/ls/utilities.go:400 +0x57github.com/microsoft/typescript-go/internal/ls.(*LanguageService).toLSProtoTextEdits(0xc00382eb10, 0xc0000de008, {0xc00382ec00, 0x2, 0xc000274288?})github.com/microsoft/typescript-go/internal/ls/format.go:31 +0xe5github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideFormatDocument(0xc00382eb10, {0xd228b0, 0xc000711770}, {0xc0001763c0?, 0x62e397?}, 0xc002f4bb20)github.com/microsoft/typescript-go/internal/ls/format.go:43 +0x7dgithub.com/microsoft/typescript-go/internal/lsp.(*Server).handleDocumentFormat(0xc0000b8000, {0xd228b0, 0xc000711770}, 0xc001e2dc80)github.com/microsoft/typescript-go/internal/lsp/server.go:726 +0xcagithub.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0xc0001ad608?, {0xd228b0?, 0xc000711770?}, 0x0?)github.com/microsoft/typescript-go/internal/lsp/server.go:486 +0xb3github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()github.com/microsoft/typescript-go/internal/lsp/server.go:364 +0x75created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 22github.com/microsoft/typescript-go/internal/lsp/server.go:382 +0x4d2[Error - 17:08:57] Request textDocument/formatting failed. Message: InternalError: panic handling request textDocument/formatting: runtime error: slice bounds out of range [:10] with length 9 Code: -32603