branch: externals/ivy commit 078dcc713e088cb959af549cbd00f2267deb175a Author: Basil L. Contovounesios <ba...@contovou.net> Commit: Basil L. Contovounesios <ba...@contovou.net>
Fix Eglot completion The recent changes to ivy-completion-in-region fixed some cases but broke the base-size calculation for Eglot, which doesn't seem to compute field boundaries. Either way, the result is that completion-all-completions does not include a base-size, its candidates do not bear a completions-first-difference, and completion-try-completion returns a cons even for no/sole match. * ivy.el (ivy-completion-in-region): Take lack of base-size as covering the whole completion string. This is consistent with completion-boundaries and other minibuffer.el functions. Remove resulting dead code. If completion-try-completion returns a cons, try detecting no/sole match from completion-all-completions instead. This avoids an error when calling ivy-completion-in-region-action on an empty list of candidates in the no match case, avoids erasing and reinserting a sole match, and in both cases ensures a message is printed to the user. (ivy-completion-common-length): Mark as obsolete since it is no longer used and shouldn't be relied on. * ivy-test.el (ivy-completion-common-length): Silence resulting warnings. Fixes #3068. Re: #1361. --- ivy-test.el | 3 ++- ivy.el | 28 ++++++++-------------------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/ivy-test.el b/ivy-test.el index f850bbe736..5cb8de007d 100644 --- a/ivy-test.el +++ b/ivy-test.el @@ -1010,7 +1010,8 @@ Since `execute-kbd-macro' doesn't pick up a let-bound `default-directory'.") (mapc (lambda (pair) (dolist (str (cdr pair)) (ert-info ((format "%S" str) :prefix "String: ") - (should (= (ivy-completion-common-length str) (car pair)))))) + (should (= (with-no-warnings (ivy-completion-common-length str)) + (car pair)))))) '((0 "" #("a" 0 1 (face completions-first-difference)) #("ab" 0 1 (face completions-first-difference)) diff --git a/ivy.el b/ivy.el index 4c8e9d92cb..35cbcfe067 100644 --- a/ivy.el +++ b/ivy.el @@ -2668,6 +2668,7 @@ Typically the completion-matching parts of STR have previously been propertized by `completion-all-completions', but then the base-size returned by that function should be preferred over `ivy-completion-common-length'." + (declare (obsolete "it is no longer used." "0.15.1")) (let* ((char-property-alias-alist '((face font-lock-face))) (cmn (length str)) (i cmn)) @@ -2693,16 +2694,18 @@ See `completion-in-region' for further information." (try (completion-try-completion str collection predicate reg md)) (comps (completion-all-completions str collection predicate reg md)) (last (last comps)) - (base-size (cdr last)) + (base-size (or (cdr last) 0)) (ivy--minibuffer-table collection) (ivy--minibuffer-pred predicate)) (when last (setcdr last ())) - (cond ((not try) + ;; For no/sole match: + ;; give priority to boolean `try', falling back on `comps'. + (cond ((not (and try (or (eq try t) comps))) (and (not completion-fail-discreetly) completion-show-inline-help (minibuffer-message "No matches")) nil) - ((eq try t) + ((and try (or (eq try t) (equal (list str) comps))) (goto-char end) (let ((minibuffer-completion-table collection) (minibuffer-completion-predicate predicate)) @@ -2711,23 +2714,8 @@ See `completion-in-region' for further information." (t (when (eq collection 'crm--collection-fn) (setq comps (delete-dups comps))) - (let* ((cmn (ivy-completion-common-length (car comps))) - ;; Translate a 'not found' result to 0. Do this here (instead - ;; of fixing `ivy-completion-common-length') for backward - ;; compatibility, since it's a potentially public function. - (cmn (if (= cmn (length (car comps))) 0 cmn)) - (initial (cond (base-size (substring str base-size)) - ;; The remaining clauses should hopefully never - ;; be taken, since they rely on - ;; `ivy-completion-common-length'. - ((= cmn 0) - "") - ((>= cmn reg) - (setq cmn reg) - str) - (t - (substring str (- cmn))))) - (base-pos (if base-size (+ start base-size) (- end cmn)))) + (let ((initial (substring str base-size)) + (base-pos (+ start base-size))) (delete-region base-pos end) (setq ivy-completion-beg base-pos) (setq ivy-completion-end ivy-completion-beg)