chore: allow docgen to ignore a struct

Using a well known comment (docgen: nodoc), we can now tell docgen to
ignore certain structs.

Signed-off-by: Andrew Rynhard <andrew@andrewrynhard.com>
This commit is contained in:
Andrew Rynhard
2020-01-09 07:57:30 -08:00
committed by Spencer Smith
parent 4c5cd2bb5c
commit d123d24b93

View File

@ -97,30 +97,45 @@ func collectStructs(node ast.Node) []*structType {
structs := []*structType{}
collectStructs := func(n ast.Node) bool {
t, ok := n.(*ast.TypeSpec)
g, ok := n.(*ast.GenDecl)
if !ok {
return true
}
if t.Type == nil {
return true
if g.Doc != nil {
for _, comment := range g.Doc.List {
if strings.Contains(comment.Text, "docgen: nodoc") {
return true
}
}
}
x, ok := t.Type.(*ast.StructType)
if !ok {
return true
for _, spec := range g.Specs {
t, ok := spec.(*ast.TypeSpec)
if !ok {
return true
}
if t.Type == nil {
return true
}
x, ok := t.Type.(*ast.StructType)
if !ok {
return true
}
structName := t.Name.Name
s := &structType{
name: structName,
node: x,
pos: x.Pos(),
}
structs = append(structs, s)
}
structName := t.Name.Name
s := &structType{
name: structName,
node: x,
pos: x.Pos(),
}
structs = append(structs, s)
return true
}