Skip to content

Commit a4113fc

Browse files
committed
gopls: Implement reference jumping between Go functions and assembly functions.
This commit modifies the addition of reference relationships in assembly files within the references file. Updates golang/go#71754
1 parent f8deb4d commit a4113fc

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

gopls/internal/cache/package.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,7 @@ func (p *Package) ParseErrors() []scanner.ErrorList {
202202
func (p *Package) TypeErrors() []types.Error {
203203
return p.pkg.typeErrors
204204
}
205+
206+
func (p *Package) AsmFiles() []*asm.File {
207+
return p.pkg.asmFiles
208+
}

gopls/internal/cache/xrefs/xrefs.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ func Index(files []*parsego.File, pkg *types.Package, info *types.Info, asmFiles
117117
for fileIndex, af := range asmFiles {
118118
for _, id := range af.Idents {
119119
_, name, ok := morestrings.CutLast(id.Name, ".")
120+
if !ok {
121+
continue
122+
}
120123
if id.Kind != asm.Text {
121124
continue
122125
}

gopls/internal/golang/references.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ import (
3232
"golang.org/x/tools/gopls/internal/cache/parsego"
3333
"golang.org/x/tools/gopls/internal/file"
3434
"golang.org/x/tools/gopls/internal/protocol"
35+
"golang.org/x/tools/gopls/internal/util/asm"
36+
"golang.org/x/tools/gopls/internal/util/morestrings"
3537
"golang.org/x/tools/gopls/internal/util/safetoken"
3638
"golang.org/x/tools/internal/event"
3739
)
@@ -610,6 +612,29 @@ func localReferences(pkg *cache.Package, targets map[types.Object]bool, correspo
610612
}
611613
}
612614
}
615+
616+
for _, pgf := range pkg.AsmFiles() {
617+
for _, id := range pgf.Idents {
618+
_, name, ok := morestrings.CutLast(id.Name, ".")
619+
if !ok {
620+
continue
621+
}
622+
if id.Kind != asm.Text {
623+
continue
624+
}
625+
obj := pkg.Types().Scope().Lookup(name)
626+
if obj == nil {
627+
continue
628+
}
629+
if rng, err := pgf.NodeRange(id); err == nil && matches(obj) {
630+
asmLocation := protocol.Location{
631+
URI: pgf.URI,
632+
Range: rng,
633+
}
634+
report(asmLocation, false)
635+
}
636+
}
637+
}
613638
return nil
614639
}
615640

0 commit comments

Comments
 (0)