Skip to content

Commit 0beb6d8

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 9e2e104 commit 0beb6d8

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
@@ -33,7 +33,9 @@ import (
3333
"golang.org/x/tools/gopls/internal/cache/parsego"
3434
"golang.org/x/tools/gopls/internal/file"
3535
"golang.org/x/tools/gopls/internal/protocol"
36+
"golang.org/x/tools/gopls/internal/util/asm"
3637
"golang.org/x/tools/gopls/internal/util/cursorutil"
38+
"golang.org/x/tools/gopls/internal/util/morestrings"
3739
"golang.org/x/tools/gopls/internal/util/safetoken"
3840
"golang.org/x/tools/internal/astutil"
3941
"golang.org/x/tools/internal/event"
@@ -608,6 +610,29 @@ func localReferences(pkg *cache.Package, targets map[types.Object]bool, correspo
608610
}
609611
}
610612
}
613+
614+
for _, pgf := range pkg.AsmFiles() {
615+
for _, id := range pgf.Idents {
616+
_, name, ok := morestrings.CutLast(id.Name, ".")
617+
if !ok {
618+
continue
619+
}
620+
if id.Kind != asm.Text {
621+
continue
622+
}
623+
obj := pkg.Types().Scope().Lookup(name)
624+
if obj == nil {
625+
continue
626+
}
627+
if rng, err := pgf.NodeRange(id); err == nil && matches(obj) {
628+
asmLocation := protocol.Location{
629+
URI: pgf.URI,
630+
Range: rng,
631+
}
632+
report(asmLocation, false)
633+
}
634+
}
635+
}
611636
return nil
612637
}
613638

0 commit comments

Comments
 (0)