Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upgo/ast: Empty field docs and comments for function arguments #35484
Labels
Comments
This comment has been minimized.
This comment has been minimized.
You have to use the package main
import (
"fmt"
"go/parser"
"go/token"
"log"
)
const src = `
package my_package
func MyFunc(
// FuncComment
argument string,
) {}
`
func main() {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "", src, parser.ParseComments)
if err != nil {
log.Fatal(err)
}
for _, c := range f.Comments {
fmt.Printf("%v\n", c.Text())
}
} Look into https://golang.org/pkg/go/ast/#CommentMap for more information. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Hi,
I tried to get comment for argument from it's func declaration, but
ast.Field.Comment
andast.Field.Doc
have nil values. Also, I tried the same for struct fields and comments there are exist.Output
What did you expect to see?
ast.Field.Doc
for func argument should contain comment if it exists in source.What did you see instead?
Empty
ast.Field.Doc
andast.Field.Comment
for existed comments in source.