@@ -219,6 +219,7 @@ func (p *GoParser) parseSelector(ctx *fileContext, expr *ast.SelectorExpr, infos
219219 return false
220220 }
221221 id := NewIdentity (mod , path , expr .Sel .Name )
222+ dep := NewDependency (id , ctx .FileLine (expr .Sel ))
222223
223224 // NOTICE: refer external codes for convinience
224225 if err := p .referCodes (ctx , & id , p .opts .ReferCodeDepth ); err != nil {
@@ -233,16 +234,16 @@ func (p *GoParser) parseSelector(ctx *fileContext, expr *ast.SelectorExpr, infos
233234 // // fmt.Fprintf(os.Stderr, "failed to get type id for %s\n", expr.Name)
234235 // return false
235236 // }
236- * infos .tys = Dedup (* infos .tys , id )
237+ * infos .tys = Dedup (* infos .tys , dep )
237238 // global var
238239 } else if _ , ok := v .(* types.Const ); ok {
239- * infos .globalVars = Dedup (* infos .globalVars , id )
240+ * infos .globalVars = Dedup (* infos .globalVars , dep )
240241 // external const
241242 } else if _ , ok := v .(* types.Var ); ok {
242- * infos .globalVars = Dedup (* infos .globalVars , id )
243+ * infos .globalVars = Dedup (* infos .globalVars , dep )
243244 // external function
244245 } else if _ , ok := v .(* types.Func ); ok {
245- * infos .functionCalls = Dedup (* infos .functionCalls , id )
246+ * infos .functionCalls = Dedup (* infos .functionCalls , dep )
246247 }
247248 return false
248249 }
@@ -281,19 +282,20 @@ func (p *GoParser) parseSelector(ctx *fileContext, expr *ast.SelectorExpr, infos
281282 rname = rev .Name ()
282283 }
283284 id := NewIdentity (mod , pkg , rname + "." + expr .Sel .Name )
285+ dep := NewDependency (id , ctx .FileLine (expr .Sel ))
284286 if err := p .referCodes (ctx , & id , p .opts .ReferCodeDepth ); err != nil {
285287 fmt .Fprintf (os .Stderr , "failed to get refer code for %s: %v\n " , id .Name , err )
286288 }
287- * infos .methodCalls = Dedup (* infos .methodCalls , id )
289+ * infos .methodCalls = Dedup (* infos .methodCalls , dep )
288290 return false
289291 }
290292
291293 return cont
292294}
293295
294296type collectInfos struct {
295- functionCalls , methodCalls * []Identity
296- tys , globalVars * []Identity
297+ functionCalls , methodCalls * []Dependency
298+ tys , globalVars * []Dependency
297299}
298300
299301// parseFunc parses all function declaration in one file
@@ -321,23 +323,20 @@ func (p *GoParser) parseFunc(ctx *fileContext, funcDecl *ast.FuncDecl) (*Functio
321323 }
322324
323325 // collect parameters
324- params := [] Identity {}
326+ var params [] Dependency
325327 if funcDecl .Type .Params != nil {
326328 ctx .collectFields (funcDecl .Type .Params .List , & params )
327329 }
328330 // collect results
329- results := [] Identity {}
331+ var results [] Dependency
330332 if funcDecl .Type .Results != nil {
331333 ctx .collectFields (funcDecl .Type .Results .List , & results )
332334 }
333- // collect types
334- tys := []Identity {}
335- // collect global vars
336- globalVars := []Identity {}
335+
337336 // collect content
338337 content := string (ctx .GetRawContent (funcDecl ))
339338
340- var functionCalls , methodCalls = [] Identity {}, [] Identity {}
339+ var functionCalls , globalVars , tys , methodCalls [] Dependency
341340
342341 if funcDecl .Body == nil {
343342 goto set_func
@@ -370,31 +369,32 @@ func (p *GoParser) parseFunc(ctx *fileContext, funcDecl *ast.FuncDecl) (*Functio
370369 // }
371370 if use , ok := ctx .pkgTypeInfo .Uses [expr ]; ok {
372371 id := NewIdentity (ctx .module .Name , ctx .pkgPath , callName )
372+ dep := NewDependency (id , ctx .FileLine (expr ))
373373 // type name
374374 if _ , isNamed := use .(* types.TypeName ); isNamed {
375375 // id, ok := ctx.getTypeId(tn.Type())
376376 // if !ok {
377377 // // fmt.Fprintf(os.Stderr, "failed to get type id for %s\n", expr.Name)
378378 // return false
379379 // }
380- tys = Dedup (tys , id )
380+ tys = Dedup (tys , dep )
381381 // global var
382382 } else if v , ok := use .(* types.Var ); ok {
383383 // NOTICE: the Parent of global scope is nil?
384384 if isPkgScope (v .Parent ()) {
385- globalVars = Dedup (globalVars , id )
385+ globalVars = Dedup (globalVars , dep )
386386 }
387387 // global const
388388 } else if c , ok := use .(* types.Const ); ok {
389389 if isPkgScope (c .Parent ()) {
390- globalVars = Dedup (globalVars , id )
390+ globalVars = Dedup (globalVars , dep )
391391 }
392392 return false
393393 // function
394394 } else if f , ok := use .(* types.Func ); ok {
395395 // exclude method
396396 if f .Type ().(* types.Signature ).Recv () == nil {
397- functionCalls = Dedup (functionCalls , id )
397+ functionCalls = Dedup (functionCalls , dep )
398398 }
399399 }
400400 }
@@ -472,7 +472,8 @@ func (p *GoParser) parseStruct(ctx *fileContext, struName string, name *ast.Iden
472472 if stru , ok := fieldDecl .Type .(* ast.StructType ); ok {
473473 // anonymous struct. parse and collect it
474474 as , _ := p .parseStruct (ctx , "_" + fieldname , nil , stru )
475- st .SubStruct = append (st .SubStruct , as .Identity )
475+ dep := NewDependency (as .Identity , ctx .FileLine (fieldDecl .Type ))
476+ st .SubStruct = append (st .SubStruct , dep )
476477 } else {
477478 p .collectTypes (ctx , fieldDecl .Type , st , inlined )
478479 }
0 commit comments