-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Update attributes in EEP 48 #8945
Conversation
Currently, editors and documentation tooling must parse metadata from several chunks in order to function properly. The source is in the compilation chunk. The behaviours a module implements is in the attributes chunk. And the annotation of any definition requires traversing abstract code. With this commit, we introduce three new attributes, `:behaviours`, `:source`, and `:source_anno`, so this additional data can be standardized and easily located. We also remove `edit_url` from the standard. As it is not used by any of the official tooling, languages, or libraries.
@garazdawi please let me know if you are happy with these changes and we can also provide a PR to OTP to attach this informtation to its Docs chunk. |
CT Test Results 2 files 70 suites 1h 5m 43s ⏱️ Results for commit 6e9c07f. ♻️ This comment has been updated with latest results. To speed up review, make sure that you have read Contributing to Erlang/OTP and that all checks pass. See the TESTING and DEVELOPMENT HowTo guides for details about how to run test locally. Artifacts// Erlang/OTP Github Action Bot |
Could you give an/some examples of how |
@garazdawi it seems both Erlang and Elixir keep source as an absolute path, so that's how we should proceed?
The -doc "Example".
example() -> ok. So a literal copy of whatever is in the AST. For the module definition, probably the annotation of |
Sounds good, feel free to open a PR adding these. Just make sure that |
I wonder if it might also be a good idea to move the spec into the documentation metadata? So that all the docs can be rendered without looking into anything but the doc chunk? |
I thought about this, back when the EEP was written, and I could not decide, because if we are storing the whole spec as an AST, then we are effectively duplicating potentially large chunks of it. Could it be a problem? We could store only the string format but ExDoc will want to parse it to generate autolinks, and we would need to be able to parse both Elixir and Erlang versions. So I didn't see much benefit. Thoughts? |
For When considering that doc chunks can also be external to the .beam file it makes even more sense as then you can build only the .chunk files and use those for rendering the complete docs. For systems that are concerned about the file size, I think most strip doc chunks anyway? Or if they don't, then they can strip the debug info and still get complete documentation if the spec is included. So in conclusion I think I would like to see the spec in there. Maybe the format should be as the AST with a function that can be called to render it into a string? For example
|
Those are good points. Storing the function is tricky because the function may not be available. For example, I may be looking at a Elixir module without fully loading Elixir itself (or |
On elixir side that wasn't very useful as the spec was erlang code. A spec in typespec AST on the other hand can be easily translated back to elixir code |
Any tool will most likely want want to use their own rendering functions for things anyway, for example in the shell we want to provide the current terminal width. So yes, a string will work just as well. We will have to rely on documentation for the tools to know how to parse the string. |
I realized another possibility is to store the specs themselves as their own entry in the chunk:
This comes with the benefit of them having their own metadata (although the docs field itself would always be That said, are you ok with postponing this discussion? I have been postponing this on the ExDoc side as well because both Erlang and Elixir uses typespecs, so we may have assumptions there that can be harmful if a language uses something else. Given Elixir may have set-theoretic types in about a year, that will force us to exercise the tooling and come up with a better understanding of what is needed here. Btw, how do you want to proceed with this? Are we ok with merging this as a spec-only change and then send a PR for Erlang to add the new information? Or do you want a PR with everything? Although this is not ready yet for merging. |
I'm fine with postponing the spec discussion and merging this PR as is if you are happy with the names of the fields. |
For those following this, PR for |
Thanks! |
FTR PR attaching the new information to the docs chunk: #8975. |
Currently, editors and documentation tooling must
parse metadata from several chunks in order to
function properly. The source is in the compilation chunk.
The behaviours a module implements is in the attributes
chunk. And the annotation of any definition requires
traversing abstract code.
With this commit, we introduce three new attributes,
:behaviours
,:source
, and:source_anno
, sothis additional data can be standardized and easily located.
We also remove
edit_url
from the standard. As it is notused by any of the official tooling, languages, or libraries.