-
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
EDoc: EEP-48 doc chunk generation #2803
Conversation
This is amazing work @erszcz! ❤️ One of the things to discuss, probably for after this PR is merged, is to deprecate the tags |
I was just about to ask if we could get this in place for the OTP 24
release (and release candidates beginning in February) so this is fantastic
good news.
Thanks @erszcz.
/Regards Kenneth
…On Wed, Oct 14, 2020 at 5:09 PM Radek Szymczyszyn ***@***.***> wrote:
This PR enables EDoc to output EEP-48 style doc chunks. The work leading
to this PR was so far discussed and documented at erlef/documentation-wg#4
<erlef/documentation-wg#4>, whereas developed
at https://github.com/erszcz/edoc.
I tried to address all points raised in the discussions so far:
1. Chunks are written to disk as standalone files, not embedded into
.beam files.
2. It's possible to generate chunks from the command line by running a
script.
3. The chunks are as close to erl_docgen chunks as possible (with the
caveat of type links described below).
4. All @SPEC and @type tags are rewritten to -spec and -type
attributes, respectively.
We discussed the type link caveat with @garazdawi
<https://github.com/garazdawi> - erl_docgen chunk links to types do not
use type arities. This means links to t/0 and t/1 have the same form.
EDoc chunks do not follow this principle, since it seemed more robust to
allow linking to arbitrary types. Until this is fixed for erl_docgen
chunks, measures have to be taken in 3rd party tools (e.g. ExDoc) to watch
for this difference.
Some features stemming from EDoc design and implementation, but not
necessarily consistent with expectations towards a modern documentation
system are not addressed in this PR:
1. Function doc comments can be precede or follow -spec attributes,
but type doc comments must follow -type attributes.
2. Callbacks cannot have associated doc comments at all.
3. @SInCE and @deprecated tags are supported on functions, but are not
supported on types or callbacks.
This PR also adds test/eep48_SUITE.erl which tests the majority of the
newly added functionality, as well as some of the above points which are
currently not supported (these tests are skipped by default).
------------------------------
You can view, comment on, or merge this pull request online at:
#2803
Commit Summary
- Import EEP-48 chunk support
- Merge branch 'import-edoc-chunks' into edoc-chunk-support
- Fix build issues with warnings-as-errors
- Update SOURCES in src/Makefile
- Fix more warnings-as-errors build issues
- Enable eep48_SUITE
- Output callback chunk entries based on #tag{} records
- Describe EEP-48 chunk support and how to generate chunks with EDoc
- Drop the EDoc chunk Rebar3 plugin from this repository
- Fix some types
- Export shell_docs:{chunk_elements,chunk_element_attr}/0
- Add edoc_doclet to erl_docgen's list of modules known not to have
any functions
- Fix Dialyzer errors
- Remove some TODOs
File Changes
- *A* lib/edoc/bin/edoc.escript
<https://github.com/erlang/otp/pull/2803/files#diff-ee778b4af2631a1e1aa6984ef56ba35e6ffab41beeb7025d7d92fba048623c7d>
(5)
- *M* lib/edoc/doc/overview.edoc
<https://github.com/erlang/otp/pull/2803/files#diff-7bc60eb4edf1ff4080c56a92eb534fa9f00b3e21ba68694ba6b1dc1882d53101>
(39)
- *M* lib/edoc/include/edoc_doclet.hrl
<https://github.com/erlang/otp/pull/2803/files#diff-a8cd5451e7912fb1caf64214b20bc69a778ef41502cfa1ed014073d78f9127e9>
(37)
- *M* lib/edoc/src/Makefile
<https://github.com/erlang/otp/pull/2803/files#diff-21c03813315afd3004e0fc4c9aabe1bac8f6330a22a80e91c140e0fa6b030241>
(8)
- *M* lib/edoc/src/edoc.app.src
<https://github.com/erlang/otp/pull/2803/files#diff-0a87902b12eb6aa05129af33e7b184453f98012d7c9eee9f4b5f6c7aca6b7c04>
(6)
- *M* lib/edoc/src/edoc.erl
<https://github.com/erlang/otp/pull/2803/files#diff-0b079f122092e17e86f314df15ba27691ff93d9316ea7e724b8bcf260e5a4098>
(171)
- *M* lib/edoc/src/edoc.hrl
<https://github.com/erlang/otp/pull/2803/files#diff-977c7f72433598c4ac43ab02af3242866076c32acbd2c8f39e95398cf694a7a0>
(45)
- *A* lib/edoc/src/edoc_cli.erl
<https://github.com/erlang/otp/pull/2803/files#diff-b3ef7e087b1a2ad92ac1e72fd39af8efb7574f69f3e3650595e071aa0e70b189>
(95)
- *M* lib/edoc/src/edoc_data.erl
<https://github.com/erlang/otp/pull/2803/files#diff-4d0162619716552eb4c6c2f16d3e0f03eb143e8a75517b7a4d27e4a7594eb513>
(35)
- *M* lib/edoc/src/edoc_doclet.erl
<https://github.com/erlang/otp/pull/2803/files#diff-fba37bba9fd6411f788c8864b0a042d6f4e844db53b4b4d7b0042e8a2b09fd67>
(441)
- *A* lib/edoc/src/edoc_doclet_chunks.erl
<https://github.com/erlang/otp/pull/2803/files#diff-e4410b8280b27cf26217699e9fa9c536829181db786b570802bcd2a40dbe11b9>
(117)
- *A* lib/edoc/src/edoc_doclet_default.erl
<https://github.com/erlang/otp/pull/2803/files#diff-590d21cc001fcba0ce54ffc5381911546b448c24607ba0356052946a08b4f636>
(462)
- *M* lib/edoc/src/edoc_extract.erl
<https://github.com/erlang/otp/pull/2803/files#diff-188f547a2e63e6d2b93b4b634d27284bd8f532995710f4c7baaa5a66c7a08a78>
(248)
- *M* lib/edoc/src/edoc_layout.erl
<https://github.com/erlang/otp/pull/2803/files#diff-7ceb762dc31de77e955cdc811dcb2c760b0c5c49d5d121aacb034fd9f0e04ba3>
(12)
- *A* lib/edoc/src/edoc_layout_chunks.erl
<https://github.com/erlang/otp/pull/2803/files#diff-cc2ad3d2874b85f201ad812ada23b33f3fa4cdc92a790b4dc78c76d4182ac708>
(393)
- *M* lib/edoc/src/edoc_lib.erl
<https://github.com/erlang/otp/pull/2803/files#diff-9d4fb29b418b494e1cbf7de1c7340fb4f5b63cc409b23cf6e0898e99cdbf2206>
(63)
- *M* lib/edoc/src/edoc_macros.erl
<https://github.com/erlang/otp/pull/2803/files#diff-7874d8c1279db0d58e35f8dabda5931598cf2d140f70d10b4aa57d27f8ad8a7f>
(5)
- *M* lib/edoc/src/edoc_parser.yrl
<https://github.com/erlang/otp/pull/2803/files#diff-08fac87126bc3f83aaee7fb3631289ff69898c01f5c25a5374f36e5915b87faf>
(12)
- *M* lib/edoc/src/edoc_refs.erl
<https://github.com/erlang/otp/pull/2803/files#diff-656cace0664d499b8847f3949b440d03b59cb6b38c7bcfbaf15d53f2acc361b9>
(47)
- *M* lib/edoc/src/edoc_run.erl
<https://github.com/erlang/otp/pull/2803/files#diff-41a5d13b5a98a97c5faf0f614d5ca267ec751c8f3542e021562397aec5fa342b>
(18)
- *M* lib/edoc/src/edoc_specs.erl
<https://github.com/erlang/otp/pull/2803/files#diff-2d7bbab975312d3c634bd173db9f6567021edb5057af5407ab3801a983a99577>
(59)
- *M* lib/edoc/src/edoc_tags.erl
<https://github.com/erlang/otp/pull/2803/files#diff-e91e9acf3ba1063cb68d62e18ea200a80fcad988264be31af5cbdbf9e249e6ed>
(20)
- *M* lib/edoc/src/edoc_types.erl
<https://github.com/erlang/otp/pull/2803/files#diff-e96bd7c16c6eb37adce5c88fe687fde14e793abd170e93e8691c4bfb3a1c4e8e>
(94)
- *M* lib/edoc/src/edoc_types.hrl
<https://github.com/erlang/otp/pull/2803/files#diff-3cd9a87a9a2b1f736a5ac3fe9b417052666cc896900508edb6601e52e0b88686>
(75)
- *M* lib/edoc/test/Makefile
<https://github.com/erlang/otp/pull/2803/files#diff-107c51805818c42250d762d26b196e0d782d6526d9db1d4ed26eaf7e68c9a368>
(3)
- *A* lib/edoc/test/eep48_SUITE.erl
<https://github.com/erlang/otp/pull/2803/files#diff-4cca9d805c2e58708406fd194dd1640ce9f66f27404c10ec99acf0c7cc757291>
(290)
- *A* lib/edoc/test/eep48_SUITE_data/eep48_links.erl
<https://github.com/erlang/otp/pull/2803/files#diff-f84ff0e291adc4bc1ec4ced67efdde94043057e5fc632d383dbb07a7e237e033>
(102)
- *A* lib/edoc/test/eep48_SUITE_data/eep48_meta.erl
<https://github.com/erlang/otp/pull/2803/files#diff-65229d9ea93b2e0bb1b18c42b7507849a2b3bf76b0a1edb9b79bf737c5dc867a>
(35)
- *M* lib/erl_docgen/src/docgen_xml_to_chunk.erl
<https://github.com/erlang/otp/pull/2803/files#diff-7c882197ab5fc0a16a579261802a2d72e18a52560e68ccf2e4ccf71f4415a82a>
(3)
- *M* lib/stdlib/src/shell_docs.erl
<https://github.com/erlang/otp/pull/2803/files#diff-f0464950a78b61375e01dc0c9f31222f83dd71d85c77783bd39d9e57379a3f0e>
(2)
Patch Links:
- https://github.com/erlang/otp/pull/2803.patch
- https://github.com/erlang/otp/pull/2803.diff
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2803>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABFWSFVSGFVHFSGAJD4LRLSKW5K5ANCNFSM4SQXUSYQ>
.
|
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've done a cursory review and I think all in it it looks very good. Most of the comments are about backward-compatibility and documentation.
It would be nice if the changes of @spec
to -spec
would be a separate commit from everything else so that it is easier to see that it does not change any functionality.
Does @richcarl have any comments about this PR?
I also looked through some rendered functions and found some small irregularities that I'm not sure if you have seen or not:
erl_parse:tree/2
In the edoc html generate this function looks like this:
tree(Type::atom(),Data::term()) -> tree()
however, in the shell docs it looks like this:
-spec tree(atom(),term()) -> tree().
This because edoc for html reads the variable names and inserts them
into the spec. Information is lost when this is not done as the reader
does not know which argument is Type
and which is Data
in the text.
-spec tree(atom(), term()) -> tree().
For special purposes only. Creates an abstract syntax tree node
with type tag *Type* and associated data *Data*.
See also
See also data/1.
See also is_tree/1.
See also type/1.
These should probably be grouped into one:
See also data/1, is_tree/1, type/1
as that is done both in the edoc html and shell_docs.
Problem in shell_docs
Seems like shell_docs does not render <pre>
correctly, or rather
it does not insert a newline before itself so that things like merl
look like this:
Quick start
To enable the full power of Merl, your module needs to include the
Merl header file:
-include_lib("syntax_tools/include/merl.hrl").
Then, you can use the ?Q(Text) macros in your code to create
ASTs or match on existing ASTs. For example:
Tuple = ?Q("{foo, 42}"),
?Q("{foo, _@Number}") = Tuple,
Call = ?Q("foo:bar(_@Number)")
Calling merl:print(Call) will then print the following code:
foo:bar(42)
The ?Q macros turn the quoted code fragments into ASTs, and
I'll take a look at fixing that and try not to break any of the erl_docgen renderings.
Thanks for the review, @garazdawi! I think it makes the most sense to start with the spec/type changes. I'm sending a separate PR shortly, to make it easy to review. Then, I'll rebase this as appropriate. |
fc009ab
to
f1c92fa
Compare
700bf56
to
eafc139
Compare
With regard to -spec tree(atom()) -> tree().
tree(Type) ->
tree(Type, []).
-spec tree(atom(), term()) -> tree().
tree(Type, Data) ->
... We get properly named types in
It does not yet support 'bounded_fun' syntax tree nodes ( |
Done in the newest batch of changes. Moreover, arg names are now properly added to |
Would you mind rebasing on top of latest master to get the #2914 changes removed from this PR? |
@garazdawi Sure, I should be able to rebase this tomorrow. I also have some WIP on the documentation for the escript - I'll attach on top of the rebase. |
Great, let me know when you are ready for me to review the PR again. |
e10d3cb
to
db33aff
Compare
I've rebased this on top of the current master. I think I've addressed all points of the first review - please let me know if there's something missing. The current status is as follows:
TODOs:
|
Hello, I did
Is that because they have both a |
I think it is fine that they do not match 100%. This is an oddity in the way that edoc behaves, but I don't think it is worth forcing users to rewrite their specs. |
I think it is better to do this in another PR. |
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 did a quick look to see if it would be easy to add support in the make system to use edoc instead of erl_docgen to build the doc chunks for Erlang/OTP and it turns out that it is not. So I think we will leave that for later.
My only remaining question from the original review is whether we should document the edoc_doclet_chunks
and edoc_layout_chunks
modules? The way it is implemented now it is only possible to generate chunks via the script without relying on undocumented API's.
d8b83b9
to
bc0d6d4
Compare
Status update:
Done.
Indeed, that turns out to be the reason. It seems that in such a case EDoc doesn't pass the -spec attr form down to the layout :| I might be able to find out why and fix it in EDoc core, but for now a warning will be printed that just |
In order to gather all info about a type that EEP-48 requires, we refer to EDoc #tag{} records. These records do not contain the type name at the top level, so this lookup was done just by line number. When a header file is included into another file, it might happen that the position information of two distinct type definitions is the same - they are still different types, but the lookup by line will return the wrong one. This lead to the following error (on kernel/src/disk_log.erl): name: dlog_size arity: 0 type attr: {attribute,82,type,{file_error,{type,82,term,[]},[]}} edoc: error in layout 'edoc_layout_chunks': {'EXIT', {{badmatch,{file_error,[]}}, [{edoc_layout_chunks,meta_type_sig,4, [{file,"edoc_layout_chunks.erl"}, {line,170}]}, This change introduces a more sophisticated and robust lookup, which fixes the problem of types defined in include files.
- Fix unused variables and lookup functions - Remove edoc-orig-tag - Remove name attribute from <a> elements - Be less verbose if not debugging
Co-authored-by: Lukas Larsson <[email protected]>
ea0046d
to
52dc947
Compare
This change also prevents the 'multiple @SPEC tag' error.
github actions doc build has started to fail with the latest changes, do you know why? |
ce77e68 and c5581d2 introduce the priority of attrs over tags. However, as this changes EDoc core, it's not limited to chunk generation, but all paths, so static HTML or Specs were missing in OTP docs after these changes - I'm now troubleshooting some types which used to be exported, but currently are not. |
93c34bb
to
52dc947
Compare
I’ve reverted the PR to the last commit passing all checks. I’ll carry on in a separate branch. |
Apparently, these are not handled properly by EDoc, therefore types mentioned in them aren't properly exported to docs.
The latest commits invert the priorities of tags and attributes. This priority inversion means that if a module has both a In case of specs, the problem of consecutive I finally think there's nothing more to add to this PR, unless some bugs pop up. @garazdawi @richcarl what do you think? |
I agree. |
Merged! Thanks for all your work! |
Woohoo! And thank you for the reviews! |
This PR enables EDoc to output EEP-48 style doc chunks. The work leading to this PR was so far discussed and documented at erlef/documentation-wg#4, whereas developed at https://github.com/erszcz/edoc.
I tried to address all points raised in the discussions so far:
.beam
files.erl_docgen
chunks as possible (with the caveat of type links described below).@spec
and@type
tags are rewritten to-spec
and-type
attributes, respectively.We discussed the type link caveat with @garazdawi -
erl_docgen
chunk links to types do not use type arities. This means links tot/0
andt/1
have the same form. EDoc chunks do not follow this principle, since it seemed more robust to allow linking to arbitrary types. Until this is fixed forerl_docgen
chunks, measures have to be taken in 3rd party tools (e.g. ExDoc) to watch for this difference.Some features stemming from EDoc design and implementation, but not necessarily intuitive, are not addressed in this PR:
-spec
attributes, but type doc comments must follow-type
attributes.@since
and@deprecated
tags are supported on functions, but are not supported on types or callbacks.This PR also adds
test/eep48_SUITE.erl
which tests the majority of the newly added functionality, as well as some of the above points which are currently not supported (these tests are skipped by default).