@@ -17,13 +17,15 @@ import (
1717 "golang.org/x/tools/gopls/internal/cache/metadata"
1818 "golang.org/x/tools/gopls/internal/cache/parsego"
1919 "golang.org/x/tools/gopls/internal/protocol"
20+ "golang.org/x/tools/gopls/internal/util/asm"
2021 "golang.org/x/tools/gopls/internal/util/bug"
2122 "golang.org/x/tools/gopls/internal/util/frob"
23+ "golang.org/x/tools/gopls/internal/util/morestrings"
2224)
2325
2426// Index constructs a serializable index of outbound cross-references
2527// for the specified type-checked package.
26- func Index (files []* parsego.File , pkg * types.Package , info * types.Info ) []byte {
28+ func Index (files []* parsego.File , pkg * types.Package , info * types.Info , asmFiles [] * asm. File ) []byte {
2729 // pkgObjects maps each referenced package Q to a mapping:
2830 // from each referenced symbol in Q to the ordered list
2931 // of references to that symbol from this package.
@@ -70,7 +72,7 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info) []byte {
7072 // (e.g. local const/var/type).
7173 continue
7274 }
73- gobObj = & gobObject {Path : path }
75+ gobObj = & gobObject {Path : path , isAsm : false }
7476 objects [obj ] = gobObj
7577 }
7678
@@ -112,6 +114,37 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info) []byte {
112114 }
113115 }
114116
117+ for fileIndex , af := range asmFiles {
118+ for _ , id := range af .Idents {
119+ _ , name , ok := morestrings .CutLast (id .Name , "." )
120+ if id .Kind != asm .Text {
121+ continue
122+ }
123+ obj := pkg .Scope ().Lookup (name )
124+ if obj == nil {
125+ continue
126+ }
127+ objects := getObjects (pkg )
128+ gobObj , ok := objects [obj ]
129+ if ! ok {
130+ path , err := objectpathFor (obj )
131+ if err != nil {
132+ // Capitalized but not exported
133+ // (e.g. local const/var/type).
134+ continue
135+ }
136+ gobObj = & gobObject {Path : path , isAsm : true }
137+ objects [obj ] = gobObj
138+ }
139+ if rng , err := af .NodeRange (id ); err == nil {
140+ gobObj .Refs = append (gobObj .Refs , gobRef {
141+ FileIndex : fileIndex ,
142+ Range : rng ,
143+ })
144+ }
145+ }
146+ }
147+
115148 // Flatten the maps into slices, and sort for determinism.
116149 var packages []* gobPackage
117150 for p := range pkgObjects {
@@ -148,6 +181,9 @@ func Lookup(mp *metadata.Package, data []byte, targets map[metadata.PackagePath]
148181 if _ , ok := objectSet [gobObj .Path ]; ok {
149182 for _ , ref := range gobObj .Refs {
150183 uri := mp .CompiledGoFiles [ref .FileIndex ]
184+ if gobObj .isAsm {
185+ uri = mp .AsmFiles [ref .FileIndex ]
186+ }
151187 locs = append (locs , protocol.Location {
152188 URI : uri ,
153189 Range : ref .Range ,
@@ -184,8 +220,9 @@ type gobPackage struct {
184220
185221// A gobObject records all references to a particular symbol.
186222type gobObject struct {
187- Path objectpath.Path // symbol name within package; "" => import of package itself
188- Refs []gobRef // locations of references within P, in lexical order
223+ Path objectpath.Path // symbol name within package; "" => import of package itself
224+ Refs []gobRef // locations of references within P, in lexical order
225+ isAsm bool // true if this is an assembly object
189226}
190227
191228type gobRef struct {
0 commit comments