-
Notifications
You must be signed in to change notification settings - Fork 18k
x/pkgsite: show exported fields promoted from unexported anonymous fields #6600
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
Comments
I have what I think is the same problem. Public receiver methods (on a hidden type) do not have their document strings displayed. Consider this code //Package showme demonstrates that public receivers on a hidden type are not documented
package showme
type hiddenType struct {
i int
s string
}
type PublicType struct {
i int
s string
}
// PublicFA should be documented
func (hiddenType) PublicFA(){
//do something boring
}
// PublicFB will be documented
func (PublicType) PublicFB(){
//do something boring
} Method |
@alecthegeek - Your issue is different. This issue is about displaying exported fields from embedded fields in a type which itself is exported. |
Interesting thing to note is if |
Change https://golang.org/cl/131176 mentions this issue: |
Before we write any more code for this, we need to decide if and what we should do about this. |
Copying over @dsnet's thoughts from the CL for completeness - I don't think we should do this. I have following concerns:
|
I'm some surprised that the following cmd doesn't work:
|
@go101, what you're describing is orthogonal to this issue. The
|
There are more cases of exported methods/fields are not listed by doc cmd and godoc webpages.
|
+1 for allowing documentation of embedded struct's exported fields. In response to @dsnet and @agnivade said:
I think the proposed doc solution in the report was good and would differentiate things enough so users were not confused |
I am surprised that throughout this thread it seems people are unsure whether to do anything about it. Labels like priority-later and comments like For me it is. I want to go look at the package site and see what functions I can call on my objects but it does not show them to me. I am glad that there are people working on this and I am not entitled to tell you what to spend your time on, but I would like to bump this up in priority in people's minds since it is a major issue for me at the moment. I rely on the package site quite a lot since my IDE's auto-completion broke (when modules were introduced) and for the most part it works. But this is really a pain point for me and I would be very happy to see this issue fixed. For reference, I was the one to open issue #48722 |
This issue creates situations where one reads code that uses exported fields that are not present in documentation. Example, the usage section of the documentation for https://github.com/andreykaipov/goobs shows the following example code: On line 16 you see this: version, err := client.General.GetVersion() but the documentation for Despite While I accept there are multiple possible solutions here, I have difficulty understanding how this can be seen as anything but obviously incorrect. |
embedding a private struct creates the confusing effect of exporting the public fields of the sub-struct without having them show in documentation. This has some discussion at the language / godoc level: golang/go#6600 This commit exports the subclients field of goobs.Client so the available fields show in documentation.
You can try Golds, which lists all promoted fields and methods. |
* docs: export Subclients embedded struct embedding a private struct creates the confusing effect of exporting the public fields of the sub-struct without having them show in documentation. This has some discussion at the language / godoc level: golang/go#6600 This commit exports the subclients field of goobs.Client so the available fields show in documentation. * client: rename subclients to categories
I'm in favor. From a principled POV the primary goal of documentation should be to display everything that a user can access and do, i.e. how they can interact with the module. Anything accessible according to the visibility rules of the language should appear in the docs. Now, from a direct use case, embeddings are particularly important because they affect which interfaces are implemented. Consider this use-case: type netConn net.Conn
type Conn struct {
netConn // We don't allow direct access to the inner net.Conn to prevent accidental misuse
br *bufio.Reader
}
func (c *Conn) Read(p []byte) (int, error) {
// Override to read from the bufio.Reader, common for wire protocols
}
// Forward the rest (7 methods) to the inner conn Crucially, users need to know that
|
This caught me by surprise, and can create compatibility issues: when preparing to publish a package, and especially when tagging v1.0.0, I always make sure I am happy with the exposed API. However, due to this, I exposed fields I did not meant to expose without noticing, and removing them would technically be a backwards compatibility issue. At least, we should change the |
The text was updated successfully, but these errors were encountered: