Skip to content

Commit 601fc8a

Browse files
authored
feat:(go) support collect interface method's deps (#92)
1 parent dd871c8 commit 601fc8a

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

lang/golang/parser/ctx.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,11 @@ func (ctx *fileContext) getTypeinfo(typ types.Type) (ti typeInfo) {
491491
ti.IsStdOrBuiltin = true
492492
}
493493
// collect sub Named type here
494-
for i := 1; i < len(tobjs); i++ {
494+
i := 0
495+
if isNamed {
496+
i = 1
497+
}
498+
for ; i < len(tobjs); i++ {
495499
tobj := tobjs[i]
496500
if isGoBuiltins(tobj.Name()) {
497501
continue

lang/golang/parser/file.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,11 @@ func (p *GoParser) parseInterface(ctx *fileContext, name *ast.Ident, decl *ast.I
609609
fn.IsMethod = true
610610
fn.IsInterfaceMethod = true
611611
fn.Signature = string(ctx.GetRawContent(fieldDecl))
612+
// collect func signature deps
613+
ty := ctx.GetTypeInfo(fieldDecl.Type)
614+
for _, dep := range ty.Deps {
615+
fn.Types = InsertDependency(fn.Types, NewDependency(dep, ctx.FileLine(fieldDecl)))
616+
}
612617
}
613618
p.collectTypes(ctx, fieldDecl.Type, st, inlined)
614619
}

testdata/go/0_golang/pkg/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,7 @@ var CaseVarFunc CaseStruct = func() CaseStruct {
161161
FieldExternalType: entity.MyStruct{},
162162
}
163163
}()
164+
165+
type CaseInterface interface {
166+
CaseMethodDeps(a int, b entity.MyStruct) Integer
167+
}

0 commit comments

Comments
 (0)