Skip to content

Commit 5e7965e

Browse files
committed
make code more clear
1 parent 657749f commit 5e7965e

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

gopls/internal/golang/signature_help.go

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,41 +47,30 @@ func SignatureHelp(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle
4747
}
4848
info := pkg.TypesInfo()
4949
var fnval ast.Expr
50-
FindCall:
50+
loop:
5151
for i, node := range path {
5252
switch node := node.(type) {
5353
case *ast.Ident:
54-
// If the selection is a function/method identifier,
54+
// If the selected text is a function/method Ident orSelectorExpr,
5555
// even one not in function call position,
5656
// show help for its signature. Example:
5757
// once.Do(initialize⁁)
5858
// 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
6966
}
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
7968
}
8069
case *ast.CallExpr:
8170
if pos >= node.Lparen && pos <= node.Rparen {
8271
callExpr = node
8372
fnval = callExpr.Fun
84-
break FindCall
73+
break loop
8574
}
8675
case *ast.FuncLit, *ast.FuncType:
8776
// The user is within an anonymous function,

0 commit comments

Comments
 (0)