From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Newsgroups: gmane.emacs.devel Subject: Re: scratch/backend-completion c807121fbd 1/2: Add lisp/backend-completion.el Date: Sat, 3 Dec 2022 13:21:04 +0000 Message-ID: References: <166938157708.15020.14294469350904271113@vcs2.savannah.gnu.org> <20221125130621.A3C14C0E4C1@vcs2.savannah.gnu.org> <878rjzuhgv.fsf@gmail.com> <87a649qsef.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000399de305eeec544a" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27990"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Dec 03 14:22:06 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p1SSz-00072V-B8 for ged-emacs-devel@m.gmane-mx.org; Sat, 03 Dec 2022 14:22:05 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p1SSH-0007BM-6B; Sat, 03 Dec 2022 08:21:21 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p1SSF-0007AL-MA for emacs-devel@gnu.org; Sat, 03 Dec 2022 08:21:19 -0500 Original-Received: from mail-ot1-x32d.google.com ([2607:f8b0:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p1SSD-0000Ym-JX for emacs-devel@gnu.org; Sat, 03 Dec 2022 08:21:19 -0500 Original-Received: by mail-ot1-x32d.google.com with SMTP id m7-20020a9d6447000000b0066da0504b5eso4530098otl.13 for ; Sat, 03 Dec 2022 05:21:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gQe8EuZ7wt7ro5sxd6KaBS+6WMP3nWEY/d2W8Dvikdc=; b=RdHUnZvn5zG6o+q3YghR5K7mgfVQ7E8JSE2I5TAEVihUoo4KrPf8h2qIrQzSa2Dopm joChKH+a+2MzUG249qnti8Oos6YEhR6pKPhKvVUOHSe2bmXjjUWqehtkooPqtHokJYc7 6Nt/OsqD82fWHrYPlTvEeYw1ClXum4EqfNnGINc/uFC61KY+HPOlGEUP1Vap8mzQYcCI k6xf+blr91tcgXDd9d8D0KO+1C42a9Uxi1CPOfxxrJhMtisne6voJ/o5jpIvQ/eCdrEd s3hPViwAS7IiidQpTVP1qSJRckBma0TmEGItUpsjKJs5m1J/L1HfKarRjMH7HrspYW7B DWog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gQe8EuZ7wt7ro5sxd6KaBS+6WMP3nWEY/d2W8Dvikdc=; b=hIrK4OVO6QslVRmLfqaJ84IGsDO4HiOQa1X6M4FamrSBJnUFBdw2n4+Bah+7lgw6BG 7uC32qA9Qxm61yxC2PEjxktc91X3RJJ9xAbdq208gC9rYXLTbjsTw3swXPJ16Ta/LvRT 4LJBeGtpRGTbObeRGudVaLEuOxrEqMUy4gsiAic0HqGsTO3gBcV4Bm1JgGV30BY/j0P4 0goiWfPUFzM1nSDIdlFs0hZMwFYXY1j/U50KIOyjiwqRH0BX7KhbSGOv+MuWNMJsY8W1 DWIwzqYSFxXYkt2wwogm092Qx+n3cx10umnEJDIB4fy9U8NMuh4rf0jwl5gO8g3HO+UW UfTQ== X-Gm-Message-State: ANoB5pm3oyzGmT5NEx2AHGZXoREVQ50PRXWsVNLBh2dktTLmK2eG2++m +6HR3fDUmqzkz6kZJhDLSZUD+AwVWceqosbTSDpagoj5 X-Google-Smtp-Source: AA0mqf5hWLcpoJTkQk7573apwpByydZTCn5iX3lwyhokMiYRYDnBYu0IyuUlHJD7jxrmMvgrMTi3OTwY6csHopz7Yp8= X-Received: by 2002:a9d:61ca:0:b0:66e:6d59:b2df with SMTP id h10-20020a9d61ca000000b0066e6d59b2dfmr7827418otk.201.1670073676306; Sat, 03 Dec 2022 05:21:16 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::32d; envelope-from=joaotavora@gmail.com; helo=mail-ot1-x32d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:300868 Archived-At: --000000000000399de305eeec544a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=C3=A3o On Tue, Nov 29, 2022 at 11:44 PM Stefan Monnier 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=3D 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))) > > --=20 Jo=C3=A3o T=C3=A1vora --000000000000399de305eeec544a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hey Stefan,

