Skip to content

Commit 531ffef

Browse files
Copilotjakebailey
andcommitted
Fix panic when tokenAtPosition is nil in onTypeFormatting
Co-authored-by: jakebailey <[email protected]>
1 parent 26fdb17 commit 531ffef

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

internal/ls/format.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ func getRangeOfEnclosingComment(
140140
precedingToken *ast.Node,
141141
tokenAtPosition *ast.Node,
142142
) *ast.CommentRange {
143+
if tokenAtPosition == nil {
144+
return nil
145+
}
143146
jsdoc := ast.FindAncestor(tokenAtPosition, (*ast.Node).IsJSDoc)
144147
if jsdoc != nil {
145148
tokenAtPosition = jsdoc.Parent

internal/ls/utilities.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ func isExportSpecifierAlias(referenceLocation *ast.Identifier, exportSpecifier *
182182
}
183183

184184
func isInComment(file *ast.SourceFile, position int, tokenAtPosition *ast.Node) *ast.CommentRange {
185+
if tokenAtPosition == nil {
186+
tokenAtPosition = astnav.GetTokenAtPosition(file, position)
187+
}
185188
return getRangeOfEnclosingComment(file, position, astnav.FindPrecedingToken(file, position), tokenAtPosition)
186189
}
187190

0 commit comments

Comments
 (0)