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: Wed, 15 Feb 2023 15:52:00 +0100 Message-ID: <87ttzn6kxb.fsf@thornhill.no> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33045"; mail-complaints-to="usenet@ciao.gmane.io" Cc: joaotavora@gmail.com To: 61532@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Feb 15 15:53:18 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 1pSJ9p-0008Ph-UK for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 15 Feb 2023 15:53:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pSJ9f-0003Vf-0L; Wed, 15 Feb 2023 09:53:07 -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 1pSJ9b-0003VD-7N for bug-gnu-emacs@gnu.org; Wed, 15 Feb 2023 09:53:03 -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 1pSJ9a-0002mY-Th for bug-gnu-emacs@gnu.org; Wed, 15 Feb 2023 09:53:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pSJ9a-0005YC-Ju; Wed, 15 Feb 2023 09:53:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: joaotavora@gmail.com, bug-gnu-emacs@gnu.org Resent-Date: Wed, 15 Feb 2023 14:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 61532 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: joaotavora@gmail.com Original-Received: via spool by submit@debbugs.gnu.org id=B.167647273221260 (code B ref -1); Wed, 15 Feb 2023 14:53:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 15 Feb 2023 14:52:12 +0000 Original-Received: from localhost ([127.0.0.1]:58445 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pSJ8m-0005Wm-5Y for submit@debbugs.gnu.org; Wed, 15 Feb 2023 09:52:12 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:46096) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pSJ8h-0005Wa-HG for submit@debbugs.gnu.org; Wed, 15 Feb 2023 09:52:10 -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 1pSJ8h-0003Ou-9Z for bug-gnu-emacs@gnu.org; Wed, 15 Feb 2023 09:52:07 -0500 Original-Received: from out-3.mta1.migadu.com ([2001:41d0:203:375::3]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pSJ8e-0002XO-I1 for bug-gnu-emacs@gnu.org; Wed, 15 Feb 2023 09:52:06 -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=1676472722; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=Zu5D/ymzzY/jOutb6aLZ3KbxmgVomkIv1t+drXHjXMs=; b=Rb8s9nb8q2StcFet7I9xa1qAacZbRQuqHxbrn2+bU5CG3xaGJ1QXndpX5DtvM+hF2LIhco ukNHbLWra35yRbTywmOK7zXYeCL87d1v5nL9u8qoKFJodbRLVHZ57MqDdxQYjtnbuWOYK5 a/+JOUGZa0r2ghxU0BP/kbwR89TzdllJEXpaGAAJlwJPJGhN19+KErYjaWs6WB5w9XRQat 1YBjOOsGiNzBrIPYKuKp77gPDkfu1mlZWFL+K/+Zces1Z83fYT3l1DgXMtcRtumDsVyflF tfGyVzvavWP1mZ+klKfofTVgPWXQlVfOvHylGRBKx83uZUflvUBGQwRcGn2EHA== X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:203:375::3; envelope-from=theo@thornhill.no; helo=out-3.mta1.migadu.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:255726 Archived-At: --=-=-= Content-Type: text/plain Hi Joao and others! As I mentioned in a different Eglot bug I believed there was a problem with sorting of candidates. It seems there kinda is, but it's a little convoluted. To test this you need to have a server that supplies snippets, or at least that sends some items with and without :sortText. However, the code is simple enough, so it should be enough to read it. So, what happens with completion in Eglot that I find confusing is that sometimes, candidates in the completion frameworks (company, corfu etc) display candidates in a seemingly random order compared to what the server sends. In particular, the Jdtls server sends snippets without sorttext, which will be converted to the empty string in the sorter function. That in turn will make all the snippets fall to the front of the list as (string-lessp "" "anything else") evaluates to t. That means we ignore the sorts supplied by the server. Because (string-lessp nil "anything else") evaluates to nil it will put them at the end of the list, which IMO makes more sense. In addition, the completion-category-defaults set by eglot uses flex, as you know, so the display-sort-function will sort them very hungrily, making them seem out of order. For example, if the candidates are (delete, deleteAll, deleteById) when buffer content is (| is point): ``` something.del| ``` completion will display them in this order: (deleteAll, deleteById, delete), which yet again "doesn't respect sort order". The latter issue is fixed by setting (setq completion-category-overrides '((eglot (styles basic partial-completion initials)))) or something else, which works, but is very convoluted and really not documented anywhere, or did I miss it? The former issue is fixed in the supplied patch. Do you agree with what I propose? We could also default to something like :label or :insertText, but that would in some cases also likely conflict with what the server is expected to send. Theo --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Make-completions-without-sortText-fall-to-back-of-th.patch >From 6b5c37f00f73abf07a72d2bc2fe6edb99f8ee0a4 Mon Sep 17 00:00:00 2001 From: Theodor Thornhill Date: Wed, 15 Feb 2023 15:16:15 +0100 Subject: [PATCH] Make completions without :sortText fall to back of the list * lisp/progmodes/eglot.el: String-lessp is safe with (string-lessp nil "foo") and (string-lessp "foo" nil), but defaulting to the empty string puts candidates to the top of the list. Nil will make the candidates fall to the end of the list. --- lisp/progmodes/eglot.el | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 5e761d3064f..c8620f4199f 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -2782,10 +2782,9 @@ eglot-completion-at-point (cl-sort completions #'string-lessp :key (lambda (c) - (or (plist-get - (get-text-property 0 'eglot--lsp-item c) - :sortText) - ""))))) + (plist-get + (get-text-property 0 'eglot--lsp-item c) + :sortText))))) (metadata `(metadata (category . eglot) (display-sort-function . ,sort-completions))) resp items (cached-proxies :none) -- 2.34.1 --=-=-=--