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

OTP27 export moduledoc and doc for module docs and function docs #3010

Open
inoas-nbw opened this issue Apr 19, 2024 · 6 comments · May be fixed by #3729
Open

OTP27 export moduledoc and doc for module docs and function docs #3010

inoas-nbw opened this issue Apr 19, 2024 · 6 comments · May be fixed by #3729
Labels
good first issue Good for newcomers help wanted Contributions encouraged priority:medium

Comments

@inoas-nbw
Copy link

inoas-nbw commented Apr 19, 2024

This EEP proposes two new attributes: -doc and -moduledoc. They could be used as follows:

See: https://www.erlang.org/eeps/eep-0059#new-module-attributes

Implemented in OTP 27 https://www.erlang.org/news/167#documentation

Maybe moduledoc false for @internal? https://www.erlang.org/eeps/eep-0059#hidden-docs

@lpil
Copy link
Member

lpil commented Apr 19, 2024

Yooo this rules!! Let's do it for sure

@lpil lpil added help wanted Contributions encouraged good first issue Good for newcomers priority:medium labels Apr 19, 2024
@inoas
Copy link
Contributor

inoas commented Apr 19, 2024

Cool. I may be alone with this but I think that gleam is not just great on itself but is the best way to create beam eco system libraries and this will help a lot <3.

@mooreryan
Copy link

Hey, I'm pretty interested in this feature (I made a post about it on discord yesterday), and was looking through the code exploring ways that it could potentially be added.

I was looking through the code and it looks like the function that generates erlang code is module_document. That takes a TypedModule, which includes a TypedDefinition, which has a TypedExpression, which has the Fn variant, but that variant doesn't carry the documentation info.

There is the get_documentation that allows you to get documentation from some of the TypedExpression variants (Var and ModuleSelect). So I was thinking at least the potential may be there to let the typed AST Fn carry around something from which its documentation could be recovered?

If that is way off track, do y'all have any ideas about how to go about adding this feature?

Module docs would be cool as well, but so far I have only tried looking into the function level docs.

@lpil
Copy link
Member

lpil commented Oct 18, 2024

I don't have any particular thoughts on the implementation, but I expect it to be fairly straightforward given we already use documentation for various things in the compiler.

Maybe we should wait until OTP26 is EOL'd before implementing this as it doesn't support these attributes?

@giacomocavalieri
Copy link
Member

Maybe we should wait until OTP26 is EOL'd before implementing this as it doesn't support these attributes?

At CodeBEAM someone showed a way to do it while keeping compatibility with lower OTP versions:

-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.

We could add this definition to the top of the generated modules.

@lpil
Copy link
Member

lpil commented Oct 18, 2024

Sneaky!

@giacomocavalieri giacomocavalieri linked a pull request Oct 21, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Contributions encouraged priority:medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants