0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

  1. GitHub Issue go/ast: TypeSpec.Doc is nil? Have to grab documentation at GenDecl #27477

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?