I just pushed to scratch/ba= ckend-completion.

I integrated most of your sugges= tions and added docstrings.=C2=A0 I'm sure=C2=A0
you'll w= ant to comment and tweak some stuff (some of the=C2=A0
documentat= ion is=C2=A0purposely=C2=A0cheeky and there is also a FIXME=C2=A0
or two.).=C2=A0=C2=A0

I quite like this and it= 9;s working well for both Eglot and that other=C2=A0
library.=C2= =A0 I haven't tried it with SLY but I'm sure it will do the job nic= ely.

One of the most important things though is th= e naming.=C2=A0=C2=A0
"Backend completion" is not a goo= d name, there are already a ton
of "backend" semantics= =C2=A0that are entirely Emacs only, and this new
style is really = exclusive for tools _outside_ of Emacs's=C2=A0address
=C2=A0s= pace.

Let me=C2=A0know what you think, Jo=C3=A3o

On Tue, Nov 29, 2022 at 11:44 PM Stefan Monnier <monnier@iro.umontreal.ca> wrote= :
> OK great.= =C2=A0 But where do you plug the current eglot functions into it.

Something like the patch below?

> Maybe.=C2=A0 As I've often told you, all this completion code is h= ard to
> grasp.=C2=A0 I do "get" it somewhat, and I've been worki= ng with it intensely
> for a long time.=C2=A0 But also, I don't really get it :-) For exa= mple, I
> have no solid concept of what a category or a style is, so everything<= br> > just reads like "an indirection from this thing to that other thi= ng".

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 &= quot;sets of
identifiers" this is completing so users can customize the behavior fo= r
specific cases.

> So I named this thing 'eglot-indirection' . 'eglot-code= 9; may be logical
> for someone who knows what a category means, now but sounds something<= br> > 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<= br> inserts/selects by completion".


=C2=A0 =C2=A0 =C2=A0 =C2=A0 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
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let (= (probe (gethash pat cache :missing)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(if (eq probe :missing) (puthash pat (refresh pat) cache)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0probe)))
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (lookup (pat)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (lookup (pat _poin= t)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(let (= (res (lookup-1 pat))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0(def (and (string=3D pat "") (gethash :default c= ache))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(append def res nil)))
@@ -2579,16 +2579,13 @@ eglot--workspace-symbols
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cl-ge= tf (get-text-property
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A00 'eglot--lsp-workspaceSymbol c)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 :score 0)))
-=C2=A0 =C2=A0 =C2=A0 (lambda (string _pred action)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 (pcase action
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (`metadata `(metadata
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(cycle-sort-function
+=C2=A0 =C2=A0 =C2=A0 (backend-completion-table
+=C2=A0 =C2=A0 =C2=A0 =C2=A0(lambda (string point) `(,string . ,point))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0#'lookup
+=C2=A0 =C2=A0 =C2=A0 =C2=A0'eglot-indirection-joy
+=C2=A0 =C2=A0 =C2=A0 =C2=A0`((cycle-sort-function
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0. ,(lambda (completions)
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cl-sort completions #'> :key #'s= core)))
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0(category . eglot-indirection-joy)))
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (`(eglot--lsp-tryc . ,point) `(eglot--l= sp-tryc . (,string . ,point)))
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (`(eglot--lsp-allc . ,_point) `(eglot--= lsp-allc . ,(lookup string)))
-=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (_ nil))))))
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(cl-sort completions #'> :key #'s= core))))))))

=C2=A0(defun eglot--recover-workspace-symbol-meta (string)
=C2=A0 =C2=A0"Search `eglot--workspace-symbols-cache' for rich ent= ry of STRING."
@@ -2600,7 +2597,7 @@ eglot--recover-workspace-symbol-meta
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (setq v (cdr= v))))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 eglot--workspace-symbols-c= ache)))

-(add-to-list 'completion-category-overrides
+(add-to-list 'completion-category-defaults
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 '(eglot-indirection-jo= y (styles . (eglot--lsp-backend-style))))

=C2=A0(cl-defmethod xref-backend-identifier-at-point ((_backend (eql eglot)= ))



--
Jo=C3=A3o T=C3=A1vora
--000000000000399de305eeec544a--