From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61532: 30.0.50; [PATCH]: Make completions without sortText fall to back of the list Date: Sun, 19 Feb 2023 19:52:43 +0100 Message-ID: <87pma5ij2c.fsf@thornhill.no> References: <87ttzn6kxb.fsf@thornhill.no> <875yby62j9.fsf@thornhill.no> <348D7924-284D-4D14-882E-02C8CAD7A925@thornhill.no> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26495"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 61532@debbugs.gnu.org To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= , Stefan Monnier , Augusto Stoffel Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 19 19:53:17 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1pTooH-0006iy-C4 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 Feb 2023 19:53:17 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pToo4-000211-Oc; Sun, 19 Feb 2023 13:53:04 -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 1pToo2-00020f-Mp for bug-gnu-emacs@gnu.org; Sun, 19 Feb 2023 13:53:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pToo2-00015h-9T for bug-gnu-emacs@gnu.org; Sun, 19 Feb 2023 13:53:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pToo2-0008OK-0x for bug-gnu-emacs@gnu.org; Sun, 19 Feb 2023 13:53:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 19 Feb 2023 18:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61532 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 61532-submit@debbugs.gnu.org id=B61532.167683276732235 (code B ref 61532); Sun, 19 Feb 2023 18:53:01 +0000 Original-Received: (at 61532) by debbugs.gnu.org; 19 Feb 2023 18:52:47 +0000 Original-Received: from localhost ([127.0.0.1]:49665 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pTonn-0008No-An for submit@debbugs.gnu.org; Sun, 19 Feb 2023 13:52:47 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]:16360) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pTonl-0008Ng-6Z for 61532@debbugs.gnu.org; Sun, 19 Feb 2023 13:52:45 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1676832764; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dhsq5JBUafd5ieMHDABQgaQTocNMWCCQXDz2nzKSY2Y=; b=Mol0k4qtfi1G/e6RvYu4joOAhABn6fVUBiNFouCIVqj3JdH3CYTU3UZLYEmoVZ50AnpQGR dyZi6GIUC7mNGE8GOU1GOzY+GtW60q86Dv3MBIvfmydleyqOH7R1nb0C5i6l0zEd6nqRAN 6TDr/aPcTQkDZeJrZ3LIVqdpHfe5uWavh1R3BN+9rIu+3Xi3/mavAjWuM5e56PoFyW9kKe V6AXsaugpneWlRFP9WIbMNPo+kENWMwAcENHz6v7ivwNfFE8caLZLK6a7/VeB7JyFxSbhx xNTc2niEa7JGoSKjohztjFSTWaADQppK770rQc8ndwUgcm2xDJjq45WCjeuqug== In-Reply-To: X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:256100 Archived-At: Jo=C3=A3o T=C3=A1vora writes: > On Sun, Feb 19, 2023 at 4:08 PM Theodor Thornhill wro= te: >> >> >> >bug tracker list. Next time, you can add me to the special X-Debbugs-C= C: >> >header] >> Pretty sure I did that, but it doesn't matter :) > > [ I didn't get the message. I went to look in the mbox file off Debbugs a= nd > I did > find a 'X-Debbugs-Cc' header, but maybe it has to be 'X-Debbugs-CC'?] > >> I don't think it's a bug, really. Isn't it just the flex style greedines= s? > > The 'flex' completion style isn't really doing (or at shouldn't be doing) > what it does normally. Its purpose in Eglot is only to allow for flex-sty= le > fontification of the pattern to happen. Nothing more, and that includes > no sorting. > > That's because, contrary to the normal uses of flex, here it's the > server which does all the selection and the filtering for whatever > it thinks is a pattern. It turns out that a very common style of filteri= ng > among servers is akin to 'flex', so using flex on our side to "paint" > the pattern in the completion candidate is usually, though not always, > a good bet. If the server happens to use 'prefix' ,then 'flex' will also > paint it correctly, in principle. This is of course presuming we guess > the filter pattern that the server used, which we're not guaranteed > to, but more or less always do by looking for a 'symbol' thing-at-point. > > Anyway, flex shouldn't be doing any kind of completion sorting for > eglot-completion-at-point. So if it is doing that, it's IMO a bug (though > perhaps not a serious one, as it wouldn't be a very absurd sorting > anyway). > I spent some time trying to understand what was happening inside this function, which seems to sort, and is triggered upon completion. Maybe that's a clue? I have no idea, honestly, but I remember getting different results when changing > to < in the middle of it: ``` (defun completion--flex-adjust-metadata (metadata) "If `flex' is actually doing filtering, adjust sorting." (let ((flex-is-filtering-p ;; JT@2019-12-23: FIXME: this is kinda wrong. What we need ;; to test here is "some input that actually leads/led to ;; flex filtering", not "something after the minibuffer ;; prompt". E.g. The latter is always true for file ;; searches, meaning we'll be doing extra work when we ;; needn't. (or (not (window-minibuffer-p)) (> (point-max) (minibuffer-prompt-end)))) (existing-dsf (completion-metadata-get metadata 'display-sort-function)) (existing-csf (completion-metadata-get metadata 'cycle-sort-function))) (cl-flet ((compose-flex-sort-fn (existing-sort-fn) ; wish `cl-flet' had proper indentation... (lambda (completions) (sort (funcall existing-sort-fn completions) (lambda (c1 c2) (let ((s1 (get-text-property 0 'completion-score c1)) (s2 (get-text-property 0 'completion-score c2))) (> (or s1 0) (or s2 0)))))))) ;; This line here `(metadata ,@(and flex-is-filtering-p `((display-sort-function . ,(compose-flex-sort-fn (or existing-dsf #'identity))))) ,@(and flex-is-filtering-p `((cycle-sort-function . ,(compose-flex-sort-fn (or existing-csf #'identity))))) ,@(cdr metadata))))) ``` >> It feels like it tries to match the longest string possible > alphabetically? It's >> just unintuitive because the json results doesn't match the output, and >> debug stepping over was very unhelpful. We could maybe just add >> some docs explaining that eglot default, which for many really is an > eglot >> hard-coding. > > I hope I explained why it's there. This is what I recall of it, though > I may be misremembering. You could help improve the documentation > by confirming my recollection hypothesis and adding comments to the > code. > > Anyway, this boils down to a limitation of LSP, that it doesn't report on > what > kind of matching style it uses for textDocument/completion. At least it > used to be a limitation of LSP, maybe someone else has fixed it in the > meantime, or added something that we can use. > > Jo=C3=A3o Yeah, that makes sense. > > PS: Added Stefan and Augusto to the discussion since I think they are > already familiar with this LSP/Emacs discrepancy regarding completion > systems and completion philosophy. :thumbsup: Theo