unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "João Távora" <joaotavora@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: scratch/backend-completion c807121fbd 1/2: Add lisp/backend-completion.el
Date: Sat, 3 Dec 2022 13:21:04 +0000	[thread overview]
Message-ID: <CALDnm51gxk3pk9JSPrs7EDxMCg-k_hpuiT+7hCf2=12C4NPK2w@mail.gmail.com> (raw)
In-Reply-To: <jwv1qplpc28.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 4200 bytes --]

Hey Stefan,

I just pushed to scratch/backend-completion.

I integrated most of your suggestions and added docstrings.  I'm sure
you'll want to comment and tweak some stuff (some of the
documentation is purposely cheeky and there is also a FIXME
or two.).

I quite like this and it's working well for both Eglot and that other
library.  I haven't tried it with SLY but I'm sure it will do the job
nicely.

One of the most important things though is the naming.
"Backend completion" is not a good name, there are already a ton
of "backend" semantics that are entirely Emacs only, and this new
style is really exclusive for tools _outside_ of Emacs's address
 space.

Let me know what you think, João

On Tue, Nov 29, 2022 at 11:44 PM Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> > OK great.  But where do you plug the current eglot functions into it.
>
> Something like the patch below?
>
> > Maybe.  As I've often told you, all this completion code is hard to
> > grasp.  I do "get" it somewhat, and I've been working with it intensely
> > for a long time.  But also, I don't really get it :-) For example, I
> > have no solid concept of what a category or a style is, so everything
> > just reads like "an indirection from this thing to that other thing".
>
> Some sets of identifiers are designed to play well with prefix
> completion, while others are a very poor fit.
>
> The "category" is a loose way to describe to users what kind of "sets of
> identifiers" this is completing so users can customize the behavior for
> specific cases.
>
> > So I named this thing 'eglot-indirection' . 'eglot-code' may be logical
> > for someone who knows what a category means, now but sounds something
> > that will make absolutely no sense to me 2 weeks from now.
>
> The `category` should be a name that describe the "kind of thing this
> inserts/selects by completion".
>
>
>         Stefan
>
>
> diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
> index e1041666754..d88c6b78dc7 100644
> --- a/lisp/progmodes/eglot.el
> +++ b/lisp/progmodes/eglot.el
> @@ -2571,7 +2571,7 @@ eglot--workspace-symbols
>                    (let ((probe (gethash pat cache :missing)))
>                      (if (eq probe :missing) (puthash pat (refresh pat)
> cache)
>                        probe)))
> -                (lookup (pat)
> +                (lookup (pat _point)
>                    (let ((res (lookup-1 pat))
>                          (def (and (string= pat "") (gethash :default
> cache))))
>                      (append def res nil)))
> @@ -2579,16 +2579,13 @@ eglot--workspace-symbols
>                    (cl-getf (get-text-property
>                              0 'eglot--lsp-workspaceSymbol c)
>                             :score 0)))
> -      (lambda (string _pred action)
> -        (pcase action
> -          (`metadata `(metadata
> -                       (cycle-sort-function
> +      (backend-completion-table
> +       (lambda (string point) `(,string . ,point))
> +       #'lookup
> +       'eglot-indirection-joy
> +       `((cycle-sort-function
>                          . ,(lambda (completions)
> -                             (cl-sort completions #'> :key #'score)))
> -                       (category . eglot-indirection-joy)))
> -          (`(eglot--lsp-tryc . ,point) `(eglot--lsp-tryc . (,string .
> ,point)))
> -          (`(eglot--lsp-allc . ,_point) `(eglot--lsp-allc . ,(lookup
> string)))
> -          (_ nil))))))
> +                             (cl-sort completions #'> :key #'score))))))))
>
>  (defun eglot--recover-workspace-symbol-meta (string)
>    "Search `eglot--workspace-symbols-cache' for rich entry of STRING."
> @@ -2600,7 +2597,7 @@ eglot--recover-workspace-symbol-meta
>                   (setq v (cdr v))))
>               eglot--workspace-symbols-cache)))
>
> -(add-to-list 'completion-category-overrides
> +(add-to-list 'completion-category-defaults
>               '(eglot-indirection-joy (styles .
> (eglot--lsp-backend-style))))
>
>  (cl-defmethod xref-backend-identifier-at-point ((_backend (eql eglot)))
>
>

-- 
João Távora

[-- Attachment #2: Type: text/html, Size: 5402 bytes --]

  reply	other threads:[~2022-12-03 13:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <166938157708.15020.14294469350904271113@vcs2.savannah.gnu.org>
     [not found] ` <20221125130621.A3C14C0E4C1@vcs2.savannah.gnu.org>
2022-11-25 15:50   ` scratch/backend-completion c807121fbd 1/2: Add lisp/backend-completion.el Stefan Monnier
2022-11-25 16:28     ` João Távora
2022-11-29 21:18       ` Stefan Monnier
2022-11-29 22:59         ` João Távora
2022-11-29 23:44           ` Stefan Monnier
2022-12-03 13:21             ` João Távora [this message]
2022-12-03 14:04               ` Stefan Monnier
2022-12-03 23:22                 ` 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='CALDnm51gxk3pk9JSPrs7EDxMCg-k_hpuiT+7hCf2=12C4NPK2w@mail.gmail.com' \
    --to=joaotavora@gmail.com \
    --cc=emacs-devel@gnu.org \
    --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).