Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

Language service panics when requesting completions after an import keyword preceded by JSDoc comments:

/** hello! */
import /*$*/  // Completions crash here

Root Cause

getSingleLineReplacementSpanForImportCompletionNode uses node.Pos() to check if the import spans multiple lines. When JSDoc precedes the import, node.Pos() includes the comment range, incorrectly indicating a multiline span and triggering the panic path.

Changes

  • internal/ls/completions.go: Use scanner.GetTokenPosOfNode(node, sourceFile, false) instead of node.Pos() to exclude JSDoc/trivia when checking line span
  • internal/fourslash/tests/manual/completionAfterImportWithJSDoc_test.go: Add regression test
Original prompt

This section details on the original issue you should resolve

<issue_title>Completions crash after import when statement is preceded by JSDoc</issue_title>
<issue_description>```ts
/** hello! /
import /
$*/


Request completions at `/*$*/`

[error] panic handling request textDocument/completion: ImportKeyword was necessarily on one line; ImportSpecifier was necessarily parented in an ImportDeclaration
goroutine 15057 [running]:
runtime/debug.Stack()
/usr/local/go/src/runtime/debug/stack.go:26 +0x5e
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0xc000140708, {0x441ae5?, 0xc01457e540?}, 0xc027b0ce40)
/workspaces/typescript-go/internal/lsp/server.go:777 +0x4c
panic({0xbf2f40?, 0x10ebe70?})
/usr/local/go/src/runtime/panic.go:783 +0x132
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getSingleLineReplacementSpanForImportCompletionNode(0xc026445540, 0xc0233a4420)
/workspaces/typescript-go/internal/ls/completions.go:5131 +0x24e
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getImportStatementCompletionInfo(0xc026445540, 0xc0233a4420, 0xc02734d600?)
/workspaces/typescript-go/internal/ls/completions.go:5107 +0x36d
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionData(0xc026445540, {0x10f6028, 0xc026650bd0}, 0xc0122d6608, 0xc0273f0a88, 0xe, 0xc00d0db400)
/workspaces/typescript-go/internal/ls/completions.go:528 +0x30a
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionsAtPosition(0xc026445540, {0x10f6028, 0xc026650bd0}, 0xc0273f0a88, 0xe, 0x0)
/workspaces/typescript-go/internal/ls/completions.go:347 +0x35f
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideCompletion(0xc026445540, {0x10f6028, 0xc026650b10}, {0xc00184c2d0?, 0xc026650b10?}, {0x184c2d0?, 0xc0?}, 0xc027b0ab00)
/workspaces/typescript-go/internal/ls/completions.go:47 +0x11c
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleCompletion(0x418834?, {0x10f6028?, 0xc026650b10?}, 0xc00184c2d0?, 0x10f6028?)
/workspaces/typescript-go/internal/lsp/server.go:1095 +0x39
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceWithAutoImportsRequestHandler[...].28({0x10f6028, 0xc026650b10}, 0xc027b0ce40)
/workspaces/typescript-go/internal/lsp/server.go:682 +0x16c
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0xc000140708, {0x10f6060?, 0xc026035ea0?}, 0xc027b0ce40)
/workspaces/typescript-go/internal/lsp/server.go:531 +0x1c6
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
/workspaces/typescript-go/internal/lsp/server.go:414 +0x3a
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 10
/workspaces/typescript-go/internal/lsp/server.go:438 +0x9f1


## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Use token position instead of node position when checking if import is on single line to avoid including JSDoc comments in the range calculation.

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix completions crash after import with preceding JSDoc Fix crash when completing after import preceded by JSDoc Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Completions crash after import when statement is preceded by JSDoc

2 participants