From: Dmitry Gutov Date: Sun, 25 Aug 2024 15:23:51 +0000 (+0300) Subject: [Eglot] Stricter "expand common" behavior X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e69902e605ac29aed8ebfae98be24d7d80bb59bf;p=emacs.git [Eglot] Stricter "expand common" behavior * lisp/progmodes/eglot.el (eglot--dumb-tryc): Check that the expanded string matches every completion strictly (bug#72705). And in the fallback case, check whether the table matches the original prefix at all. Return nil otherwise. * test/lisp/progmodes/eglot-tests.el (eglot-test-stop-completion-on-nonprefix) (eglot-test-try-completion-nomatch): Corresponding tests. * etc/EGLOT-NEWS: New entry. (cherry picked from commit 713069dd7a87cff8388c25f1bc2c2c1b5217b1ca) --- diff --git a/etc/EGLOT-NEWS b/etc/EGLOT-NEWS index 0e3e4b7aff8..04b1a59c0be 100644 --- a/etc/EGLOT-NEWS +++ b/etc/EGLOT-NEWS @@ -26,6 +26,36 @@ Eglot will now try to not register $/progress messages from the server when the defcustom is set to nil. This requires a restart of the server for the change to take effect. +** LSP MarkedString interface is now supported (bug#71353) + +Some servers still use this deprecated interface for communicating +documentation snippets. + +** Fixes to completion logic (bug#68699, github#1339, github#1349) + +These affect mostly the "vanilla" frontend to completions (invoked with +C-M-i). + +** More strict completion expansion (bug#72705). + +It ensures that "expand common" commands (such as C-M-i or TAB in +third-party frontends) don't result in fewer completions than before +they are called. + +** Experimental support for Eglot-only subprojects (github#1337) + +Useful for complex projects with subprojects needing different language +servers. See associated github issue +https://github.com/joaotavora/eglot/discussions/1337 for examples. + +** New servers have been added to 'eglot-server-programs'. + +- blueprint (bug#70015) +- BasedPyright (bug#69925) +- move-analyzer (bug#69796) +- millet +- nushell (bug#68823) + * Changes in Eglot 1.17 (25/1/2024) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index f13470260ea..39f2421ba58 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -3194,8 +3194,18 @@ for which LSP on-type-formatting should be requested." (defun eglot--dumb-tryc (pat table pred point) (let ((probe (funcall table pat pred nil))) (cond ((eq probe t) t) - (probe (cons probe (length probe))) - (t (cons pat point))))) + (probe + (if (and (not (equal probe pat)) + (cl-every + (lambda (s) (string-prefix-p probe s completion-ignore-case)) + (funcall table pat pred t))) + (cons probe (length probe)) + (cons pat point))) + (t + ;; Match ignoring suffix: if there are any completions for + ;; the current prefix at least, keep the current input. + (and (funcall table (substring pat 0 point) pred t) + (cons pat point)))))) (add-to-list 'completion-category-defaults '(eglot-capf (styles eglot--dumb-flex))) (add-to-list 'completion-styles-alist '(eglot--dumb-flex eglot--dumb-tryc eglot--dumb-allc)) diff --git a/test/lisp/progmodes/eglot-tests.el b/test/lisp/progmodes/eglot-tests.el index 746b8470111..c0e30172482 100644 --- a/test/lisp/progmodes/eglot-tests.el +++ b/test/lisp/progmodes/eglot-tests.el @@ -645,6 +645,36 @@ directory hierarchy." (forward-line -1) (should (looking-at "Complete, but not unique"))))))) +(ert-deftest eglot-test-stop-completion-on-nonprefix () + "Test completion also resulting in 'Complete, but not unique'." + (skip-unless (executable-find "clangd")) + (eglot--with-fixture + `(("project" . (("coiso.c" . + ,(concat "int foot; int footer; int fo_obar;" + "int main() {foo"))))) + (with-current-buffer + (eglot--find-file-noselect "project/coiso.c") + (eglot--wait-for-clangd) + (goto-char (point-max)) + (completion-at-point) + (should (looking-back "foo"))))) + +(ert-deftest eglot-test-try-completion-nomatch () + "Test completion table with non-matching input, returning nil." + (skip-unless (executable-find "clangd")) + (eglot--with-fixture + `(("project" . (("coiso.c" . + ,(concat "int main() {abc"))))) + (with-current-buffer + (eglot--find-file-noselect "project/coiso.c") + (eglot--wait-for-clangd) + (goto-char (point-max)) + (should + (null + (completion-try-completion + "abc" + (nth 2 (eglot-completion-at-point)) nil 3)))))) + (ert-deftest eglot-test-try-completion-inside-symbol () "Test completion table inside symbol, with only prefix matching." (skip-unless (executable-find "clangd"))