@@ -47,41 +47,30 @@ func SignatureHelp(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle
47
47
}
48
48
info := pkg .TypesInfo ()
49
49
var fnval ast.Expr
50
- FindCall :
50
+ loop :
51
51
for i , node := range path {
52
52
switch node := node .(type ) {
53
53
case * ast.Ident :
54
- // If the selection is a function/method identifier ,
54
+ // If the selected text is a function/method Ident orSelectorExpr ,
55
55
// even one not in function call position,
56
56
// show help for its signature. Example:
57
57
// once.Do(initialize⁁)
58
58
// should show help for initialize, not once.Do.
59
- if info .Defs [node ] == nil &&
60
- info .TypeOf (node ) != nil &&
61
- is [* types.Signature ](info .TypeOf (node ).Underlying ()) {
62
- // golang/go#68922: offer signature help when the
63
- // cursor over ident or function name.
64
- // No enclosing call found.
65
- // If the selection is an Ident of func type, use that instead.
66
- fnval = node
67
- if _ , ok := info .Types [fnval ]; ok {
68
- break FindCall
59
+ if t := info .TypeOf (node ); t != nil &&
60
+ info .Defs [node ] == nil &&
61
+ is [* types.Signature ](t .Underlying ()) {
62
+ if sel , ok := path [i + 1 ].(* ast.SelectorExpr ); ok && sel .Sel == node {
63
+ fnval = sel // e.g. fmt.Println⁁
64
+ } else {
65
+ fnval = node
69
66
}
70
-
71
- if len (path ) <= i + 1 {
72
- continue
73
- }
74
- if s , ok := path [i + 1 ].(* ast.SelectorExpr ); ok {
75
- fnval = s
76
- }
77
-
78
- break FindCall
67
+ break loop
79
68
}
80
69
case * ast.CallExpr :
81
70
if pos >= node .Lparen && pos <= node .Rparen {
82
71
callExpr = node
83
72
fnval = callExpr .Fun
84
- break FindCall
73
+ break loop
85
74
}
86
75
case * ast.FuncLit , * ast.FuncType :
87
76
// The user is within an anonymous function,
0 commit comments