Skip to content

Commit 10c941e

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 10c941e

2 files changed

Lines changed: 11 additions & 16 deletions

File tree

lang/golang/parser/file.go

Lines changed: 3 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
@@ -400,7 +385,9 @@ func (p *GoParser) parseSelector(ctx *fileContext, expr *ast.SelectorExpr, infos
400385
}
401386
infos.methodCalls = InsertDependency(infos.methodCalls, dep)
402387
}
403-
return false
388+
389+
// 此处应该是 true,用于处理 chained method call,让 visit 可以继续处理
390+
return true
404391
}
405392

406393
return cont

testdata/go/0_golang/pkg/entity/entity.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,11 @@ const G1 = 1
6161
type Integer int
6262

6363
var V1 = Integer(1)
64+
65+
func (a *MyStruct) Return0() *MyStruct {
66+
return a
67+
}
68+
69+
func (a *MyStruct) Return4() string {
70+
return a.Return0().DFunction()
71+
}

0 commit comments

Comments
 (0)