unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Brennan Vincent <brennan@umanwizard.com>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 68699@debbugs.gnu.org
Subject: bug#68699: Eglot completion has stopped working in some cases
Date: Thu, 25 Jan 2024 01:35:08 +0000	[thread overview]
Message-ID: <CALDnm50kXAofuhk0uWJod301TkY882OY3AQcE+G1sxw86Q-8tA@mail.gmail.com> (raw)
In-Reply-To: <CALDnm514mmFo7pF1J2ovGR6L8-AU6O=1FVzbN5czmR8nm36gNA@mail.gmail.com>

On Thu, Jan 25, 2024 at 12:43 AM João Távora <joaotavora@gmail.com> wrote:
>
> On Wed, Jan 24, 2024 at 8:37 PM Brennan Vincent <brennan@umanwizard.com> wrote:
>
> > For example, in a Rust crate with the following main file:
> >
> > fn foo_len() {
> > }
> >
> > fn main() {
> >     len
> > }
>
> I've reproduced this with latest master:
>
> ~/Source/Emacs/emacs/src/emacs -Q ~/MoreSource/Rust/hello/src/main.rs
> -f rust-ts-mode -f eglot
>
> where main.rs is the provided snippet.
>
> Pressing C-M-i with point after 'len' yields the error.
>
> The error only happens in partial-completion is in the completion-styles
> variable, so a workaround is to remove partial-completion from
> completion-styles, at least in Eglot enabled buffers.
>
> I will look now for the underlying cause.

Stefan, this is down to partial-completion somehow thinking
that "\\'len" should match at least some LSP-provided
completion candidate, otherwise it's an "internal error"

I wish I could turn off all the styles from the table but I can
only add to them.  I simply cannot write a reasonable
try-completion thing for LSP completions.  LSP completions
are really designed to be navigated using a company-like
popup.  Without it they should almost always use the *Completions*
buffer, and rarely ever Emacs partial completion shenanigans.

Nevertheless, I need to plug this bug somehow in Eglot.

Brennan, can you try this patch I've just pushed?

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 511000927cf..c5fbf5eb9d5 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -3060,9 +3060,13 @@ eglot--dumb-flex
            finally (cl-return comp)))

 (defun eglot--dumb-allc (pat table pred _point) (funcall table pat pred t))
+(defun eglot--dumb-tryc (pat table pred point)
+  (if-let ((probe (funcall table pat pred nil)))
+      (cons probe (length probe))
+    (cons pat point)))

 (add-to-list 'completion-category-defaults '(eglot-capf (styles
eglot--dumb-flex)))
-(add-to-list 'completion-styles-alist '(eglot--dumb-flex ignore
eglot--dumb-allc))
+(add-to-list 'completion-styles-alist '(eglot--dumb-flex
eglot--dumb-tryc eglot--dumb-allc))

 (defun eglot-completion-at-point ()
   "Eglot's `completion-at-point' function."

João





  reply	other threads:[~2024-01-25  1:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-24 20:37 bug#68699: Eglot completion has stopped working in some cases Brennan Vincent
2024-01-24 20:41 ` João Távora
2024-01-25  0:43 ` João Távora
2024-01-25  1:35   ` João Távora [this message]
2024-01-25 15:34     ` Brennan Vincent
2024-01-25 19:11       ` João Távora

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALDnm50kXAofuhk0uWJod301TkY882OY3AQcE+G1sxw86Q-8tA@mail.gmail.com \
    --to=joaotavora@gmail.com \
    --cc=68699@debbugs.gnu.org \
    --cc=brennan@umanwizard.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).