From 83cd78581758876d55de69431a58cd491afba7f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felici=C3=A1n=20N=C3=A9meth?= Date: Sat, 11 Jan 2020 20:12:26 +0100 Subject: [PATCH] Fix #365: Fix eglot-completion-at-point for multiple matches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test-completion case shouldn't return t when there are multiple matches. Similarly, the try-completion should return t only if the match is exact. See (info "(elisp)Programmed Completion"). * eglot.el (eglot-completion-at-point): Instead of testing memberships, use test-completion and try-completion suggested by (info "(elisp)Programmed Completion"). * eglot-tests.el (non-unique-completions): Add new test. Co-authored-by: João Távora --- eglot-tests.el | 17 +++++++++++++++++ eglot.el | 6 +++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/eglot-tests.el b/eglot-tests.el index 47286a73..852b65a2 100644 --- a/eglot-tests.el +++ b/eglot-tests.el @@ -502,6 +502,23 @@ Pass TIMEOUT to `eglot--with-timeout'." (completion-at-point) (should (looking-back "sys.exit"))))) +(ert-deftest non-unique-completions () + "Test completion resulting in 'Complete, but not unique'" + (skip-unless (executable-find "pyls")) + (eglot--with-fixture + '(("project" . (("something.py" . "foo=1\nfoobar=2\nfoo")))) + (with-current-buffer + (eglot--find-file-noselect "project/something.py") + (should (eglot--tests-connect)) + (goto-char (point-max)) + (completion-at-point)) + ;; FIXME: `current-message' doesn't work here :-( + (with-current-buffer (messages-buffer) + (save-excursion + (goto-char (point-max)) + (forward-line -1) + (should (looking-at "Complete, but not unique")))))) + (ert-deftest basic-xref () "Test basic xref functionality in a python LSP" (skip-unless (executable-find "pyls")) diff --git a/eglot.el b/eglot.el index 0447bc85..98fa4d9a 100644 --- a/eglot.el +++ b/eglot.el @@ -2154,10 +2154,10 @@ is not active." (cond ((eq action 'metadata) metadata) ; metadata ((eq action 'lambda) ; test-completion - (member probe (funcall proxies))) + (test-completion probe (funcall proxies))) ((eq (car-safe action) 'boundaries) nil) ; boundaries - ((and (null action) ; try-completion - (member probe (funcall proxies)) t)) + ((null action) ; try-completion + (try-completion probe (funcall proxies))) ((eq action t) ; all-completions (cl-remove-if-not (lambda (proxy)