emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/eglot 76d8f49 10/54: Per #50: use completionItem/resolv


From: João Távora
Subject: [elpa] externals/eglot 76d8f49 10/54: Per #50: use completionItem/resolve more abundantly
Date: Thu, 16 Apr 2020 05:31:46 -0400 (EDT)

branch: externals/eglot
commit 76d8f49cd41f394cc602433ba79b5d18a163517f
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Per #50: use  completionItem/resolve more abundantly
    
    It was already used to resolve documentation bits of completions, but
    it can also be useful to resolve snippet templates and such.
    
    To resolve a completion, you need some part of a completion to start
    with.  If it has a :data field exists and the server supports
    :resolveProvider, fetch the new object, otherwise use whatever we had
    already.
    
    * eglot.el (eglot-completion-at-point): Add another local
    function for resolving completions.
---
 eglot.el | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/eglot.el b/eglot.el
index 1f7a396..bce4ee0 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1979,6 +1979,20 @@ is not active."
                              (put-text-property 0 1 'eglot--lsp-item item 
proxy))
                            proxy))
                        items)))))
+           resolved
+           (resolve-maybe
+            ;; Maybe completion/resolve JSON object `lsp-comp' into
+            ;; another JSON object, if at all possible.  Otherwise,
+            ;; just return lsp-comp.
+            (lambda (lsp-comp)
+              (cond (resolved resolved)
+                    ((and (eglot--server-capable :completionProvider
+                                                 :resolveProvider)
+                          (plist-get lsp-comp :data))
+                     (setq resolved
+                           (jsonrpc-request server :completionItem/resolve
+                                            lsp-comp :cancel-on-input t)))
+                    (t lsp-comp))))
            (bounds (bounds-of-thing-at-point 'symbol)))
       (list
        (or (car bounds) (point))
@@ -2021,13 +2035,7 @@ is not active."
        (lambda (proxy)
          (let* ((documentation
                  (let ((lsp-comp (get-text-property 0 'eglot--lsp-item proxy)))
-                   (or (plist-get lsp-comp :documentation)
-                       (and (eglot--server-capable :completionProvider
-                                                   :resolveProvider)
-                            (plist-get
-                             (jsonrpc-request server :completionItem/resolve
-                                              lsp-comp :cancel-on-input t)
-                             :documentation)))))
+                   (plist-get (funcall resolve-maybe lsp-comp) 
:documentation)))
                 (formatted (and documentation
                                 (eglot--format-markup documentation))))
            (when formatted
@@ -2050,13 +2058,15 @@ is not active."
                         insertText
                         textEdit
                         additionalTextEdits)
-             (or (get-text-property 0 'eglot--lsp-item proxy)
-                 ;; When selecting from the *Completions*
-                 ;; buffer, `proxy' won't have any properties.  A
-                 ;; lookup should fix that (github#148)
-                 (get-text-property
-                  0 'eglot--lsp-item
-                  (cl-find proxy (funcall proxies) :test #'string=)))
+             (funcall
+              resolve-maybe
+              (or (get-text-property 0 'eglot--lsp-item proxy)
+                        ;; When selecting from the *Completions*
+                        ;; buffer, `proxy' won't have any properties.
+                        ;; A lookup should fix that (github#148)
+                        (get-text-property
+                         0 'eglot--lsp-item
+                         (cl-find proxy (funcall proxies) :test #'string=))))
            (let ((snippet-fn (and (eql insertTextFormat 2)
                                   (eglot--snippet-expansion-fn))))
              (cond (textEdit



reply via email to

[Prev in Thread] Current Thread [Next in Thread]