-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Cadence documentation generator #927
Conversation
Very nice! 😍 👏 |
Codecov Report
@@ Coverage Diff @@
## master #927 +/- ##
=======================================
Coverage 40.09% 40.10%
=======================================
Files 254 254
Lines 32206 32206
=======================================
+ Hits 12913 12915 +2
+ Misses 18406 18405 -1
+ Partials 887 886 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
0454b0e
to
d8c3acd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Good idea to use Go templates, that makes it easy to customize the output 👍
return strings.Join(gen.typeNames, nameSeparator) | ||
} | ||
|
||
var functions = template.FuncMap{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
"isFunction": func(declaration ast.Declaration) bool { | ||
return declaration.DeclarationKind() == common.DeclarationKindFunction | ||
}, | ||
|
||
"isComposite": func(declaration ast.Declaration) bool { | ||
switch declaration.DeclarationKind() { | ||
case common.DeclarationKindStructure, | ||
common.DeclarationKindStructureInterface, | ||
common.DeclarationKindResource, | ||
common.DeclarationKindResourceInterface, | ||
common.DeclarationKindContract, | ||
common.DeclarationKindContractInterface: | ||
return true | ||
default: | ||
return false | ||
} | ||
}, | ||
|
||
"hasConformance": func(declaration ast.Declaration) bool { | ||
switch declaration.DeclarationKind() { | ||
case common.DeclarationKindStructure, | ||
common.DeclarationKindResource, | ||
common.DeclarationKindContract, | ||
common.DeclarationKindEnum: | ||
return true | ||
default: | ||
return false | ||
} | ||
}, | ||
|
||
"isInterface": func(declaration ast.Declaration) bool { | ||
switch declaration.DeclarationKind() { | ||
case common.DeclarationKindStructureInterface, | ||
common.DeclarationKindResourceInterface, | ||
common.DeclarationKindContractInterface: | ||
return true | ||
default: | ||
return false | ||
} | ||
}, | ||
|
||
"isEnum": func(declaration ast.Declaration) bool { | ||
return declaration.DeclarationKind() == common.DeclarationKindEnum | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! We could maybe add these template function right to DeclarationKind
, e.g. DeclarationKind.IsTypeDeclaration
is already a similar one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure whether it would be useful for other components, so didn't want to pollute the existing APIs.
Maybe we can add if there are more requirements?
|
||
// This is a convenient method to generate the doc files given a cadence file. | ||
// Can be used to generate the assert files needed for doc tests. | ||
func TestDocGen(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work even adding tests for this 👍
Work towards #339
Description
This is an initial version of a documentation generator for cadence. The tool generates documentation for declarations at the top level, as well as in nested levels. This version covers:
What's next:
master
branchFiles changed
in the Github PR explorer