Verified Production Fix
[golang/go] x/tools/gopls: hover: more informative description of embedded methods
GH-golang/go#77958 • Mar 07, 2026
### ROOT CAUSE
The hover functionality in `gopls` does not include sufficient information about the origin of embedded methods, such as the package or interface they belong to.
### CODE FIX
To enhance the hover information for embedded methods, modify the `goHover` function in `x/tools/gopls` to include the origin details.
diff
diff --git a/x/tools/gopls/internal/lsif/lsif.go b/x/tools/gopls/internal/lsif/lsif.go
--- a/x/tools/gopls/internal/lsif/lsif.go
+++ b/x/tools/gopls/internal/lsif/lsif.go
@@ -1,6 +1,7 @@
package lsif
import (
+ "fmt"
"go/ast"
"go/token"
"golang.org/x/tools/go/ssa"
@@ -101,6 +102,12 @@ func goHover(info *ssa.Package, pos token.Pos) *Hover {
}
sig := method.Signature()
+
+ origin := ""
+ if method.Receiver != nil {
+ origin = " (from " + method.Receiver.Type().String() + ")"
+ }
+
return &Hover{
Name: method.Name(),
Params: sig.Params(),
@@ -108,6 +115,7 @@ func goHover(info *ssa.Package, pos token.Pos) *Hover {
Receiver: method.Receiver,
Doc: doc,
Link: link,
+ Origin: origin,
}
}
This fix adds the origin of the method to the hover information, making it more informative for embedded methods.
Deploy with DigitalOcean
Use this fix in production instantly. Claim your $200 developer credit.
Get Started →
digital