Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(go_indexer): add anchor scope to func literals #5840

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions kythe/go/indexer/emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,10 @@ func (e *emitter) visitFuncLit(flit *ast.FuncLit, stack stackFunc) {
info.vname.Language = govname.Language
info.vname.Signature += "$" + strconv.Itoa(fi.numAnons)
e.pi.function[flit] = info
e.writeDef(flit, info.vname)
def := e.writeDef(flit, info.vname)
if e.opts.emitAnchorScopes() {
e.writeEdge(def, fi.vname, edges.ChildOf)
}
e.writeFact(info.vname, facts.NodeKind, nodes.Function)

if sig, ok := e.pi.Info.Types[flit].Type.(*types.Signature); ok {
Expand Down Expand Up @@ -1247,8 +1250,8 @@ func (e *emitter) writeBinding(id *ast.Ident, kind string, parent *spb.VName) *s

// writeDef emits a spanning anchor and defines edge for the specified node.
// This function does not create the target node.
func (e *emitter) writeDef(node ast.Node, target *spb.VName) {
e.writeRef(node, target, edges.Defines)
func (e *emitter) writeDef(node ast.Node, target *spb.VName) *spb.VName {
return e.writeRef(node, target, edges.Defines)
}

// writeDoc adds associations between comment groups and a documented node.
Expand Down
4 changes: 4 additions & 0 deletions kythe/go/indexer/testdata/basic/scopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ func F() {
//- IdentRef=@Ident ref/writes Ident
//- IdentRef childof F
Ident = true

//- AnonDef=@"func() {}" defines _Anon
//- AnonDef childof F
_ = func() {}
}