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

Replace Specs heading #1455

Merged
merged 5 commits into from
Mar 10, 2022
Merged

Replace Specs heading #1455

merged 5 commits into from
Mar 10, 2022

Conversation

Odaeus
Copy link
Contributor

@Odaeus Odaeus commented Jan 3, 2022

See issue #602.

As well as replacing the heading I removed the padding as it seemed excessive, but I'm happy to restore that if you like.

Original:
CleanShot 2022-01-03 at 18 44 22

New (without padding):
CleanShot 2022-01-03 at 18 45 13

CleanShot 2022-01-03 at 18 44 57

With padding:
CleanShot 2022-01-03 at 18 46 22

CleanShot 2022-01-03 at 18 44 41

@wojtekmach
Copy link
Member

Types should be rendered with @type. If missing, please also add a test how opaque type is rendered.

@eksperimental
Copy link
Contributor

I prefer the one with the padding. It makes it stand out from the rest of the docs that follow.

@josevalim
Copy link
Member

No padding unless we are adding border around it, to make consistent elsewhere.

@eksperimental
Copy link
Contributor

No padding unless we are adding border around it, to make consistent elsewhere.

Note that the current specs are padded and have no border around them.

@eksperimental
Copy link
Contributor

I'm fine with either way.

@josevalim
Copy link
Member

Sorry, I was not clear enough. The previous had the header, to give some context about it. If we pad it now, it will look like code, but not quite like code, and not enough context around it. Although I think making it look like code is worse? 🤔

@Odaeus
Copy link
Contributor Author

Odaeus commented Jan 3, 2022

@wojtekmach good point, thanks!

Should opaque types be rendered with @opaque or @type?
CleanShot 2022-01-03 at 21 14 02@2x

I only need to consider @type, @spec, and @opaque right?

@josevalim
Copy link
Member

There are also @callbacks and @macrocallbacks, for example: https://hexdocs.pm/ecto/Ecto.Repo.html

@Odaeus Odaeus force-pushed the main branch 2 times, most recently from b66953c to 419fa87 Compare January 3, 2022 23:05
@Odaeus
Copy link
Contributor Author

Odaeus commented Jan 3, 2022

I've added support for all the mentioned attribute strings (and @opaque) in a new commit (which can be squashed if wanted).

Callbacks:
CleanShot 2022-01-03 at 23 40 56@2x

@josevalim
Copy link
Member

Oh, we need to check how those look for Erlang. I think mix docs —language erlang would generate Erlang ones. And we need to see if the gray color works well on Dark Mode (press n to enable it).

@Odaeus
Copy link
Contributor Author

Odaeus commented Jan 4, 2022

The contrast ratio on the attribute in night mode was too low (using Chromium's built-in analyser) so I've set it to a night mode gray and it's happy now. (Thank you to whoever set up these vars!)

Before:
CleanShot 2022-01-04 at 17 09 23

After:
CleanShot 2022-01-04 at 17 24 25

I need a pointer on how to generate Erlang examples please. @josevalim 's suggestion of mix docs --language erlang doesn't seem to do anything (--language flag is for human languages?). I see there are some tmp test directories created by the ExDoc.Retriever.ErlangTest but they are empty unlike the Elixir tmp outputs.

@josevalim
Copy link
Member

Sorry, you are right, you need to set proglang: :erlang in the docs configuration. However @wojtekmach is the one who would know best how to make this configurable per language.

@wojtekmach
Copy link
Member

besides what José said, if you're generating the docs with the escript, ex_doc ... --proglang erlang would work too.

if "opaque" in node.annotations do
"@opaque"
else
"@type"
Copy link
Member

Choose a reason for hiding this comment

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

@type and friends is Elixir specific which means it won't be appropriate for e.g. Erlang. We try to keep language-specific functionality in the corresponding ExDoc.Language.* module so let's see if we can make the change there.

@Odaeus
Copy link
Contributor Author

Odaeus commented Jan 5, 2022

Thanks for the config setting, I didn't realise it was working because the output looks identical... except with red highlights instead of blue! I will work on adjusting the output for Erlang support.

@Odaeus
Copy link
Contributor Author

Odaeus commented Jan 11, 2022

I've added a new commit on top so you can see the extraction I made to support both languages as suggested. But I'm lost on how to demonstrate or test the Erlang side. I'm not sure what effect proglang actually has given all the code mix build has is still Elixir, so it still outputs "@SPEC" and so. I wanted to add tests but I can't find any that test Erlang output, only the "autolinker" and AST generation. I feel like generating new Erlang output tests is out of scope for this change, but am I missing something?

@wojtekmach
Copy link
Member

I wanted to add tests but I can't find any that test Erlang output, only the "autolinker" and AST generation.

Yup. I just added a basic test here: https://github.com/elixir-lang/ex_doc/pull/1514/files. Once this lands, could you rebase your PR on top and adjust the test accordingly? Thanks!

cc @josevalim

@wojtekmach
Copy link
Member

btw, proglang is a bit of misnomer. On a per-module basis we ignore that value, instead we render the docs for a given module based on the language the module is compiled with. proglang is really about the style we render the whole docs with.

@Odaeus
Copy link
Contributor Author

Odaeus commented Feb 14, 2022

Thanks so much @wojtekmach! I approached trying to do the same thing a few times but kept getting stuck.

@wojtekmach
Copy link
Member

the PR landed, please rebase. Thank you for working on this! <3

@Odaeus
Copy link
Contributor Author

Odaeus commented Feb 14, 2022

@wojtekmach I've rebased and amended your new test slightly to test the new output.

I hit an issue with running the tests but it seems isolated to my system.

@wojtekmach
Copy link
Member

@Odaeus thanks, fixed on main!

@Odaeus
Copy link
Contributor Author

Odaeus commented Feb 20, 2022

@wojtekmach updates made with a commit on top (22ab1c9). Let me know if I should squash away the in-between commits.

Copy link
Member

@wojtekmach wojtekmach left a comment

Choose a reason for hiding this comment

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

LGTM, just one tiny comment left.

@wojtekmach
Copy link
Member

No need to squash yourself, we'll do it when merging.

Issue: elixir-lang#602

Remove the "Specs" heading in favour of specifying `@spec` in-line with
the spec definition. This makes it clearer visually because the it
reduces the prominence of the typespec over the function signature, and
semantically because the heading is not correct for the descriptive
text.
Instead of prefixing `@spec` for all typespec output, use the correct
matching module attribute used to define it.
Show the typespec definition in Erlang format (`-spec`) for Erlang code
by adding `ExDoc.Language.format_attribute/1` and calling it from the
template via the `module.language` property.
The formatting of spec attributes is language specific and not all
languages support the same attributes, so rename and move
`get_spec_attribute/1` from the formatter to the language modules.
@Odaeus
Copy link
Contributor Author

Odaeus commented Feb 28, 2022

Just checking in to make sure you're not waiting on me for anything that I've forgotten. 😄

@wojtekmach wojtekmach requested a review from josevalim February 28, 2022 11:12
@wojtekmach wojtekmach merged commit 28ff9a3 into elixir-lang:main Mar 10, 2022
@wojtekmach
Copy link
Member

Thank you!

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