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

cmd/doc: -src not showing comments in function #28195

Closed
kybin opened this issue Oct 14, 2018 · 6 comments
Closed

cmd/doc: -src not showing comments in function #28195

kybin opened this issue Oct 14, 2018 · 6 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@kybin
Copy link
Contributor

kybin commented Oct 14, 2018

recently added -src flag does not showing comments in function.

so, when I run

go doc -src bytes.Buffer.ReadBytes

It prints

// ...
func (b *Buffer) ReadBytes(delim byte) (line []byte, err error) {
	slice, err := b.readSlice(delim)

	line = append(line, slice...)
	return line, err
}

But the actual function is

// ...
func (b *Buffer) ReadBytes(delim byte) (line []byte, err error) {
	slice, err := b.readSlice(delim)
	// return a copy of slice. The buffer's backing array may
	// be overwritten by later calls.
	line = append(line, slice...)
	return line, err
}
@agnivade
Copy link
Contributor

/cc @robpike

@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 14, 2018
@agnivade agnivade added this to the Go1.12 milestone Oct 14, 2018
@robpike
Copy link
Contributor

robpike commented Oct 14, 2018

The old godoc command does the same, so this is likely a property of the go/doc package.
/cc @griesemer

@griesemer
Copy link
Contributor

go/doc doesn't do anything special here. The problem is that that comments (except for doc strings) are maintained separately in the AST, and thus printing a node (such as a function node) won't know anything about internal (and non-doc) comments if they are not provided explicitly, e.g. via a go/printer.CommentedNode.

@agnivade
Copy link
Contributor

So should this be fixed ? Because godoc also had the same behavior.

@griesemer
Copy link
Contributor

I think it would be nice if it were fixed. I think with CommentedNode this shouldn't be too hard.

@agnivade agnivade added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 16, 2018
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 16, 2018
@robpike robpike self-assigned this Oct 17, 2018
@gopherbot
Copy link

Change https://golang.org/cl/143037 mentions this issue: cmd/doc: make comments inside functions appear with -src

@golang golang locked and limited conversation to collaborators Oct 18, 2019
@rsc rsc unassigned robpike Jun 23, 2022
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

5 participants