From 00b6fe68e18a84bd6a9f8b0a771435dedf07d7cd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Fri, 20 Dec 2024 23:11:30 +0000 Subject: [PATCH] Eglot: ensure quick typing doesn't undermine completion exit 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 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 66ee2749b51..801d60885f5 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -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 -- 2.39.5