Skip to content
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

Merged
merged 12 commits into from
May 27, 2021
Merged

Add Cadence documentation generator #927

merged 12 commits into from
May 27, 2021

Conversation

SupunS
Copy link
Member

@SupunS SupunS commented May 20, 2021

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:

  • Function declarations
  • Composite type declarations (structs, interfaces, enums, resources)

What's next:

  • Add remaining delcarations types. e.g: Events, variables, etc.
  • Extract parameters and return type info from the function docs.
  • Needs to polish up the formatting. e.g: Remove extra blank lines, etc.
  • Add a readme on how to run.
  • More tests

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@turbolent
Copy link
Member

Very nice! 😍 👏

@codecov-commenter
Copy link

codecov-commenter commented May 21, 2021

Codecov Report

Merging #927 (6be59a2) into master (c84693a) will increase coverage by 0.00%.
The diff coverage is n/a.

Impacted file tree graph

@@           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     
Flag Coverage Δ
unittests 40.10% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
runtime/common/intervalst/node.go 87.75% <0.00%> (+4.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c84693a...6be59a2. Read the comment docs.

@SupunS SupunS force-pushed the supun/doc-gen-2 branch 3 times, most recently from 0454b0e to d8c3acd Compare May 21, 2021 05:18
@SupunS SupunS marked this pull request as ready for review May 21, 2021 06:29
@SupunS SupunS requested a review from turbolent as a code owner May 21, 2021 06:29
Copy link
Member

@turbolent turbolent left a 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{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +259 to +302
"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
},
Copy link
Member

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

Copy link
Member Author

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) {
Copy link
Member

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 👍

@SupunS SupunS merged commit 1c06d00 into master May 27, 2021
@SupunS SupunS deleted the supun/doc-gen-2 branch May 27, 2021 04:24
@SupunS SupunS mentioned this pull request Jul 9, 2021
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants