microsoft/typescript-go

Panic Handling textDocument/onTypeFormatting

Closed this issue · 7 comments

Stack trace

panic handling request textDocument/onTypeFormatting runtime error: invalid memory address or nil pointer dereference goroutine 1314 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:26 +0x64
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0x1400010adc0, 0x1400ae41d40)
	github.com/microsoft/typescript-go/internal/lsp/server.go:532 +0x44
panic({0x1011dd960?, 0x101aa2250?})
	runtime/panic.go:783 +0x120
github.com/microsoft/typescript-go/internal/ast.(*Node).Pos(...)
	github.com/microsoft/typescript-go/internal/ast/ast.go:240
github.com/microsoft/typescript-go/internal/scanner.GetTokenPosOfNode(0xa?, 0x140032e92a8?, 0x0?)
	github.com/microsoft/typescript-go/internal/scanner/scanner.go:2318 +0xa8
github.com/microsoft/typescript-go/internal/astnav.GetStartOfNode(...)
	github.com/microsoft/typescript-go/internal/astnav/tokens.go:380
github.com/microsoft/typescript-go/internal/ls.getRangeOfEnclosingComment(0x140031b4588, 0x1, 0x0, 0x0)
	github.com/microsoft/typescript-go/internal/ls/format.go:147 +0x90
github.com/microsoft/typescript-go/internal/ls.isInComment(0x140031b4588, 0x1, 0x0)
	github.com/microsoft/typescript-go/internal/ls/utilities.go:185 +0x44
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getFormattingEditsAfterKeystroke(0x14007775c38?, {0x1013bc710?, 0x1400669f220?}, 0x140031b4588, 0x14009dde480?, 0x1, {0x1011257b0, 0x1})
	github.com/microsoft/typescript-go/internal/ls/format.go:116 +0x60
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideFormatDocumentOnType(0x14007775c68, {0x1013bc710, 0x1400669f220}, {0x1400ae7a1c0?, 0x1?}, 0x1400ae549c0, {0x2580000?, 0x140?}, {0x1011257b0, 0x1})
	github.com/microsoft/typescript-go/internal/ls/format.go:78 +0xfc
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleDocumentOnTypeFormat(0x140003521c0?, {0x1013bc710?, 0x1400669f220?}, 0x1400ae7a1c0?, 0x34?)
	github.com/microsoft/typescript-go/internal/lsp/server.go:806 +0x40
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].21({0x1013bc710, 0x1400669f220}, 0x1400ae41d40)
	github.com/microsoft/typescript-go/internal/lsp/server.go:518 +0xe0
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0x1400010adc0, {0x1013bc710, 0x1400669f220}, 0x1400ae41d40)
	github.com/microsoft/typescript-go/internal/lsp/server.go:424 +0xf4
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
	github.com/microsoft/typescript-go/internal/lsp/server.go:329 +0x34
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 34
	github.com/microsoft/typescript-go/internal/lsp/server.go:349 +0x6f8

Steps to reproduce

  1. Create an empty directory
  2. npm init -y
  3. npm install --save @typescript/native-preview
  4. Open an empty index.ts file
  5. Press <enter> to insert a newline

7.0.0-dev.20250716.1 appears to be the first version that exhibits this problem.

Record of my testing:

  • 7.0.0-dev.20250801.1 reproduces
  • 7.0.0-dev.20250701.1 does not
  • 7.0.0-dev.20250715.1 does not
  • 7.0.0-dev.20250723.1 does
  • 7.0.0-dev.20250719.1 does
  • 7.0.0-dev.20250716.1 does

So likely e62a044 ?

@DanielRosenwasser FYI performed the binary search you asked for on #1719

Verified that I can no longer reproduce with v7.0.0-dev.20251021.1. Thanks!

Girbi commented

I still get this panic error

@Girbi can you log a new issue with repro steps? Thanks!

@Girbi can you log a new issue with repro steps? Thanks!

I created one here: #2042