From 72712e5aed3716aae1e66930e8e899f12e85c5af Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Mon, 7 May 2018 18:45:57 +0100 Subject: [PATCH] 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 --- lisp/progmodes/eglot.el | 42 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 3bed8d9344f..2c97f2ff48e 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/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 ;;; -- 2.39.2