Skip to content

Commit

Permalink
Fix joaotavora#365: Fix eglot-completion-at-point for multiple matches
Browse files Browse the repository at this point in the history
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 <joaotavora@gmail.com>
  • Loading branch information
nemethf and joaotavora committed Jan 16, 2021
1 parent 8761f86 commit 83cd785
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
17 changes: 17 additions & 0 deletions eglot-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
6 changes: 3 additions & 3 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 83cd785

Please sign in to comment.