Skip to content

Commit b2ea1ec

Browse files
committed
update:support overload anonymous reference
1 parent ab79a37 commit b2ea1ec

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

gopls/internal/lsp/source/implementation_gox.go

+3
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,9 @@ func gopPathEnclosingObjNode(f *ast.File, pos token.Pos) []ast.Node {
430430
if pos == n.Star {
431431
pos = n.X.Pos()
432432
}
433+
case *ast.FuncLit:
434+
//goxls:overload anonymous function
435+
found = n.Type.Func <= pos && pos <= n.Type.Func+token.Pos(len("func"))
433436
}
434437

435438
return !found

gopls/internal/lsp/source/references_gox.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,11 @@ func gopOrdinaryReferences(ctx context.Context, snapshot Snapshot, uri span.URI,
461461
// Report the locations of the declaration(s).
462462
// TODO(adonovan): what about for corresponding methods? Add tests.
463463
for _, node := range objects {
464-
report(gopMustLocation(pgf, node), true)
464+
if funcLit, ok := node.(*ast.FuncLit); ok {
465+
report(gopMustLocation(pgf, funcLit.Type), true)
466+
} else {
467+
report(gopMustLocation(pgf, node), true)
468+
}
465469
}
466470

467471
// Convert targets map to set.
@@ -581,6 +585,9 @@ func gopObjectsAt(info *typesutil.Info, file *ast.File, pos token.Pos) (map[type
581585
return nil, nil, fmt.Errorf("%w for import %s", errNoObjectFound, GopUnquoteImportPath(leaf))
582586
}
583587
targets[obj] = leaf
588+
case *ast.FuncLit:
589+
obj := info.Implicits[leaf]
590+
targets[obj] = leaf
584591
}
585592

586593
if len(targets) == 0 {

0 commit comments

Comments
 (0)