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

Partially fix abstract Erlang types ({@type ...}) #1787

Merged
merged 3 commits into from
Oct 4, 2023
Merged

Partially fix abstract Erlang types ({@type ...}) #1787

merged 3 commits into from
Oct 4, 2023

Conversation

paulo-ferraz-oliveira
Copy link
Contributor

@type is deprecated but still documented: you get a warning upon documentation generation.

This surfaced at jelly-beam/rebar3_ex_doc#38.

Code out in the wild may contain references like the ones we include in the test.

This pull request attempts at solving a basic case for those.

EDoc seems broken for some types of @type (or at least not generating useful information), but at least this commit prevents a crash.

While discussing the solution with @starbelly we didn't know where to put the normalisation code. It might be good here, or it might belong in the doc_ast.ex module.

@type is deprecated but still documented

Code out in the wild may contain references like the ones
we include in the test

This commit attempts at solving a basic case for those

EDoc seems broken for some types of @type (or at least
not generating useful) information, but at least this commit
prevent a crash
@josevalim
Copy link
Member

I wouldn’t try to do anything smart. Can we just leave the HTML as is, making sure it does not crash?

@paulo-ferraz-oliveira
Copy link
Contributor Author

Wdym? Not putting code inside the a? Or the type- thing?

@paulo-ferraz-oliveira
Copy link
Contributor Author

Or simply avoiding the crash but not taking {@type ...} into account either (since it's deprecated)?

@paulo-ferraz-oliveira
Copy link
Contributor Author

I'll do a new commit to simply avoid the crash and nothing else.

@paulo-ferraz-oliveira
Copy link
Contributor Author

This is what's visible with the updated code (01b6065)

image

Links are not usable, because generated HTML (in doc) points to e.g. #type-myList, while anchor is identified (above) as #t:myList/0.

@paulo-ferraz-oliveira
Copy link
Contributor Author

paulo-ferraz-oliveira commented Oct 3, 2023

Using all @type examples from EDoc we get

image

and no crashes 👍 (except in the tests - if I try to create some for the examples, but I'm not sure if you want me to "fix" that too)

Edit: specifically, crash is in

    {:docs_v1, _, _, "application/erlang+html", %{"en" => doc}, _, _} =
      Code.fetch_docs(:erlang_foo)

when matching (that %{"en" => doc} is empty). Looking closely at the AST, it seems this happens because types declared like that get "hoisted" up. (if this makes sense) - in EDoc's docs: "All data type descriptions are placed in a separate section of the documentation, regardless of where the tags occur."

@paulo-ferraz-oliveira
Copy link
Contributor Author

I added this to the tests (locally - autolink_doc - where search and arity are new function arguments)

        {:docs_v1, _, _, "application/erlang+html", %{}, _, extra} ->
          [{_, _, _, %{"en" => doc}, _}] =
            Enum.filter(extra, fn
              {{:type, ^search, ^arity}, _, _, _, _} -> true
              _ -> false
            end)

as well as more tests, but maybe it's not worth it (?) I can push if you wanna.

Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

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

If @wojtekmach is happy, I am happy!

@wojtekmach wojtekmach merged commit aca43d0 into elixir-lang:main Oct 4, 2023
4 checks passed
@wojtekmach
Copy link
Member

Thank you! I'd strip out the <a> and just leave <code> but it definitely doesn't hurt to keep it this way for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants