LoginSignup
0
0

More than 3 years have passed since last update.

ASTでドキュメントコメント(Docフィールド)を取得する際にハマった

Posted at

"go/parser" でパースしたASTから、Docフィールドを取ろうとしてちょっとはまったのでメモ

GitHub のIssueによると 1
type の前につけたドキュメントコメントは、ast.TypeSpec ではなく、ast.GenDeclDocフィールドにつくよという話。

// doc comment
type Foo struct {
}
// このコメントは GenDecl.Doc につく
type A struct {
}

// このコメントは GenDecl.Doc につく
type (
    // このコメントが TypeSpec.Doc につく
    B struct {
    }
)

動作確認のソース Gist

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0