@@ -11,7 +11,6 @@ package xrefs
1111import (
1212 "go/ast"
1313 "go/types"
14- "slices"
1514 "sort"
1615
1716 "golang.org/x/tools/go/types/objectpath"
@@ -118,6 +117,9 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info, asmFiles
118117 // For each asm file, record references to identifiers.
119118 for fileIndex , af := range asmFiles {
120119 for _ , id := range af .Idents {
120+ if id .Kind != asm .Data && id .Kind != asm .Text {
121+ continue
122+ }
121123 _ , name , ok := morestrings .CutLast (id .Name , "." )
122124 if ! ok {
123125 continue
@@ -131,6 +133,7 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info, asmFiles
131133 objects := getObjects (pkg )
132134 gobObj , ok := objects [obj ]
133135 if ! ok {
136+ // obj is a package-level symbol, so its objectpath is just its name.
134137 gobObj = & gobObject {Path : objectpath .Path (obj .Name ())}
135138 objects [obj ] = gobObj
136139 }
@@ -171,14 +174,25 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info, asmFiles
171174// to any object in the target set. Each object is denoted by a pair
172175// of (package path, object path).
173176func 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+ )
175182 packageCodec .Decode (data , & packages )
176183 for _ , gp := range packages {
177184 if objectSet , ok := targets [gp .PkgPath ]; ok {
178185 for _ , gobObj := range gp .Objects {
179186 if _ , ok := objectSet [gobObj .Path ]; ok {
180187 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+ }
182196 locs = append (locs , protocol.Location {
183197 URI : uri ,
184198 Range : ref .Range ,
0 commit comments