Subject: bug#72705: 31.0.50; eglot--dumb-tryc Filters out too much

From: Dmitry Gutov <[email-masked]>
Date: Sun, 25 Aug 2024 18:56:06 +0300

On 25/08/2024 12:53, João Távora wrote:
> Dmitry Gutov <[email-masked]> writes:
> 
>> On 23/08/2024 13:23, João Távora wrote:
>>
>> I see what you're saying, but insofar that current completion is
>> mostly working out well, adding the special logic for parens would
>> improve a lot of cases, and keep others the same degree of broken (the
>> email-sending ones, for sure). So it might be worth a try.
> 
> No, it's not.  It's the kind of complexity Eglot isn't after.  It's a
> losing game with the growing number of servers who aren't bound by these
> rules in any way.
> 
>> Anyway, stopping any partial completion (at first I didn't understand
>> that you meant a more general notion that the partial-completion
>> c-style) should be similarly easy to what the current patch does. You
>> would just drop the second clause in eglot--dumb-tryc, I think. Or
>> maybe both the first and the second.
> 
> If it's easy, then we should definitely do it.

The corresponding change probably looks like this:

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 844fc634be9..fcf4e586ead 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -3147,20 +3147,10 @@ eglot--dumb-flex

  (defun eglot--dumb-allc (pat table pred _point) (funcall table pat 
pred t))
  (defun eglot--dumb-tryc (pat table pred point)
-  (let ((probe (funcall table pat pred nil)))
-    (cond ((eq probe t) t)
-          (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))))))
+  ;; 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))

But I'd prefer to hold off on it until specific issues come up.

>> This works:
>>
>>    (when (buffer-live-p "*Completions*")
>>      (kill-buffer "*Completions*"))
>>    (completion-at-point)
>>    (should (looking-back "foo"))
>>    (should (looking-at "123"))
>>    (should (get-buffer "*Completions*"))
>>
>> Is that better?
> 
> It's half-decent, I think.  Please use that.

Okay.

>> 1) Completions are not filtered by suffix, ever.
>> 2) Completing count_ones() does not delete the suffix ("1234"
>> remains).
> 
> Interesting, I thought deleting the 1234 was part of the edit, but the
> user of that bug report was after some Emacs specific behaviour.
> Anyway, I don't think the test is too brittle, and I think I'd like to
> know anyway if something about that breaks anyway.  Maybe you can just
> add a comment saying ";; this test might be a bit too brittle, but
> interesting nonetheless".

Pushed to emacs-30 as two parts: new tests for existing behavior and the 
fix with its own tests (096730510cd, 713069dd7a8).