-
Notifications
You must be signed in to change notification settings - Fork 200
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
Fix wrong-type-argument when MarkedString is a plist #72
Conversation
* eglot.el (eglot--hover-info): Handle the case when contents is neither a vector nor a string.
@@ -1353,8 +1353,7 @@ is not active." | |||
(let ((heading (and range (pcase-let ((`(,beg . ,end) (eglot--range-region range))) | |||
(concat (buffer-substring beg end) ": ")))) | |||
(body (mapconcat #'eglot--format-markup | |||
(append (cond ((vectorp contents) contents) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't solve the issue completely as contents can be strings, vectors or plist. The plist itself can be of two types: MarkedString with language and MarkupContent. Also, according to the LSP docs, MarkedString is deprecated for hover response.
I think a correct solution would be something like
(defun eglot--parse-hover-contents (contents)
"Doc."
(cond
;; string
((stringp contents) (eglot--format-markup contents))
;; MarkedString[]
((vectorp contents) (mapconcat #'eglot--parse-hover-contents contents "\n"))
((listp contents)
(if (plist-get contents :language)
;; MarkedString
(eglot--format-markup contents)
;; MarkupContent
(eglot--format-markup (plist-get contents :value))))))
(let ((heading ...)
(body (eglot--parse-hover-contents contents))
This is untested, but in concept it should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think it will work just because MarkedString
(when it's a plist) and MarkupContent
both have a :value
key and eglot--format-buffer
will silently handle an error in case it's argument is a MarkupContent
and has no :language
key. We should also handle MarkupContent
's :kind
though, but that's another issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can also merge it with eglot--format-markup to simplify the implementation and support all kinds of documentation easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @mkcms. eglot--format-markup
could see a clarification of the accepted datatypes in the docstring though, and indeed is the place where full support for MarkupContent
should be implemented.
Pushed with a tweak to the commit message |
* eglot.el (eglot--hover-info): Forward all non-vector content to eglot--format-markup. (#72: joaotavora/eglot#72
* eglot.el (eglot--hover-info): Forward all non-vector content to eglot--format-markup. GitHub-reference: joaotavora/eglot#72
In
eglot--hover-info
we weren't handling the case when MarkedString is a plist. This leads towrong-type-argument
, e.g when a class has no documentation and we calleglot-help-at-point
when using eclipse.jdt.ls.