Skip to content

Commit

Permalink
feat: allow using raw docstring for type docs
Browse files Browse the repository at this point in the history
closes #27
  • Loading branch information
Chris Larsen committed Jul 5, 2022
1 parent 8caad7c commit 3011fd5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type ProcessorConfig struct {
IgnoreTypes []string `json:"ignoreTypes"`
IgnoreFields []string `json:"ignoreFields"`
IgnoreGroupVersions []string `json:"ignoreGroupVersions"`
UseRawDocstring bool `json:"useRawDocstring"`
}

type RenderConfig struct {
Expand Down
2 changes: 2 additions & 0 deletions processor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func compileConfig(conf *config.Config) (cc *compiledConfig, err error) {
ignoreTypes: make([]*regexp.Regexp, len(conf.Processor.IgnoreTypes)),
ignoreFields: make([]*regexp.Regexp, len(conf.Processor.IgnoreFields)),
ignoreGroupVersions: make([]*regexp.Regexp, len(conf.Processor.IgnoreGroupVersions)),
useRawDocstring: conf.Processor.UseRawDocstring,
}

for i, t := range conf.Processor.IgnoreTypes {
Expand Down Expand Up @@ -59,6 +60,7 @@ type compiledConfig struct {
ignoreTypes []*regexp.Regexp
ignoreFields []*regexp.Regexp
ignoreGroupVersions []*regexp.Regexp
useRawDocstring bool
}

func (cc *compiledConfig) shouldIgnoreGroupVersion(gv string) bool {
Expand Down
5 changes: 5 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ func (p *processor) processType(pkg *loader.Package, info *markers.TypeInfo, dep
Doc: info.Doc,
}

if p.useRawDocstring && info.RawDecl != nil {
// use raw docstring to support multi-line and indent preservation
typeDef.Doc = strings.TrimSuffix(info.RawDecl.Doc.Text(), "\n")
}

// if the field list is non-empty, this is a struct
if len(info.Fields) > 0 {
typeDef.Kind = types.StructKind
Expand Down

0 comments on commit 3011fd5

Please sign in to comment.