Subject: bug#72705: closed (Re: bug#72705: 31.0.50; eglot--dumb-tryc Filters out too much)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 25 Aug 2024 23:42:02 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
72705: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=72705
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#72705: 31.0.50; eglot--dumb-tryc Filters out too much
From: Dmitry Gutov <[email-masked]>
To: João Távora <[email-masked]>
Cc: [email-masked]
Date: Mon, 26 Aug 2024 02:40:34 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

On 25/08/2024 12:53, João Távora wrote:
>>>> Okay, I am seeing a difference too: C-M-i does eat the suffix in the
>>>> Rust example (the "1234"). But completion with Company does not :-/
>>> I can't even get Company to appear in those situations.
>> You might have an older version installed?
> Maybe.

Okay, I've tracked this one down to Company adhering to what completion 
style is being used.

When no completions match the suffix, completion-all-completions falls 
back to c-style 'emacs22' (if it's in completion-styles anyway). And 
when that style is used, we don't replace the suffix. There is a report 
for vanilla completion in bug#70968.

That seems to cover all related issues I've found so far.

Thanks, and closing.

Subject: 31.0.50; eglot--dumb-tryc Filters out too much
From: Dmitry Gutov <[email-masked]>
To: [email-masked]
Date: Mon, 19 Aug 2024 04:51:15 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

X-Debbugs-Cc: [email-masked]

1. Have a project with just one file, test.go (attached).
2. Visit it, enable go-ts-mode, call 'M-x eglot'.
3. Move point right after "math.As", press C-M-i.
4. Code will get completed to "math.Asin"

This is a problem because "math.As" has more completions (one can look
at them by pressing TAB after "math.A") - such as "Acos", "Acosh" and
"Abs" - in other words, "fuzzy" matches.

Expected behavior:

1. When input is "math.As" - keep the string as-is.
2. When input is "math.Asi" - complete to "math.Asin".

This problem seems older than 65ea742ed5ec (the change that introduced
eglot--dumb-tryc itself, bug#68699), but it doesn't reproduce with Eglot
from Emacs 29. Branches emacs-30 and master are affected.

There is also another issue there: when there are no completions at all,
this style still has completion-try-completion return a non-nil value
(the last line of the implementation).

Both of these issues is something I came across when working on closer
'try-completion' integration for company-mode
(https://github.com/company-mode/company-mode/pull/1488) and testing out
the new code with Eglot.

Not sure what's the best fix, but the patch below seems to address both
problems in my limited testing. WDYT?

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 353877f60c2..e8823a9d2f0 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -3142,8 +3142,14 @@ eglot--dumb-allc
  (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)))))
+          ((and probe
+                (cl-every
+                 (lambda (s) (string-prefix-p probe s 
completion-ignore-case))
+                 (funcall table pat pred t)))
+           (cons probe (length probe)))
+          (t
+           (and (funcall table pat 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))