branch: externals/eglot commit 714e5be3080d5bef55e5b3143d3d1d3dd593a508 Author: João Távora <joaotav...@gmail.com> Commit: João Távora <joaotav...@gmail.com>
Half-baked textDocument/hover support * eglot.el (eglot--format-markup): New helper. (eglot--managed-mode): Handle eldoc-documentation-function. (eglot-eldoc-function): New function. * README.md: update --- README.md | 2 +- eglot.el | 42 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f70d15f..611839b 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ server. To skip the guess and always be prompted use `C-u M-x eglot`. - [ ] textDocument/documentSymbol - [ ] textDocument/executeCommand - [ ] textDocument/format -- [ ] textDocument/hover +- [x] textDocument/hover - [ ] textDocument/rename - [x] textDocument/references - [ ] textDocument/signatureHelp diff --git a/eglot.el b/eglot.el index 3bed8d9..2c97f2f 100644 --- a/eglot.el +++ b/eglot.el @@ -772,6 +772,23 @@ Meaning only return locally if successful, otherwise exit non-locally." (13 . "Enum") (14 . "Keyword") (15 . "Snippet") (16 . "Color") (17 . "File") (18 . "Reference"))) +(defun eglot--format-markup (markup) + "Format MARKUP according to LSP's spec." + (cond ((stringp markup) + (with-temp-buffer + (ignore-errors (funcall 'markdown-mode)) + (font-lock-ensure) + (insert markup) + (string-trim (buffer-string)))) + (t + (with-temp-buffer + (ignore-errors (funcall (intern (concat + (plist-get markup :language) + "-mode" )))) + (insert (plist-get markup :value)) + (font-lock-ensure) + (buffer-string))))) + ;;; Minor modes ;;; @@ -796,7 +813,10 @@ Meaning only return locally if successful, otherwise exit non-locally." (add-hook 'after-save-hook 'eglot--signal-textDocument/didSave nil t) (add-hook 'xref-backend-functions 'eglot-xref-backend nil t) (add-hook 'completion-at-point-functions #'eglot-completion-at-point nil t) - (flymake-mode 1)) + (add-function :before-until (local 'eldoc-documentation-function) + #'eglot-eldoc-function) + (flymake-mode 1) + (eldoc-mode 1)) (t (remove-hook 'flymake-diagnostic-functions 'eglot-flymake-backend t) (remove-hook 'after-change-functions 'eglot--after-change t) @@ -806,7 +826,9 @@ Meaning only return locally if successful, otherwise exit non-locally." (remove-hook 'before-save-hook 'eglot--signal-textDocument/willSave t) (remove-hook 'after-save-hook 'eglot--signal-textDocument/didSave t) (remove-hook 'xref-backend-functions 'eglot-xref-backend t) - (remove-hook 'completion-at-point-functions #'eglot-completion-at-point t)))) + (remove-hook 'completion-at-point-functions #'eglot-completion-at-point t) + (remove-function (local 'eldoc-documentation-function) + #'eglot-eldoc-function)))) (define-minor-mode eglot-mode "Minor mode for all buffers managed by EGLOT in some way." nil @@ -1410,6 +1432,22 @@ DUMMY is ignored" (get-text-property 0 :sortText a) (get-text-property 0 :sortText b))))))))) +(defun eglot-eldoc-function () + "EGLOT's `eldoc-documentation-function' function." + (eglot--request (eglot--current-process-or-lose) + :textDocument/hover + (eglot--obj + :textDocument (eglot--current-buffer-TextDocumentIdentifier) + :position (eglot--pos-to-lsp-position)) + :success-fn (eglot--lambda (&key contents _range) + (eldoc-message + (mapconcat #'eglot--format + (if (vectorp contents) + contents + (list contents)) + "\n")))) + nil) + ;;; Dynamic registration ;;;