Skip to content

Commit

Permalink
update:support overload anonymous reference
Browse files Browse the repository at this point in the history
  • Loading branch information
luoliwoshang committed May 9, 2024
1 parent ab79a37 commit b2ea1ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions gopls/internal/lsp/source/implementation_gox.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ func gopPathEnclosingObjNode(f *ast.File, pos token.Pos) []ast.Node {
if pos == n.Star {
pos = n.X.Pos()
}
case *ast.FuncLit:
//goxls:overload anonymous function
found = n.Type.Func <= pos && pos <= n.Type.Func+token.Pos(len("func"))
}

return !found
Expand Down
9 changes: 8 additions & 1 deletion gopls/internal/lsp/source/references_gox.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,11 @@ func gopOrdinaryReferences(ctx context.Context, snapshot Snapshot, uri span.URI,
// Report the locations of the declaration(s).
// TODO(adonovan): what about for corresponding methods? Add tests.
for _, node := range objects {
report(gopMustLocation(pgf, node), true)
if funcLit, ok := node.(*ast.FuncLit); ok {
report(gopMustLocation(pgf, funcLit.Type), true)
} else {
report(gopMustLocation(pgf, node), true)
}
}

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

if len(targets) == 0 {
Expand Down

0 comments on commit b2ea1ec

Please sign in to comment.