Skip to content

Improve hover for function docs#387

Merged
renkun-ken merged 8 commits intoREditorSupport:masterfrom
ManuelHentschel:hover
Mar 12, 2021
Merged

Improve hover for function docs#387
renkun-ken merged 8 commits intoREditorSupport:masterfrom
ManuelHentschel:hover

Conversation

@ManuelHentschel
Copy link
Member

@ManuelHentschel ManuelHentschel commented Mar 9, 2021

This PR tries to improve the quality of function documentation in hovers.

To test:
Hover e.g. over these expressions:

is.character()
is.na()
is.null()

Known issues:
Some special characters (e.g. the quotes in the documentation for is.na) get rendered incorrectly.
(Edit: fixed by specifying the encoding to be utf-8)

@renkun-ken
Copy link
Member

renkun-ken commented Mar 10, 2021

Thanks for the work! The hover help looks much better.

I did some minor updates to the code to make it consistent with other usages in languageserver.

One issue I'm curious about is that it might be a bit heavy that we need to import rmarkdown which relies on pandoc to do the work. Do we already depend on it?

@renkun-ken
Copy link
Member

I add a check rmarkdown::pandoc_available() to ensure that pandoc is available. If pandoc could be optional, then there might be no point to hard depend on rmarkdown anyway?

R/workspace.R Outdated
# enc2utf8(repr::repr_text(hfile))
html <- enc2utf8(repr::repr_html(hfile))
html_to_markdown(html)
md <- html_to_markdown(html)
Copy link
Member

@randy3k randy3k Mar 10, 2021

Choose a reason for hiding this comment

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

As html_to_markdown could be quite heavy, shall we cache the markdown results (at least per session)?

Copy link
Member

Choose a reason for hiding this comment

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

Agree. A simple dict to cache help results should be working.

@ManuelHentschel
Copy link
Member Author

One issue I'm curious about is that it might be a bit heavy that we need to import rmarkdown which relies on pandoc to do the work. Do we already depend on it?

If pandoc could be optional, then there might be no point to hard depend on rmarkdown anyway?

I guess moving rmarkdwon to Suggests: and checking if it's installed before calling rmarkdown::pandoc_available() should work. If either of the checks fails we can still fall back to the old behaviour using repr::repr_text.

Copy link
Member

@renkun-ken renkun-ken left a comment

Choose a reason for hiding this comment

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

LGTM

@renkun-ken renkun-ken merged commit 097aebd into REditorSupport:master Mar 12, 2021
@renkun-ken
Copy link
Member

@ManuelHentschel Just notice that gfm markdown format is not built-in by lower version of pandoc (e.g. pandoc 1.19.2.4 installed from official repo of Ubuntu 18.04).

Although the spec says it should follow gfm, I tried commonmark and markdown_strict and the output looks mostly the same.

Do we check the version of pandoc via rmarkdown::pandoc_version() and conditionally use gfm or commonmark? I'm not sure which version starts to build in gfm format.

@renkun-ken
Copy link
Member

From the release notes of pandoc:

New input format gfm (GitHub-flavored CommonMark) (#3841). This uses bindings to GitHub’s fork of cmark. markdown_github has been deprecated in favor of gfm.

I guess we might need to use markdown_github for pandoc < 2.0 and gfm for pandoc >= 2.0.

@renkun-ken
Copy link
Member

Fixed via 5f1d88e.

@ManuelHentschel ManuelHentschel deleted the hover branch March 12, 2021 11:42
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