Skip to content

Commit 5dfaf73

Browse files
committed
fix: Work on both the function name and the identifier
1 parent cb31975 commit 5dfaf73

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

gopls/gopls

30.2 MB
Binary file not shown.

gopls/internal/golang/signature_help.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func SignatureHelp(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle
3939
if err != nil {
4040
return nil, 0, err
4141
}
42-
// Find a call/SelectorExpr expression surrounding the query position.
42+
// Find a Ident/Call/SelectorExpr expression surrounding the query position.
4343
var callNode ast.Node
4444
path, _ := astutil.PathEnclosingInterval(pgf.File, pos, pos)
4545
if path == nil {
@@ -49,6 +49,8 @@ FindCall:
4949
for _, node := range path {
5050
switch node := node.(type) {
5151
case *ast.SelectorExpr, *ast.Ident:
52+
// golang/go#68922: offer signature help when the
53+
// cursor over ident or function name.
5254
if pos >= node.Pos() && pos <= node.End() {
5355
callNode = node
5456
}
@@ -86,7 +88,12 @@ FindCall:
8688
case *ast.Ident:
8789
expr = node
8890
case *ast.SelectorExpr:
89-
expr = node
91+
// If the cursor not on the sel, it is over the function name.
92+
if pos >= node.Sel.Pos() && pos <= node.Sel.End() {
93+
expr = node
94+
} else {
95+
expr = node.X
96+
}
9097
case *ast.CallExpr:
9198
if node.Fun == nil {
9299
return nil, 0, nil

gopls/internal/test/marker/marker_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ func Test(t *testing.T) {
115115

116116
for _, test := range tests {
117117
test := test
118+
if !strings.Contains(test.name, "signature.txt") {
119+
continue
120+
}
118121
t.Run(test.name, func(t *testing.T) {
119122
t.Parallel()
120123
if test.skipReason != "" {

0 commit comments

Comments
 (0)