@@ -11,7 +11,6 @@ package xrefs
11
11
import (
12
12
"go/ast"
13
13
"go/types"
14
- "slices"
15
14
"sort"
16
15
17
16
"golang.org/x/tools/go/types/objectpath"
@@ -118,6 +117,9 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info, asmFiles
118
117
// For each asm file, record references to identifiers.
119
118
for fileIndex , af := range asmFiles {
120
119
for _ , id := range af .Idents {
120
+ if id .Kind != asm .Data && id .Kind != asm .Text {
121
+ continue
122
+ }
121
123
_ , name , ok := morestrings .CutLast (id .Name , "." )
122
124
if ! ok {
123
125
continue
@@ -131,6 +133,7 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info, asmFiles
131
133
objects := getObjects (pkg )
132
134
gobObj , ok := objects [obj ]
133
135
if ! ok {
136
+ // obj is a package-level symbol, so its objectpath is just its name.
134
137
gobObj = & gobObject {Path : objectpath .Path (obj .Name ())}
135
138
objects [obj ] = gobObj
136
139
}
@@ -171,14 +174,25 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info, asmFiles
171
174
// to any object in the target set. Each object is denoted by a pair
172
175
// of (package path, object path).
173
176
func Lookup (mp * metadata.Package , data []byte , targets map [metadata.PackagePath ]map [objectpath.Path ]struct {}) (locs []protocol.Location ) {
174
- var packages []* gobPackage
177
+ var (
178
+ packages []* gobPackage
179
+ goFilesLen = len (mp .CompiledGoFiles )
180
+ goAsmFilesLen = len (mp .AsmFiles )
181
+ )
175
182
packageCodec .Decode (data , & packages )
176
183
for _ , gp := range packages {
177
184
if objectSet , ok := targets [gp .PkgPath ]; ok {
178
185
for _ , gobObj := range gp .Objects {
179
186
if _ , ok := objectSet [gobObj .Path ]; ok {
180
187
for _ , ref := range gobObj .Refs {
181
- uri := slices .Concat (mp .CompiledGoFiles , mp .AsmFiles )[ref .FileIndex ]
188
+ var uri protocol.DocumentURI
189
+ if ref .FileIndex < goFilesLen {
190
+ uri = mp .CompiledGoFiles [ref .FileIndex ]
191
+ } else if ref .FileIndex < goFilesLen + goAsmFilesLen {
192
+ uri = mp .AsmFiles [ref .FileIndex ]
193
+ } else {
194
+ continue // out of bounds
195
+ }
182
196
locs = append (locs , protocol.Location {
183
197
URI : uri ,
184
198
Range : ref .Range ,
0 commit comments