]> git.eshelyaron.com Git - emacs.git/commitdiff
Eglot: ensure quick typing doesn't undermine completion exit
authorJoão Távora <joaotavora@gmail.com>
Fri, 20 Dec 2024 23:11:30 +0000 (23:11 +0000)
committerEshel Yaron <me@eshelyaron.com>
Mon, 23 Dec 2024 15:18:51 +0000 (16:18 +0100)
Some completion resolution requests in
eglot-completion-at-point, specifically those that might be
triggered from the :exit function, can't be cancellable, else
the completion edit or snippet will never be obtained and the
user is left with the nonsensical completion label in the
buffer.

Github-reference: https://github.com/joaotavora/eglot/issues/1474
(cherry picked from commit b71ddaf6d3ac39487302fbc27614b9de28bf6cef)

lisp/progmodes/eglot.el

index 66ee2749b51b017a21e63515a02996d4b1a48a02..801d60885f576421759ea08b429ec3ca97bd2a18 100644 (file)
@@ -3267,14 +3267,15 @@ for which LSP on-type-formatting should be requested."
             ;; Maybe completion/resolve JSON object `lsp-comp' into
             ;; another JSON object, if at all possible.  Otherwise,
             ;; just return lsp-comp.
-            (lambda (lsp-comp)
+            (lambda (lsp-comp &optional dont-cancel-on-input)
               (or (gethash lsp-comp resolved)
                   (setf (gethash lsp-comp resolved)
                         (if (and (eglot-server-capable :completionProvider
                                                         :resolveProvider)
                                  (plist-get lsp-comp :data))
                             (eglot--request server :completionItem/resolve
-                                            lsp-comp :cancel-on-input t
+                                            lsp-comp :cancel-on-input
+                                            (not dont-cancel-on-input)
                                             :immediate t)
                           lsp-comp))))))
       (when (and (consp eglot--capf-session)
@@ -3389,7 +3390,12 @@ for which LSP on-type-formatting should be requested."
                       ;; A lookup should fix that (github#148)
                       (get-text-property
                        0 'eglot--lsp-item
-                       (cl-find proxy (funcall proxies) :test #'string=))))
+                       (cl-find proxy (funcall proxies) :test #'string=)))
+                  ;; Be sure to pass non-nil here since we don't want
+                  ;; any quick typing after the soon-to-be-undone
+                  ;; insertion to potentially cancel an essential
+                  ;; resolution request (github#1474).
+                  'dont-cancel-on-input)
                (let ((snippet-fn (and (eql insertTextFormat 2)
                                       (eglot--snippet-expansion-fn))))
                  (cond (textEdit