From 572bb298b26715d4451cacd6ac91685fb0d2ddec Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Thu, 10 May 2018 21:56:54 +0100 Subject: [PATCH] Support :completionitem/resolve This is quite handy with company and company-quickhelp * eglot.el (eglot-completion-at-point): Send :completionItem/resolve * README.md: Mention completionItem/resolve --- lisp/progmodes/eglot.el | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 58a2374bbfe..35573034bf7 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1278,23 +1278,35 @@ DUMMY is ignored" :textDocument/completion)) (items (if (vectorp resp) resp (plist-get resp :items)))) (eglot--mapply - (eglot--lambda (&key insertText label kind detail - documentation sortText &allow-other-keys) - (propertize (or insertText label) - :kind-name (cdr (assoc kind eglot--kind-names)) - :detail detail - :documentation documentation :sortText sortText)) + (eglot--lambda (&rest all &key label &allow-other-keys) + (add-text-properties 0 1 all label) label) items)))) :annotation-function - (lambda (what) - (propertize (concat " " (or (get-text-property 0 :detail what) - (get-text-property 0 :kind what))) + (lambda (obj) + (propertize (concat " " (or (get-text-property 0 :detail obj) + (cdr (assoc (get-text-property 0 :kind obj) + eglot--kind-names)))) 'face 'font-lock-function-name-face)) :display-sort-function - (lambda (items) (sort items (lambda (a b) - (string-lessp - (get-text-property 0 :sortText a) - (get-text-property 0 :sortText b))))) + (lambda (items) + (sort items (lambda (a b) + (string-lessp + (or (get-text-property 0 :sortText a) "") + (or (get-text-property 0 :sortText b) ""))))) + :company-doc-buffer + (lambda (obj) + (let ((documentation + (or (get-text-property 0 :documentation obj) + (plist-get (eglot--request proc :completionItem/resolve + (text-properties-at 0 obj)) + :documentation)))) + (when documentation + (with-current-buffer (get-buffer-create " *eglot doc*") + (erase-buffer) + (ignore-errors (funcall (intern "markdown-mode"))) + (font-lock-ensure) + (insert documentation) + (current-buffer))))) :exit-function (lambda (_string _status) (eglot-eldoc-function)))))) -- 2.39.2