diff --git a/internal/repotools/cmd/docextractor/extract.go b/internal/repotools/cmd/docextractor/extract.go index 46f1c5420f0..ea0d3ff6436 100644 --- a/internal/repotools/cmd/docextractor/extract.go +++ b/internal/repotools/cmd/docextractor/extract.go @@ -76,15 +76,11 @@ func Extract(servicePath string, serviceDir fs.DirEntry, items map[string]jewelr // extractType iterates through func extractTypes(packageName string, types map[string]*ast.TypeSpec, items map[string]jewelryItem) error { for kt, vt := range types { - summary := "" - if vt.Doc != nil { - summary = vt.Doc.Text() - } typeName := vt.Name.Name item := jewelryItem{ Name: typeName, - Summary: summary, + Summary: formatComment(vt.Doc), Members: []jewelryItem{}, Tags: []string{}, OtherBlocks: map[string]string{}, @@ -134,26 +130,13 @@ func extractTypes(packageName string, types map[string]*ast.TypeSpec, items map[ break } fieldName := vf.Names[i].Name - var fieldItem jewelryItem - if vf.Doc == nil || vf.Doc.List == nil || vf.Doc.List[i] == nil { - fieldItem = jewelryItem{ - Name: fieldName, - Tags: []string{}, - OtherBlocks: map[string]string{}, - Params: []jewelryParam{}, - Members: []jewelryItem{}, - Summary: "", - } - - } else { - fieldItem = jewelryItem{ - Name: fieldName, - Tags: []string{}, - OtherBlocks: map[string]string{}, - Params: []jewelryParam{}, - Members: []jewelryItem{}, - Summary: vf.Doc.List[i].Text, - } + fieldItem := jewelryItem{ + Name: fieldName, + Tags: []string{}, + OtherBlocks: map[string]string{}, + Params: []jewelryParam{}, + Members: []jewelryItem{}, + Summary: formatComment(vf.Doc), } fieldItem.Type = jewelryItemKindField fieldItem.BreadCrumbs = []breadCrumb{ @@ -170,15 +153,11 @@ func extractTypes(packageName string, types map[string]*ast.TypeSpec, items map[ Kind: jewelryItemKindField, }, } - se, ok := vf.Type.(*ast.StarExpr) - if ok { - ident, ok := se.X.(*ast.Ident) - if ok { - fieldItem.Signature = typeSignature{ - Signature: ident.Name, - } - } + fieldItem.Signature = typeSignature{ + Signature: toSignature(vf.Type, packageName), + // Location is unused - links have to be embedded in signature } + members = append(members, fieldItem) } } @@ -189,6 +168,125 @@ func extractTypes(packageName string, types map[string]*ast.TypeSpec, items map[ return nil } +// We've already converted the model's HTML to Go docs, now for ref docs we +// must convert back. We can't use the model's original docs directly because +// that doesn't include extra content we may inject at codegen. +// +// Practically this is just a matter of converting lists and paragraphs, since +// that's really all Go docs do in terms of formatting. Links are left as-is. +// Note we don't bother with