Skip to content

Commit 9fe9077

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 4f2e87f commit 9fe9077

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
@@ -214,3 +214,7 @@ func (p *Package) ParseErrors() []scanner.ErrorList {
214214
func (p *Package) TypeErrors() []types.Error {
215215
return p.pkg.typeErrors
216216
}
217+
218+
func (p *Package) AsmFiles() []*asm.File {
219+
return p.pkg.asmFiles
220+
}

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
)
@@ -609,6 +611,29 @@ func localReferences(pkg *cache.Package, targets map[types.Object]bool, correspo
609611
}
610612
}
611613
}
614+
615+
for _, pgf := range pkg.AsmFiles() {
616+
for _, id := range pgf.Idents {
617+
_, name, ok := morestrings.CutLast(id.Name, ".")
618+
if !ok {
619+
continue
620+
}
621+
if id.Kind != asm.Text {
622+
continue
623+
}
624+
obj := pkg.Types().Scope().Lookup(name)
625+
if obj == nil {
626+
continue
627+
}
628+
if rng, err := pgf.NodeRange(id); err == nil && matches(obj) {
629+
asmLocation := protocol.Location{
630+
URI: pgf.URI,
631+
Range: rng,
632+
}
633+
report(asmLocation, false)
634+
}
635+
}
636+
}
612637
return nil
613638
}
614639

0 commit comments

Comments
 (0)