Skip to content

Commit 6f39760

Browse files
committed
fix(golang): continue parsing chained selector method calls
Allow selector traversal to keep visiting chained method calls instead of returning early, so downstream calls can still be collected during Go parsing.
1 parent 56e878a commit 6f39760

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

lang/golang/parser/file.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,6 @@ func (p *GoParser) parseSelector(ctx *fileContext, expr *ast.SelectorExpr, infos
354354
} else if sel, ok := expr.X.(*ast.SelectorExpr); ok {
355355
// recurse call
356356
cont = p.parseSelector(ctx, sel, infos)
357-
} else {
358-
// try to get type info of field first
359-
if ti := ctx.GetTypeInfo(expr); ti.Ty != nil {
360-
if _, ok := ti.Ty.(*types.Signature); ok {
361-
// collect method call
362-
// method call
363-
rev := ctx.GetTypeInfo(expr.X)
364-
if !rev.IsStdOrBuiltin {
365-
id := NewIdentity(rev.Id.ModPath, rev.Id.PkgPath, rev.Id.Name+"."+expr.Sel.Name)
366-
dep := NewDependency(id, ctx.FileLine(expr.Sel))
367-
infos.methodCalls = InsertDependency(infos.methodCalls, dep)
368-
}
369-
}
370-
}
371-
return true
372357
}
373358

374359
// method calls
@@ -398,9 +383,14 @@ func (p *GoParser) parseSelector(ctx *fileContext, expr *ast.SelectorExpr, infos
398383
if err := p.referCodes(ctx, &id, p.opts.ReferCodeDepth); err != nil {
399384
fmt.Fprintf(os.Stderr, "failed to get refer code for %s: %v\n", id.Name, err)
400385
}
386+
if id.Name == "MyStructD.DFunction" {
387+
fmt.Println(1)
388+
}
401389
infos.methodCalls = InsertDependency(infos.methodCalls, dep)
402390
}
403-
return false
391+
392+
// 此处应该是 true,用于处理 chained method call,让 visit 可以继续处理
393+
return true
404394
}
405395

406396
return cont

0 commit comments

Comments
 (0)