-
Notifications
You must be signed in to change notification settings - Fork 664
Open
Labels
CrashDomain: EditorRelated to the LSP server, editor experienceRelated to the LSP server, editor experience
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 +0x5e
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1.1()
github.com/microsoft/typescript-go/internal/lsp/server.go:351 +0x5d
panic({0xab9e40?, 0xc0027f71d0?})
runtime/panic.go:792 +0x132
github.com/microsoft/typescript-go/internal/ls.(*Converters).PositionToLineAndCharacter(0xc0002742a0, {0xd216d0, 0xc0000de008}, 0xa)
github.com/microsoft/typescript-go/internal/ls/converters.go:236 +0x1ad
github.com/microsoft/typescript-go/internal/ls.(*Converters).ToLSPRange(0xc0002742a0, {0xd216d0, 0xc0000de008}, {0xa80e60?, 0x0?})
github.com/microsoft/typescript-go/internal/ls/converters.go:36 +0x46
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).createLspRangeFromBounds(0xc00382eb10, 0x9, 0xa, 0xc0000de008)
github.com/microsoft/typescript-go/internal/ls/utilities.go:400 +0x57
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).toLSProtoTextEdits(0xc00382eb10, 0xc0000de008, {0xc00382ec00, 0x2, 0xc000274288?})
github.com/microsoft/typescript-go/internal/ls/format.go:31 +0xe5
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideFormatDocument(0xc00382eb10, {0xd228b0, 0xc000711770}, {0xc0001763c0?, 0x62e397?}, 0xc002f4bb20)
github.com/microsoft/typescript-go/internal/ls/format.go:43 +0x7d
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleDocumentFormat(0xc0000b8000, {0xd228b0, 0xc000711770}, 0xc001e2dc80)
github.com/microsoft/typescript-go/internal/lsp/server.go:726 +0xca
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0xc0001ad608?, {0xd228b0?, 0xc000711770?}, 0x0?)
github.com/microsoft/typescript-go/internal/lsp/server.go:486 +0xb3
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
github.com/microsoft/typescript-go/internal/lsp/server.go:364 +0x75
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 22
github.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
Copilot
Metadata
Metadata
Assignees
Labels
CrashDomain: EditorRelated to the LSP server, editor experienceRelated to the LSP server, editor experience