-
-
Notifications
You must be signed in to change notification settings - Fork 10
RFC 0011: Extending API Docs #11
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
Merged
straight-shoota
merged 18 commits into
crystal-lang:main
from
nobodywasishere:nobody/extend-api-docs
Mar 25, 2025
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
407d34c
Extending API docs RFC
nobodywasishere 5e9026a
Update RFC number
nobodywasishere 0a52075
fix link typo
ysbaddaden 2c130f6
Update text/0011-extending-api-docs.md
nobodywasishere 84520c6
Update text/0011-extending-api-docs.md
nobodywasishere 6e22bc1
Update text/0011-extending-api-docs.md
nobodywasishere b222db2
Update text/0011-extending-api-docs.md
nobodywasishere 2ec23a0
Add info about how other languages handle this use-case
nobodywasishere 353c3b4
Update text/0011-extending-api-docs.md
nobodywasishere c467d1f
Better example comments
nobodywasishere 5220741
Update text/0011-extending-api-docs.md
nobodywasishere 53c19ed
Update text/0011-extending-api-docs.md
nobodywasishere 9127d5c
Update text/0011-extending-api-docs.md
nobodywasishere 0b06c53
Update text/0011-extending-api-docs.md
nobodywasishere d8b4aab
Finish all TBDs
nobodywasishere 825d75d
Update 0011-extending-api-docs.md
nobodywasishere b5a1588
Update 0011-extending-api-docs.md
nobodywasishere 9f1477f
Convert metadata into YAML frontmatter (see #3)
straight-shoota File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| - Feature Name: extending-api-docs | ||
| - Start Date: 2024-11-14 | ||
| - RFC PR: [crystal-lang/rfcs#0000](https://github.com/crystal-lang/rfcs/pull/0000) | ||
| - Issue: [crsytal-lang/crystal#6721](https://github.com/crystal-lang/crystal/issues/6721) | ||
|
|
||
| # Summary | ||
|
|
||
| This RFC would add a directive `:showdoc:` that would allow private / protected methods and objects, | ||
| as well as C lib, fun, enum, etc, to show up in API documentation. | ||
|
|
||
| # Motivation | ||
|
|
||
| Currently, API documentation is not generated for private/protected methods/objects or C lib binding objects. | ||
| This was originally done as these (typically) should not be used, however, this is not always the case. | ||
| When inheriting from a class that has a protected method that is intended to be implemented, it is useful | ||
| to know that method exists, and what parameters / types it has, without needing to refer to the source code. | ||
| Another use case is for libraries such as [raylib.cr](https://github.com/sol-vin/raylib-cr), where developing a | ||
| "Crystal" interface to them using classes and structs would be prohibitive, and currently requires diving | ||
| into the source code in order to figure out what methods are available. | ||
|
|
||
| # Guide-level explanation | ||
|
|
||
| The `:showdoc:` directive can be added to private or protected objects, as well as C lib binding objects, to have them show up in API documentation. | ||
| By default, these are hidden and should only be shown if they're intended to be used directly. | ||
|
|
||
| In this example, when generating API documentation, `Foo.foo` will be included even though it is a private method. | ||
|
|
||
| ```crystal | ||
| module Foo | ||
| # :showdoc: | ||
| private def self.foo | ||
| end | ||
| end | ||
| ``` | ||
|
|
||
| This also works for C lib, struct, enum, etc; everything in the `FooLib` namespace will be included in doc generation. | ||
|
|
||
| ```crystal | ||
| # :showdoc: | ||
| lib FooLib | ||
| fun my_function(value : Int32) : Int32 | ||
|
|
||
| enum FooEnum | ||
| Member1 | ||
| Member1 | ||
| Member3 | ||
| end | ||
|
|
||
| struct FooStruct | ||
| var_1 : Int32 | ||
| var_2 : Int32 | ||
| end | ||
| end | ||
| ``` | ||
|
|
||
| If a namespace has the `:nodoc:` directive, then the `:showdoc:` directive will have no effect on anything in its namespace. | ||
|
|
||
| ```crystal | ||
| # :nodoc: | ||
| struct MyStruct | ||
| # This will not show up in API docs | ||
| # :showdoc: | ||
| struct MyStructChild | ||
| end | ||
| end | ||
| ``` | ||
|
|
||
| # Reference-level explanation | ||
|
|
||
| - The parser will need to be updated to support doc comments for C lib binding objects and the `:showdoc:` directive | ||
| - The documentation generator will need to be updated to support C lib binding objects and private/protected objects | ||
| - If an object has a `:showdoc:` directive and its parent namespace is shown, then it should be shown too | ||
|
|
||
| TBD | ||
|
|
||
| # Drawbacks | ||
|
|
||
| TBD | ||
|
|
||
| # Rationale and alternatives | ||
|
|
||
| The other design that has been considered is having flags on the documentation generator itself that enable showing of private / protected objects and C lib objects in the API documentation. We chose not to go with this design as it required flags to be added at generation time, and only generated all or none (no granularity in what is shown). | ||
|
|
||
| This cannot be done in a library instead as it requires updates to the parser itself. This proposal makes Crystal code easier to understand, as it increases the amount and quality of API documentation. | ||
|
|
||
| # Prior art | ||
|
|
||
| There is a [PR](https://github.com/crystal-lang/crystal/pull/14816) implementing a similar feature, however it uses the generation-time flag method mentioned above, instead of the `:showdoc:` directive. | ||
|
|
||
| # Unresolved questions | ||
|
|
||
| TBD | ||
|
|
||
| # Future possibilities | ||
|
|
||
| TBD | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.