From 4dcbf61c1518dc53061707aeff8887517e050003 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=C3=A3o=20T=C3=A1vora?= Date: Tue, 26 Dec 2023 07:47:29 -0600 Subject: [PATCH] Eglot: Make 'try-completion' less broken The 'try-completion' completion operation, used mostly in vanilla 'completion-at-point' invoked with C-M-i is close to impossible to get right in LSP because of the arbitrary edits handled in ':exit-function'. When this operation is invoked on the table, returning the pattern argument unchanged somehow (TM) makes a sole completion show the *Completions* buffer, where selecting it will recover context necessary for `:exit-function' and call that function. It doesn't break any other cases I know, and that's good enough for now. https://github.com/joaotavora/eglot/issues/1339 * lisp/progmodes/eglot.el (eglot-completion-at-point): Return pattern when 'try-completion' is invoked. --- lisp/progmodes/eglot.el | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index d777e488c43..a97c9e2a3e0 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -3113,8 +3113,8 @@ for which LSP on-type-formatting should be requested." ((eq action 'lambda) ; test-completion (test-completion pattern (funcall proxies))) ((eq (car-safe action) 'boundaries) nil) ; boundaries - ((null action) ; try-completion - (try-completion pattern (funcall proxies))) + ((null action) ; try-completion (github#1339) + pattern) ((eq action t) ; all-completions (let ((comps (funcall proxies))) (dolist (c comps) (eglot--dumb-flex pattern c t)) @@ -3215,7 +3215,8 @@ for which LSP on-type-formatting should be requested." ;; was obtained from server. If a `proxy' ;; "bar" was obtained from a buffer with ;; "foo.b", the LSP edit applies to that - ;; state, _not_ the current "foo.bar". + ;; state, _not_ the current "foo.bar" + ;; (github#1339) (delete-region orig-pos (point)) (insert (substring bounds-string (- orig-pos (car bounds)))) (eglot--dbind ((TextEdit) range newText) textEdit -- 2.39.2