Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 6, 2025

Requesting completions at the beginning of a property name preceded by JSDoc caused a nil pointer panic when accessing contextToken.Kind.

Root Cause

Variable shadowing in getRelevantTokens: Used := instead of =, creating a local variable that shadowed the return parameter, causing contextToken to return nil.

// Before: shadows the return parameter
contextToken := astnav.FindPrecedingToken(file, previousToken.Pos())

// After: assigns to return parameter
contextToken = astnav.FindPrecedingToken(file, previousToken.Pos())

Missing nil guards in tryGetClassLikeCompletionSymbols: tryGetObjectTypeDeclarationCompletionContainer can return a non-nil declaration when contextToken is nil (e.g., when location is an identifier in a class body).

Changes

  • Fixed variable shadowing in getRelevantTokens (line 2753)
  • Added nil checks before accessing contextToken.Kind and contextToken.Parent in tryGetClassLikeCompletionSymbols (lines 1447, 1461, 1464, 1471)
Original prompt

This section details on the original issue you should resolve

<issue_title>Crash completing beginning of property name when preceded by JSDoc</issue_title>
<issue_description>```ts
export class SomeInterface {
/** ruh-roh! /
/
$1*/property: string;
}

export class SomeClass {
/** ruh-roh! /
/
$2*/property = "value";
}


Request completions at the beginning of either property (markers `/*$1*/` and `/*$2*/`).

error] panic handling requesttextDocument/completionruntime error: invalid memory address or nil pointer dereferencegoroutine 23769 [running]:
runtime/debug.Stack()
runtime/debug/stack.go:26 +0x5e
github.com/microsoft/typescript-go/internal/lsp.(*Server).recover(0xc0001e4008, 0xc026483a10)
github.com/microsoft/typescript-go/internal/lsp/server.go:872 +0x58
panic({0xbddea0?, 0x16c8b70?})
runtime/panic.go:783 +0x132
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionData.func15()
github.com/microsoft/typescript-go/internal/ls/completions.go:1447 +0xba
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionData.func18(...)
github.com/microsoft/typescript-go/internal/ls/completions.go:1689
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionData(0xc029141380, {0x107d088, 0xc029141320}, 0xc036d90008, 0xc005362f08, 0x85, 0xc0097e1e00)
github.com/microsoft/typescript-go/internal/ls/completions.go:1717 +0x1edf
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).getCompletionsAtPosition(0xc029141380, {0x107d088, 0xc029141320}, 0xc005362f08, 0x85, 0x0)
github.com/microsoft/typescript-go/internal/ls/completions.go:383 +0x2cf
github.com/microsoft/typescript-go/internal/ls.(*LanguageService).ProvideCompletion(0xc029141380, {0x107d088, 0xc029141320}, {0xc0035e8690?, 0xc029141320?}, {0x35e8690?, 0xc0?}, 0xc02b74b0f0)
github.com/microsoft/typescript-go/internal/ls/completions.go:44 +0xc8
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleCompletion(0xc00140c008?, {0x107d088?, 0xc029141320?}, 0xc0035e8690?, 0x40b92c?)
github.com/microsoft/typescript-go/internal/lsp/server.go:1208 +0x39
github.com/microsoft/typescript-go/internal/lsp.init.func1.registerLanguageServiceDocumentRequestHandler[...].16({0x107d088, 0xc029141320}, 0xc026483a10)
github.com/microsoft/typescript-go/internal/lsp/server.go:621 +0x130
github.com/microsoft/typescript-go/internal/lsp.(*Server).handleRequestOrNotification(0xc0001e4008, {0x107d0c0?, 0xc01d1484b0?}, 0xc026483a10)
github.com/microsoft/typescript-go/internal/lsp/server.go:502 +0x14b
github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop.func1()
github.com/microsoft/typescript-go/internal/lsp/server.go:405 +0x3a
created by github.com/microsoft/typescript-go/internal/lsp.(*Server).dispatchLoop in goroutine 10
github.com/microsoft/typescript-go/internal/lsp/server.go:425 +0x9ad


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

<comments>
</comments>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI self-assigned this Dec 6, 2025
Copilot AI and others added 2 commits December 6, 2025 18:04
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
…SDoc

Fixed two issues:
1. Variable shadowing bug in getRelevantTokens where contextToken was declared with := instead of assigned with =, causing it to remain nil
2. Added nil checks in tryGetClassLikeCompletionSymbols to handle cases where contextToken is nil

These changes prevent the nil pointer dereference crash reported in the issue.

Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix crash on JSDoc completion request Fix nil pointer dereference in completion at property start after JSDoc Dec 6, 2025
Copilot finished work on behalf of DanielRosenwasser December 6, 2025 18:21
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.

Crash completing beginning of property name when preceded by JSDoc

2 participants