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

lsp-ui-doc--extract renders content kind=markdown as plaintext #193

Open
cpbotha opened this Issue Nov 20, 2018 · 10 comments

Comments

Projects
None yet
4 participants
@cpbotha
Contributor

cpbotha commented Nov 20, 2018

lsp-ui-doc--extract returns kind=markdown contents as plaintext, while there is great support for showing markdown.

See for example the screenshot below:

lsp-mode-displays-markdown-hover-as-plain

This hover text is returned by the Microsoft Python Language Server (same one as for visual studio code). Two issues: 1. All of those   entities (I have also logged Microsoft/python-language-server#422 for this) and 2. Emacs is not displaying the markdown.

I was able to fix both issues by modifying lsp-ui-doc--extract as follows:

(defun lsp-ui-doc--extract (contents)
  "Extract the documentation from CONTENTS.
CONTENTS can be differents type of values:
MarkedString | MarkedString[] | MarkupContent (as defined in the LSP).
We don't extract the string that `lps-line' is already displaying."
  (when contents
    (cond
     ((stringp contents) contents)
     ((sequencep contents) ;; MarkedString[]
      (mapconcat 'lsp-ui-doc--extract-marked-string
                 (lsp-ui-doc--filter-marked-string contents)
                 "\n\n"
                 ;; (propertize "\n\n" 'face '(:height 0.4))
                 ))

     ;; cpbotha: with numpy functions, e.g. np.array for example, kind=markdown
     ;; and docs are in markdown, but in default lsp-ui-20181031 this is rendered as plaintext
     ;; see https://microsoft.github.io/language-server-protocol/specificatoin#markupcontent
     ;; not only that, MS PyLS turns all spaces into   instances, which we remove here
     ;; this single additional cond clause fixes all of this for hover
     ;; as if that was not enough: import pandas as pd - pandas is returned with kind plaintext
     ;; but contents markdown, whereas pd is returned with kind markdown. fortunately,
     ;; handling plaintext with the markdown viewer still looks good, so here we are.
     ((member (gethash "kind" contents) '("markdown" "plaintext"))
      (replace-regexp-in-string " " " " (lsp-ui-doc--extract-marked-string contents)))
     
     ((gethash "kind" contents) (gethash "value" contents)) ;; MarkupContent
     ((gethash "language" contents) ;; MarkedString
      (lsp-ui-doc--extract-marked-string contents)))))

You'll see that I'm sending both markdown and plaintext to the markdown handler. One could decide to only do this for markdown. Anyways, after applying this change, hover looks like:

emacs-ms-lsp-docbox-and-describe-term

Making this change would probably fix issue #172 also.

@yyoncho

This comment has been minimized.

Member

yyoncho commented Nov 22, 2018

From what I can see, you have fixed the issue, willing to provide a PR?

@seanfarley

This comment has been minimized.

seanfarley commented Nov 29, 2018

I tried this code and found that functions that begin with an _ are escaped by \_. Is that a Microsoft LSP server thing or something that the markdown renderer should take care of?

@yyoncho yyoncho referenced this issue Dec 3, 2018

Closed

^M in doc frame #196

@astenman

This comment has been minimized.

astenman commented Dec 3, 2018

I am not sure that this fix solves my ^M issue in #196 (it rather fixes the   issue), but if it does I am happy with that.

@cpbotha

This comment has been minimized.

Contributor

cpbotha commented Dec 3, 2018

@yyoncho I'll prepare that PR and get back to you here. Thanks!

It does not look like the MS PyLSP devs want to get rid of the   entities their server generates (see discussion on Microsoft/python-language-server#422 ), so we're going to have to care of them on the Emacs side.

@yyoncho

This comment has been minimized.

Member

yyoncho commented Dec 4, 2018

@astenman I believe emacs itself could be configured to ignore ^M - https://stackoverflow.com/questions/730751/hiding-m-in-emacs/750933 .

@cpbotha

This comment has been minimized.

Contributor

cpbotha commented Dec 4, 2018

@yyoncho Here is the PR: #198

I've kept it as minimal as possible, just fixing the bug that markdown was being rendered as plaintext.

We are working on a separate MS PyLS Emacs package that will fix the rest of the   issues: https://github.com/andrew-christianson/lsp-python-ms

@astenman

This comment has been minimized.

astenman commented Dec 4, 2018

@astenman I believe emacs itself could be configured to ignore ^M - https://stackoverflow.com/questions/730751/hiding-m-in-emacs/750933 .

OK. I will have to solve it myself then.

Would it be possible to add a hook/filter that the user could use to filter the message?

@cpbotha

This comment has been minimized.

Contributor

cpbotha commented Dec 4, 2018

@astenman Please try adding your ^M to the lsp-python-ms--filter-nbsp defun in the new https://github.com/andrew-christianson/lsp-python-ms package.

If it works, consider doing a PR. @andrew-christianson and I will hopefully soon have this in MELPA.

@yyoncho

This comment has been minimized.

Member

yyoncho commented Dec 4, 2018

@cpbotha @andrew-christianson please take a look at emacs-lsp/lsp-mode#479 regarding lsp-python-ms.

@yyoncho

This comment has been minimized.

Member

yyoncho commented Dec 4, 2018

@cpbotha is this issue resolved?

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