@@ -527,7 +527,7 @@ func (p *GoParser) searchName(name string) (ids []Identity, err error) {
527527 if err != nil {
528528 return err
529529 }
530- tids , e := p .searchOnFile (file , fset , fcontent , m .Name , pkg , impts , name )
530+ tids , e := p .searchOnFile (file , fset , fcontent , m .Name , pkg , impts , name , "" )
531531 if e != nil {
532532 err = e
533533 return nil
@@ -553,7 +553,13 @@ func (p *GoParser) exportFileLine(fset *token.FileSet, decl ast.Node) (ret FileL
553553 return
554554}
555555
556- func (p * GoParser ) searchOnFile (file * ast.File , fset * token.FileSet , fcontent []byte , mod string , pkg string , impt * importInfo , name string ) (ids []Identity , err error ) {
556+ func (p * GoParser ) searchOnFile (file * ast.File , fset * token.FileSet , fcontent []byte , mod string , pkg string , impt * importInfo , name string , pkgDir string ) (ids []Identity , err error ) {
557+ isExternal := pkgDir != ""
558+ homeDir := p .homePageDir
559+ if isExternal {
560+ homeDir = pkgDir
561+ }
562+
557563 for _ , decl := range file .Decls {
558564 // println(string(GetRawContent(fset, fcontent, decl)))
559565 switch decl := decl .(type ) {
@@ -562,7 +568,7 @@ func (p *GoParser) searchOnFile(file *ast.File, fset *token.FileSet, fcontent []
562568 var receiver * Receiver
563569 if decl .Recv != nil && strings .Contains (name , "." ) {
564570 var m = map [string ]Identity {}
565- tname , isPointer := p .mockTypes (decl .Recv .List [0 ].Type , m , fcontent , fset , getRelativeOrBasePath (p . homePageDir , fset , decl .Pos ()), mod , pkg , impt )
571+ tname , isPointer := p .mockTypes (decl .Recv .List [0 ].Type , m , fcontent , fset , getRelativeOrBasePath (homeDir , fset , decl .Pos ()), mod , pkg , impt )
566572 if tname == "" {
567573 fmt .Fprintf (os .Stderr , "Error: cannot get type from receiver %v" , decl .Recv .List [0 ].Type )
568574 continue
@@ -584,7 +590,12 @@ func (p *GoParser) searchOnFile(file *ast.File, fset *token.FileSet, fcontent []
584590 ids = append (ids , newIdentity (mod , pkg , name ))
585591 fn := p .newFunc (mod , pkg , name )
586592 fn .Content = string (GetRawContent (fset , fcontent , decl , p .opts .CollectComment ))
587- fn .FileLine = p .exportFileLine (fset , decl )
593+ if isExternal {
594+ fn .FileLine .File = fset .Position (decl .Pos ()).Filename
595+ } else {
596+ fn .FileLine .File = getRelativeOrBasePath (homeDir , fset , decl .Pos ())
597+ }
598+ fn .FileLine .Line = fset .Position (decl .Pos ()).Line
588599 fn .IsMethod = decl .Recv != nil
589600 fn .Receiver = receiver
590601 // if decl.Type.Params != nil {
@@ -612,7 +623,12 @@ func (p *GoParser) searchOnFile(file *ast.File, fset *token.FileSet, fcontent []
612623 if spec .Name .Name == name {
613624 st = p .newType (mod , pkg , spec .Name .Name )
614625 st .Content = string (GetRawContent (fset , fcontent , spec , p .opts .CollectComment ))
615- st .FileLine = p .exportFileLine (fset , spec )
626+ if isExternal {
627+ st .FileLine .File = fset .Position (spec .Pos ()).Filename
628+ } else {
629+ st .FileLine .File = getRelativeOrBasePath (homeDir , fset , spec .Pos ())
630+ }
631+ st .FileLine .Line = fset .Position (spec .Pos ()).Line
616632 st .TypeKind = getTypeKind (spec .Type )
617633 ids = append (ids , newIdentity (mod , pkg , name ))
618634 }
@@ -628,7 +644,12 @@ func (p *GoParser) searchOnFile(file *ast.File, fset *token.FileSet, fcontent []
628644 ids = append (ids , newIdentity (mod , pkg , name ))
629645 fn := p .newFunc (mod , pkg , name )
630646 fn .Content = string (GetRawContent (fset , fcontent , m , p .opts .CollectComment ))
631- fn .FileLine = p .exportFileLine (fset , m )
647+ if isExternal {
648+ fn .FileLine .File = fset .Position (m .Pos ()).Filename
649+ } else {
650+ fn .FileLine .File = getRelativeOrBasePath (homeDir , fset , m .Pos ())
651+ }
652+ fn .FileLine .Line = fset .Position (m .Pos ()).Line
632653 fn .IsMethod = true
633654 fn .IsInterfaceMethod = true
634655 fn .Receiver = & Receiver {
@@ -659,7 +680,12 @@ func (p *GoParser) searchOnFile(file *ast.File, fset *token.FileSet, fcontent []
659680 ids = append (ids , newIdentity (mod , pkg , name ))
660681 v := p .newVar (mod , pkg , name , decl .Tok == token .CONST )
661682 v .Content = string (GetRawContent (fset , fcontent , spec , p .opts .CollectComment ))
662- v .FileLine = p .exportFileLine (fset , spec )
683+ if isExternal {
684+ v .FileLine .File = fset .Position (spec .Pos ()).Filename
685+ } else {
686+ v .FileLine .File = getRelativeOrBasePath (homeDir , fset , spec .Pos ())
687+ }
688+ v .FileLine .Line = fset .Position (spec .Pos ()).Line
663689 if spec .Type != nil {
664690 var m = map [string ]Identity {}
665691 // NOTICE: collect all types
0 commit comments