Skip to content

Commit

Permalink
feat(go_indexer): add anchor scope to func literals (#5840)
Browse files Browse the repository at this point in the history
  • Loading branch information
schroederc committed Sep 12, 2023
1 parent b3e3ff6 commit f3c56bc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 6 additions & 3 deletions kythe/go/indexer/emit.go
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
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() {}
}

0 comments on commit f3c56bc

Please sign in to comment.