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 16:18:57 -0500 Message-ID: References: <166938157708.15020.14294469350904271113@vcs2.savannah.gnu.org> <20221125130621.A3C14C0E4C1@vcs2.savannah.gnu.org> <878rjzuhgv.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="4160"; 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 Tue Nov 29 22:20:11 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 1p081T-0000q1-6A for ged-emacs-devel@m.gmane-mx.org; Tue, 29 Nov 2022 22:20:11 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p080h-0006UE-Vi; Tue, 29 Nov 2022 16:19:26 -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 1p080P-0006R4-3j for emacs-devel@gnu.org; Tue, 29 Nov 2022 16:19:18 -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 1p080M-0006sO-78 for emacs-devel@gnu.org; Tue, 29 Nov 2022 16:19:04 -0500 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id DBFF61001D0; Tue, 29 Nov 2022 16:18:59 -0500 (EST) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 10DB7100184; Tue, 29 Nov 2022 16:18:58 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1669756738; bh=4WDbS2ju34v5cowLWa2sgoY3ct7SIsWUJYLY4Y448Bw=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=oJ83iT2/+LlRku3jLktYGIEiU97MuG1TjYiKpVcV/ao492FA/raIAFfnUYbmHQAfi j9IrMhx6oMD0myUZDiW7jzcByJQv8j3iTOoMI5Cxd1B95YzX9SH7EXfVPCpiHIIbBG xwqhBFvUgf/mFxLJHPptpR/z9WNjf8Wl2xcFGirSTe5C78vLw9sNcqhsm5S+wEVFGq gyaxpAxlbKj1Nts1D5xqs1o/ENPN6pH1UkggzITjGwyWJZBM2vSr/sNJTAQ9F+10w5 7iFjJAQGc64bgnKpc/VP54b+5Q55eaWkiiqU8POIRd1zmO1RHjQHBTTmzkOtsGmT2J NoJofyZ81tVbg== Original-Received: from lechazo (lechon.iro.umontreal.ca [132.204.27.242]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 0047A122556; Tue, 29 Nov 2022 16:18:57 -0500 (EST) In-Reply-To: <878rjzuhgv.fsf@gmail.com> (=?windows-1252?Q?=22Jo=E3o_T=E1vo?= =?windows-1252?Q?ra=22's?= message of "Fri, 25 Nov 2022 16:28:00 +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:300728 Archived-At: >> Maybe a good way to do that is to provide a (backend-completion-table >> FUNC CATEGORY &optional METADATA) where FUN is a function which handles >> the tryc and allc cases (maybe the `tryc` handling could even be >> optional, depending on how the `tryc` case is usually handled (do >> backends often provide something usable for `tryc`?)). That function >> would then return an appropriate completion-table (function), and would >> make sure along the way that CATEGORY is mapped to `completion-backend` >> in the `completion-category-defaults`. > > I get the idea, I think. I thought about this, but I'm not sure this > can be made generic enough to service the three examples I know of: > Eglot, SLY and the eel.el thing I've been using lately. I can't see why it wouldn't be just as general as what we have now. (defun backend-completion-table ( tryc-function allc-function category &optional metadata) (unless (assq category completion-category-defaults) (push `(,category (styles completion-backend)) `completion-category-defaults)) (lambda (string pred action) (pcase action (`metadata `(metadata (category . ,category) . ,metadata)) (`(backend-completion-tryc . ,point) ;; FIXME: Obey `pred`? Pass it to `tryc`? `(backend-completion-tryc . ,(funcall tryc string point))) (`(backend-completion-allc . ,point) (let ((all (funcall allc string point))) `(backend-completion-allc . ,(seq-filter pred all)))) (`(boundaries . ,_) nil) (t (let ((all (funcall allc string (length string)))) (complete-with-action action all string pred)))))) >> That `backend-completion-table` would also have the benefit that it >> could make sure the completion-table it returns also behaves sanely >> with other styles (i.e. also handle the "normal" completion table >> requests), whereas otherwise the temptation would be very high for users >> of this package to use "completion table functions" which only handle >> the `backend-completion-tryc/allc` requests and fail pathetically when >> another style is used. Similarly `backend-completion-table` could also >> make sure PRED is obeyed. > > Alright. But please, follow up with some code. You're probably right, > but this whole thing is too complicated for me to understand. See above. >>> (add-to-list 'completion-category-overrides >>> - '(eglot-indirection-joy (styles . (eglot--lsp-backend-style)))) >>> + '(eglot-indirection-joy (styles . (backend-completion-backend-style)))) Wow! I didn't pay attention at first, but I now see you're modifying `completion-category-overrides` which is the user-facing variable. You should modify `completion-category-defaults` instead! >> Any reason not to call that completion category just `eglot`? > > Yes, 'eglot' is already a different completion category, for > completion-at-point, with a different structure. > `eglot-indirection-joy' is just a product of my usual confusion with > this whole jungle of concepts: I just vaguely understand it's an > indirection so I called it accordingly for mental reference. But feel > free to suggest a better name. I'm not very familiar with Eglot's code but based on a cursory check, it seems this is used specifically when completing an identifier for things like `xref`, so maybe `eglot-identifier` (and maybe `eglot` should be renamed to `eglot-code` since it's used to complete the actual code in the buffer)? Stefan