-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go/doc: Package.Parser should collect up interface methods #62293
Comments
Change https://go.dev/cl/523059 mentions this issue: |
Hey guys I just note that links to public methods in a public interface are not linked correctly via godoc if it refers to the same package. Same for public fields: notable examples link to public method in type interfacehttps://pkg.go.dev/encoding/json@go1.22.4#MarshalerError
// A MarshalerError represents an error from calling a
// [Marshaler.MarshalJSON] or [encoding.TextMarshaler.MarshalText] method.
type MarshalerError struct { The rendering:
Another example: https://pkg.go.dev/io@go1.22.4#WriteString link to public field in type structhttps://pkg.go.dev/archive/tar@go1.22.4#Reader.Read // Calling Read on special types like [TypeLink], [TypeSymlink], [TypeChar],
// [TypeBlock], [TypeDir], and [TypeFifo] returns (0, [io.EOF]) regardless of what
// the [Header.Size] claims.
func (tr *Reader) Read(b []byte) (int, error) {
The rendering:
I can't find an example, but I think it may work from another package, like the previous issue in the public interface link to builtin function defined on the current package:https://pkg.go.dev/builtin@go1.22.4#recover
The rendering:
let me ask: this issue #62293 also refer to such errors? or should I open another ticket? This is kinda annoying BTW |
There is a duplicate #63679 |
Alternatively, to fix links it should be enough to add interface methods into p.syms like: index 4d01ae458b..192554ec2b 100644
--- a/src/go/doc/doc.go
+++ b/src/go/doc/doc.go
@@ -167,6 +167,7 @@ func (p *Package) collectTypes(types []*Type) {
p.collectValues(t.Vars)
p.collectFuncs(t.Funcs)
p.collectFuncs(t.Methods)
+ p.collectInterfaceMethods(t)
}
}
@@ -184,6 +185,21 @@ func (p *Package) collectFuncs(funcs []*Func) {
}
}
+func (p *Package) collectInterfaceMethods(t *Type) {
+ if t.Decl != nil && t.Decl.Tok == token.TYPE {
+ for _, s := range t.Decl.Specs {
+ s := s.(*ast.TypeSpec) // token.TYPE guarantees this
+ if i, ok := s.Type.(*ast.InterfaceType); ok {
+ for _, m := range i.Methods.List {
+ if len(m.Names) > 0 { // skip embedded interfaces
+ p.syms[t.Name+"."+m.Names[0].Name] = true
+ }
+ }
+ }
+ }
+ }
+}
+ |
Related to #54033 |
Currently, the methods of a interface are not linkable because
Package.Parser
does not collect them up.Thus, if you put a declaration like
[Reader.Read]
within theio
package, thepkgsite
is not able to link to theRead
method.It is unclear how to best fix this. Ideally interface methods appear in
Type.Methods
, but historically they have not.Adding them in there could break tools that are not expecting their appearance.
The text was updated successfully, but these errors were encountered: