Skip to content

Commit 9a0b323

Browse files
Fix signature help crash for type arguments when call target is unresolved (#2295)
1 parent ae37f82 commit 9a0b323

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

internal/fourslash/tests/signatureHelpCrash_test.go renamed to internal/fourslash/tests/signatureHelpBetweenTypeArgsAndArgs_test.go

File renamed without changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/testutil"
8+
)
9+
10+
func TestSignatureHelpOnTypeArgumentsWithUnresolvedTarget(t *testing.T) {
11+
t.Parallel()
12+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
13+
const content = `
14+
/*1*/un/*2*/resolvedVal/*3*/</*4*/Un/*5*/resolvedType/*6*/>/*7*/(/*8*/un/*9*/resolvedVal/*10*/);
15+
`
16+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
17+
defer done()
18+
19+
f.GoToEachMarker(t, nil, func(marker *fourslash.Marker, index int) {
20+
f.VerifyNoSignatureHelp(t)
21+
})
22+
}

internal/ls/signaturehelp.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,12 @@ func getCandidateOrTypeInfo(info *argumentListInfo, c *checker.Checker, sourceFi
670670
if onlyUseSyntacticOwners && !isSyntacticOwner(startingToken, info.invocation.callInvocation.node, sourceFile) {
671671
return nil
672672
}
673+
673674
resolvedSignature, candidates := checker.GetResolvedSignatureForSignatureHelp(info.invocation.callInvocation.node, info.argumentCount, c)
674675
if len(candidates) == 0 {
675676
return nil
676677
}
678+
677679
return &CandidateOrTypeInfo{
678680
candidateInfo: &candidateInfo{
679681
candidates: candidates,
@@ -687,9 +689,11 @@ func getCandidateOrTypeInfo(info *argumentListInfo, c *checker.Checker, sourceFi
687689
if ast.IsIdentifier(called) {
688690
container = called.Parent
689691
}
692+
690693
if onlyUseSyntacticOwners && !containsPrecedingToken(startingToken, sourceFile, container) {
691694
return nil
692695
}
696+
693697
candidates := getPossibleGenericSignatures(called, info.argumentCount, c)
694698
if len(candidates) != 0 {
695699
return &CandidateOrTypeInfo{
@@ -699,11 +703,17 @@ func getCandidateOrTypeInfo(info *argumentListInfo, c *checker.Checker, sourceFi
699703
},
700704
}
701705
}
702-
symbol := c.GetSymbolAtLocation(called)
703-
return &CandidateOrTypeInfo{
704-
typeInfo: symbol,
706+
707+
if symbol := c.GetSymbolAtLocation(called); symbol != nil {
708+
return &CandidateOrTypeInfo{
709+
typeInfo: symbol,
710+
}
705711
}
712+
713+
// This can happen in the case of an unresolved symbol.
714+
return nil
706715
}
716+
707717
if info.invocation.contextualInvocation != nil {
708718
return &CandidateOrTypeInfo{
709719
candidateInfo: &candidateInfo{

0 commit comments

Comments
 (0)