From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: scratch/backend-completion c807121fbd 1/2: Add lisp/backend-completion.el Date: Tue, 29 Nov 2022 18:44:47 -0500 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: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31136"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: emacs-devel@gnu.org To: =?windows-1252?B?Sm/jbyBU4XZvcmE=?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Nov 30 00:45:41 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 1p0AIH-0007w8-ER for ged-emacs-devel@m.gmane-mx.org; Wed, 30 Nov 2022 00:45:41 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p0AHZ-0003hX-Sk; Tue, 29 Nov 2022 18:44:59 -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 1p0AHY-0003hM-Gp for emacs-devel@gnu.org; Tue, 29 Nov 2022 18:44:56 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p0AHW-0001jz-98 for emacs-devel@gnu.org; Tue, 29 Nov 2022 18:44:56 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7637C100182; Tue, 29 Nov 2022 18:44:50 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id A8981100143; Tue, 29 Nov 2022 18:44:48 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1669765488; bh=YapVLW7TDko6kJ1sQOz+/g94cnZF44/arpztDznnS1M=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=ZnMPQ69h64C41j46auaqWLlrtY3HH6Qccp8nveiD7rmhMiHNob8fOpfRoMzzL0JER hNS7QueIjQWl/6NKmWhh29gLUuwCSz32PJ6zOikGm4jYujAgBO4Id2zGHfKz1KmJh9 D28TIXoTdVVnP3GrCV5xvAKsWk4LsMK16U+Fi1YSQNNiBaHonjodbx1zNquLBtBxYI MtponI47T+csKyj28fWg84c8NrCZowSGEa/GPETmFvh37aGpggi6ZNX3b3equF12mV n+jR6e0yGB6SDJf0QDGIX6l7Ou7v9nHLM0DAJCb/Zwl7d5UuBQd8KEKhZGt9A42RzJ EIxkKm/XR3bUg== Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 67FD3122556; Tue, 29 Nov 2022 18:44:48 -0500 (EST) In-Reply-To: <87a649qsef.fsf@gmail.com> (=?windows-1252?Q?=22Jo=E3o_T=E1vo?= =?windows-1252?Q?ra=22's?= message of "Tue, 29 Nov 2022 22:59:04 +0000") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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:300736 Archived-At: > 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)))