@@ -17,13 +17,15 @@ import (
17
17
"golang.org/x/tools/gopls/internal/cache/metadata"
18
18
"golang.org/x/tools/gopls/internal/cache/parsego"
19
19
"golang.org/x/tools/gopls/internal/protocol"
20
+ "golang.org/x/tools/gopls/internal/util/asm"
20
21
"golang.org/x/tools/gopls/internal/util/bug"
21
22
"golang.org/x/tools/gopls/internal/util/frob"
23
+ "golang.org/x/tools/gopls/internal/util/morestrings"
22
24
)
23
25
24
26
// Index constructs a serializable index of outbound cross-references
25
27
// 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 {
27
29
// pkgObjects maps each referenced package Q to a mapping:
28
30
// from each referenced symbol in Q to the ordered list
29
31
// of references to that symbol from this package.
@@ -70,7 +72,7 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info) []byte {
70
72
// (e.g. local const/var/type).
71
73
continue
72
74
}
73
- gobObj = & gobObject {Path : path }
75
+ gobObj = & gobObject {Path : path , isAsm : false }
74
76
objects [obj ] = gobObj
75
77
}
76
78
@@ -112,6 +114,37 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info) []byte {
112
114
}
113
115
}
114
116
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
+
115
148
// Flatten the maps into slices, and sort for determinism.
116
149
var packages []* gobPackage
117
150
for p := range pkgObjects {
@@ -148,6 +181,9 @@ func Lookup(mp *metadata.Package, data []byte, targets map[metadata.PackagePath]
148
181
if _ , ok := objectSet [gobObj .Path ]; ok {
149
182
for _ , ref := range gobObj .Refs {
150
183
uri := mp .CompiledGoFiles [ref .FileIndex ]
184
+ if gobObj .isAsm {
185
+ uri = mp .AsmFiles [ref .FileIndex ]
186
+ }
151
187
locs = append (locs , protocol.Location {
152
188
URI : uri ,
153
189
Range : ref .Range ,
@@ -184,8 +220,9 @@ type gobPackage struct {
184
220
185
221
// A gobObject records all references to a particular symbol.
186
222
type 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
189
226
}
190
227
191
228
type gobRef struct {
0 commit comments