emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scratch/backend-completion c807121fbd 1/2: Add lisp/backend-completi


From: João Távora
Subject: Re: scratch/backend-completion c807121fbd 1/2: Add lisp/backend-completion.el
Date: Sat, 3 Dec 2022 13:21:04 +0000

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]