Skip to content

Commit

Permalink
Don't treat the lack of documentation as an error
Browse files Browse the repository at this point in the history
Even if there's no docstring, we can still print the type definition.

Furthermore, print "Undocumented" instead of "no documentation found".
The latter looks too close to the error reported when the identifier
couldn't be resolved.
  • Loading branch information
dominikh committed Apr 6, 2016
1 parent a4b5524 commit 4ecb996
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ident.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func IdentDoc(id *ast.Ident, info *loader.PackageInfo, prog *loader.Program) (*D
}

_, nodes, _ := prog.PathEnclosingInterval(obj.Pos(), obj.Pos())
if len(nodes) == 0 {
return nil, fmt.Errorf("No documentation found for %s", obj.Name())
}
var doc *Doc
for _, node := range nodes {
switch node.(type) {
Expand Down Expand Up @@ -167,5 +170,5 @@ func IdentDoc(id *ast.Ident, info *loader.PackageInfo, prog *loader.Program) (*D
}
}
}
return nil, fmt.Errorf("No documentation found for %s", obj.Name())
return doc, nil
}
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func main() {
}
fmt.Println(d.Title)
fmt.Println()
if d.Doc == "" {
d.Doc = "Undocumented."
}
doc.ToText(os.Stdout, d.Doc, indent, preIndent, lineLength)
}

Expand Down

0 comments on commit 4ecb996

Please sign in to comment.