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

Eep 48 markdown #1100

Merged
merged 33 commits into from
Oct 27, 2021
Merged

Eep 48 markdown #1100

merged 33 commits into from
Oct 27, 2021

Conversation

garazdawi
Copy link
Contributor

@garazdawi garazdawi commented Oct 1, 2021

Description

This PR adds a markdown rendering backend for EEP-48 style documentation.

TODO:

  • Create markdown renderer
  • Fetch docs for types
  • Use edoc doc chunks renderer when available
  • Use edoc doc chunks renderer when available
  • Add docs to type completion
  • Extract clauses when docs do not exist
  • Check all versions of file for eep48 docs before resorting to edoc (i.e. if developing OTP and autocompleting the lists module)
  • Fix multiline code examples in emacs. See atom_to_list/1 for example.
  • Add testing...

In VS code the change looks like this.

Before:
before_els_markdown

After:
after_els_markdown

I'm opening this as a draft to get some feedback if this is something you want. If so, there is more work to be done in order to add tests and also check that is actually renders the markdown nicely in most of the editors.

@robertoaloi
Copy link
Member

Hi @garazdawi !

I guess improving the way documentation is displayed would be a nice thing to do. I just wonder why we'd need to fork the shell_docs module which is currently part of stdlib. Is the idea to iterate faster within the erlang_ls repo and eventually merge the changes back to OTP?

@garazdawi
Copy link
Contributor Author

I guess improving the way documentation is displayed would be a nice thing to do.

You don't sound overly convinced?

I just wonder why we'd need to fork the shell_docs module which is currently part of stdlib. Is the idea to iterate faster within the erlang_ls repo and eventually merge the changes back to OTP?

I choose to make a copy of the Erlang/OTP implementation for rendering in the shell in order to get some of the basic framework in place. I've redone much of the actual rendering logic as markdown and ansi shells are different in what they need.

I started out with the idea of creating a markdown renderer for EEP-48 style documentation in Erlang/OTP. But I think that in order to make the docs look nice, it will have to render different markdown depending on the editor, which leads me to think that this code belongs here instead.

If it turns out that I was wrong and no difference was needed for different editors, I'm not opposed to moving it into Erlang/OTP as I would rather maintain them both in one place than two separate versions.

@robertoaloi
Copy link
Member

You don't sound overly convinced?

I am very convinced! I was just wondering if there was any reason for not wanting this, given you asked :)
So, go ahead! The plan makes sense to me.

@garazdawi
Copy link
Contributor Author

I am very convinced! I was just wondering if there was any reason for not wanting this, given you asked :)
So, go ahead! The plan makes sense to me.

My main concern was that it is a lot of code and might increase maintenance while not providing enough benefit.

Happy to hear that you would like to have this. I'll spend more time on it and get something that can be merged soon(tm).

@garazdawi
Copy link
Contributor Author

Did some more work.

Added documentation lookup for types:
type_els_markdown

Started using edoc chunks (made possible by erlang/otp#2803 in Erlang/OTP 24) for creating docs from edoc:

Before:
before_edoc_markdown

After:
after_edoc_markdown

I haven't added so that you get documentation on completion of types (yet). Any hints you have of what has to be changed in els_completion_provider to make it work would be most welcome.

I also noticed that Elixir already has done this work, though I think my renderer is a bit more correct/complete. So maybe there is an opportunity to share some code in between the projects.

It would have been really neat if you could refer to other files or allow hovering on things within the returned markdown docs so that we could expand the type documentation within the function documentation if the user want that. But it seems like it is not possible.

@garazdawi garazdawi force-pushed the eep-48-markdown branch 5 times, most recently from b352bec to fe65d62 Compare October 5, 2021 07:46
@robertoaloi
Copy link
Member

@garazdawi Let us know when the PR is ready for review!

@garazdawi
Copy link
Contributor Author

Will do. I've added a todo list in the first post so that you can track progress.

@garazdawi
Copy link
Contributor Author

I've given up on fixing it so that emacs works properly. There seems to be some strange bug in lsp-ui that sometimes deletes newlines from code fenced blocks and my emacs debugging skills are not good enough to figure out what is going on. I may submit an issue to them and see if anyone can assist.

The only thing remaining is creating testcases for all the new code (and fixing any bugs I find a long the way).

So, I would say the code is ready for review!

@garazdawi garazdawi marked this pull request as ready for review October 21, 2021 11:17
When there are multiple versions of the same file we sometimes
want to check all of them.
When developing Erlang/OTP all the modules (i.e. lists.erl)
show up at least twice so when looking for the EEP-48 style
docs we should check all of them in prioritization order for
docs and display the first we find.
rebar.config Outdated Show resolved Hide resolved
Copy link
Member

@robertoaloi robertoaloi left a comment

Choose a reason for hiding this comment

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

LGTM (we may found issues later on, but I don't see a problem solving them incrementally).
Only things are support for "-opaque" as H. mentioned and the "missing_spec_all" warning that has been commented out. Otherwise we can merge, unless someone else would like to have an extra review.

@garazdawi
Copy link
Contributor Author

I've added tests for most of the things now and addressed the other issues brought up.

Tests are missing for:

  • Documentation rendering
  • Multiple modules of same name (i.e. when editing the lists module)
  • Rendering documentation for elixir modules

When I get the CI to pass (just need to fix some linting issues) I think we can merge this and I'll try to find some more time to add more tests.

@garazdawi
Copy link
Contributor Author

There we go, CI passed. Feel free to merge when you want to. Or if you have any more comments for things you want me to address.

@@ -156,6 +156,8 @@ editable_range(#{kind := type_application, id := {M, T, _A}, range := Range}) ->
EditToC = EditFromC + length(atom_to_string(T)),
els_protocol:range(#{ from => {FromL, EditFromC}
, to => {FromL, EditToC} });
editable_range(#{kind := type_definition, data := #{ name := Range }}) ->
Copy link
Member

Choose a reason for hiding this comment

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

It can be addressed as a follow-up, but isn't it a bit counterintuitive to have a range under name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

naming is hard :)

@robertoaloi robertoaloi merged commit d975ac7 into erlang-ls:main Oct 27, 2021
@robertoaloi
Copy link
Member

Thanks so much for this @garazdawi ! 🙏

@garazdawi garazdawi deleted the eep-48-markdown branch October 27, 2021 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants