branch: externals/eglot
commit 83cd78581758876d55de69431a58cd491afba7f1
Author: Felicián Németh <[email protected]>
Commit: João Távora <[email protected]>
Fix #365: Fix eglot-completion-at-point for multiple matches
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 <[email protected]>
---
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 47286a7..852b65a 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 0447bc8..98fa4d9 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)