microsoft/typescript-go

Panic in `getTokenAtPosition`

Closed this issue · 1 comments

Stack trace

panic handling request textDocument/definition did not expect KindParenthesizedExpression to have KindIdentifier in its trivia goroutine 257 [running]:
runtime/debug.Stack()
	C:/Program Files/Go/src/runtime/debug/stack.go:26 +0x8e
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0xc000168dc0, 0xc001b87860)
	c:/ts-go/internal/lsp/server.go:532 +0x53
panic({0x7ff6fa0c8080?, 0xc001aec730?})
	C:/Program Files/Go/src/runtime/panic.go:783 +0x136
github.com/microsoft/typescript-go/internal/astnav.getTokenAtPosition(0xc0008678c8, 0x35, 0x0, 0x7ff6fa3479b0)
	c:/ts-go/internal/astnav/tokens.go:176 +0x945
github.com/microsoft/typescript-go/internal/astnav.GetTouchingPropertyName(0xc0008678c8, 0x35)
	c:/ts-go/internal/astnav/tokens.go:12 +0x39
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideDefinition(0xc0002a2a68, {0x7ff6fa3d93d0, 0xc001974140}, {0xc0002a8408, 0x17}, {0x1, 0x22})
	c:/ts-go/internal/ls/definition.go:17 +0x14f
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleDefinition(0xc000168dc0, {0x7ff6fa3d93d0, 0xc001974140}, 0xc0002a2a68, 0xc001b87830)
	c:/ts-go/internal/lsp/server.go:735 +0xc9
github.com/microsoft/typescript-go/internal/lsp.registerLanguageServiceDocumentRequestHandler[...].func1({0x7ff6fa3d93d0, 0xc001974140}, 0xc001b87860)
	c:/ts-go/internal/lsp/server.go:518 +0x2a5
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0xc000168dc0, {0x7ff6fa3d93d0, 0xc001974140}, 0xc001b87860)
	c:/ts-go/internal/lsp/server.go:424 +0xb9
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
	c:/ts-go/internal/lsp/server.go:329 +0x65
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 23
	c:/ts-go/internal/lsp/server.go:349 +0x5c5

[Error - 1:22:40 PM] Request textDocument/definition failed.
  Message: InternalError: panic handling request textDocument/definition: did not expect KindParenthesizedExpression to have KindIdentifier in its trivia
  Code: -32603 

Steps to reproduce

Place the following code in a source file with a .js extension and go-to-definition on x in the type assertion.

function foo(x) {
    const s = /**@type {string}*/(x)  // Go-to-definition on x causes panic
}

@andrewbranch I think you wrote the code for getTokenAtPosition, so assigning to you.