Skip to content

Commit 3ba13a6

Browse files
committed
gopls: Refactor xrefs.go Lookup function.
Modify the logic for distinguishing between asm files and Go files. Add test examples. Updates golang/go#71754
1 parent f47a913 commit 3ba13a6

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

gopls/internal/cache/xrefs/xrefs.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info, asmFiles
175175
// of (package path, object path).
176176
func Lookup(mp *metadata.Package, data []byte, targets map[metadata.PackagePath]map[objectpath.Path]struct{}) (locs []protocol.Location) {
177177
var (
178-
packages []*gobPackage
179-
goFilesLen = len(mp.CompiledGoFiles)
180-
goAsmFilesLen = len(mp.AsmFiles)
178+
packages []*gobPackage
181179
)
182180
packageCodec.Decode(data, &packages)
183181
for _, gp := range packages {
@@ -186,12 +184,10 @@ func Lookup(mp *metadata.Package, data []byte, targets map[metadata.PackagePath]
186184
if _, ok := objectSet[gobObj.Path]; ok {
187185
for _, ref := range gobObj.Refs {
188186
var uri protocol.DocumentURI
189-
if ref.FileIndex < goFilesLen {
187+
if asmIndex := ref.FileIndex - len(mp.CompiledGoFiles); asmIndex < 0 {
190188
uri = mp.CompiledGoFiles[ref.FileIndex]
191-
} else if ref.FileIndex < goFilesLen+goAsmFilesLen {
192-
uri = mp.AsmFiles[ref.FileIndex]
193189
} else {
194-
continue // out of bounds
190+
uri = mp.AsmFiles[asmIndex]
195191
}
196192
locs = append(locs, protocol.Location{
197193
URI: uri,
@@ -234,6 +230,6 @@ type gobObject struct {
234230
}
235231

236232
type gobRef struct {
237-
FileIndex int // index of enclosing file within P's CompiledGoFiles
233+
FileIndex int // index of enclosing file within P's CompiledGoFiles + AsmFiles
238234
Range protocol.Range // source range of reference
239235
}

gopls/internal/test/marker/testdata/references/asm.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@ TEXT ·sub(SB), NOSPLIT, $0-24 //@ loc(defSub, "·sub"), refs("sub", defSub, use
3434
MOVQ a+0(FP), AX
3535
SUBQ b+8(FP), AX
3636
RET
37+
38+
TEXT ·AddAndSub(SB), NOSPLIT, $0-24
39+
CALL ·Add(SB)
40+
CALL ·sub(SB)
41+
RET

0 commit comments

Comments
 (0)