Skip to content
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: lineWrapper does not add // prefix while wrapping a line comment #20929

Closed
rsc opened this issue Jul 6, 2017 · 6 comments
Closed

go/doc: lineWrapper does not add // prefix while wrapping a line comment #20929

rsc opened this issue Jul 6, 2017 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Jul 6, 2017

$ go doc csv.Reader.ReuseRecord
struct Reader {
    // ReuseRecord controls whether calls to Read may return a slice sharing
    // the backing array of the previous call's returned slice for performance.
    // By default, each call to Read returns newly allocated memory owned by the
    caller.
    ReuseRecord bool
}

Note the "caller" line without a leading //. It should have one.

/cc @robpike

@rsc rsc added this to the Go1.9 milestone Jul 6, 2017
@robpike
Copy link
Contributor

robpike commented Jul 6, 2017

Pretty sure this is a bug in go/doc's ToText function. cmd/doc calls that to format comments.

@bradfitz
Copy link
Contributor

@griesemer?

@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 14, 2017
@bradfitz bradfitz modified the milestones: Go1.9Maybe, Go1.9 Jul 14, 2017
@bradfitz
Copy link
Contributor

Hard to see this as a release blocker, though. Demoting to Maybe.

@bradfitz bradfitz modified the milestones: Go1.9Maybe, Go1.10 Jul 20, 2017
@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017
@gopherbot gopherbot modified the milestones: Go1.11, Unplanned May 23, 2018
@agnivade
Copy link
Contributor

This is due to indentedWidth being 76 in doc.ToText in src/cmd/doc/pkg.go.(*pkg printFieldDoc). So when the last line of comment is being printed, the lineWrapper wraps it in the next line but does not add a // for the next line of comment.

This does not happen in go doc csv.Reader because the printing of the Reader type is done by format.Node which does not have any line wrapping logic.

To fix this, we need to add logic to lineWrapper to check if it is printing a comment and add a // in the next line. Currently, ToText is not aware that whether it is printing a comment or any random text. Although the doc comment does say that // ToText prepares comment text for presentation in textual output.

@griesemer - Are you okay with this ? In general, are there cases where doc.ToText is called for something which is not a comment ? From a cursory grep, it does not appear so.

Also what about block comments ? I have never seen block comments in struct fields, but I guess it is plausible some people can use it. The formatting screws up even further if I use them

gotip run . csv.Reader.ReuseRecord
type Reader struct {
    /* ReuseRecord controls whether calls to Read may return a slice sharing

    the backing array of the previous call's returned slice for performance.
    By default, each call to Read returns newly allocated memory owned by the caller. */    ReuseRecord bool

    // ... other fields elided ...
}

@agnivade agnivade changed the title cmd/doc: comment wrapping can lose // prefix in go doc struct.field go/doc: lineWrapper does not add // prefix while wrapping a line comment Feb 20, 2019
@griesemer griesemer modified the milestones: Unplanned, Go1.13 Feb 20, 2019
@griesemer
Copy link
Contributor

Whatever lineWrapper is doing, it needs to be aware of whether it's in a comment (and what kind of comment), and do the right thing. Looks like this is clearly a bug that should be addressed.

@gopherbot
Copy link

Change https://golang.org/cl/163578 mentions this issue: go/doc: add // while wrapping a line comment in ToText

@golang golang locked and limited conversation to collaborators Mar 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants