From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.bugs Subject: bug#61726: [PATCH] Eglot: Support positionEncoding capability Date: Fri, 24 Feb 2023 12:01:48 +0100 Message-ID: <87wn479vj7.fsf@gmail.com> References: <87a614g628.fsf@gmail.com> <83cz60r7hu.fsf@gnu.org> <875ybsfvtj.fsf@gmail.com> <831qmgr17p.fsf@gnu.org> <87wn48ecdz.fsf@gmail.com> <83v8jspgnr.fsf@gnu.org> <87lekodxja.fsf@gmail.com> <83a614p4sh.fsf@gnu.org> <87cz60dus9.fsf@gmail.com> <835ybrpnqj.fsf@gnu.org> <87y1oncz09.fsf@gmail.com> <83r0ufo3uc.fsf@gnu.org> <87356vbf0b.fsf@gmail.com> 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="35931"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 61726@debbugs.gnu.org, Eli Zaretskii To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 24 12:02:50 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 1pVVqj-0009A4-SK for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 24 Feb 2023 12:02:49 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVVq4-0006cg-8z; Fri, 24 Feb 2023 06:02:08 -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 1pVVpy-0006cE-SG for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2023 06:02: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 1pVVpy-0000qO-JH for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2023 06:02:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pVVpy-0002x7-0C for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2023 06:02:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Augusto Stoffel Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 Feb 2023 11:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61726 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 61726-submit@debbugs.gnu.org id=B61726.167723651911341 (code B ref 61726); Fri, 24 Feb 2023 11:02:01 +0000 Original-Received: (at 61726) by debbugs.gnu.org; 24 Feb 2023 11:01:59 +0000 Original-Received: from localhost ([127.0.0.1]:36043 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVVpv-0002wq-Ee for submit@debbugs.gnu.org; Fri, 24 Feb 2023 06:01:59 -0500 Original-Received: from mail-ed1-f50.google.com ([209.85.208.50]:33692) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pVVpt-0002we-QO for 61726@debbugs.gnu.org; Fri, 24 Feb 2023 06:01:58 -0500 Original-Received: by mail-ed1-f50.google.com with SMTP id ck15so54567901edb.0 for <61726@debbugs.gnu.org>; Fri, 24 Feb 2023 03:01:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a7qMbeBYtEFHwKcMb3ZPPiOqMJn3/oJXyqqH4PRcdsk=; b=QJzqwvJsWwEUrscpZ1Xlw3l1O6wJlLS7sgEpEbL4OLBaX6itS/PVtY8XGZ4rn2rabq HnUDhsm7jxoc5Dw9a/lWikWSwd0qzgctxl6xLQfFnFdZoEZLqnXuinB9+Gb80KpeGVxj VCE91ntp6W7GLaGhBrwGmxGgdqRZVjgG6THqe6C4UL10jg1chZx4A3h31m+6akNdwmwe facVr2atN79BuP6AnMJO7RjWtcNrR9OumTcO8JVUK39hHoDltb0pZmQVvOY3aAyyB9dT 9F7cuNnY6jgUr2trMrWN3xfDIGFwr6EIj1MPJudQI0pGUczQxXdoj9VHo/WThjPO0UxU E5Tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=a7qMbeBYtEFHwKcMb3ZPPiOqMJn3/oJXyqqH4PRcdsk=; b=OySle+/dqRmORu0kDwzktomKpYEWGlbQhDDW/w7mztVT3lxQemqt0qJHdsdQSJiCCW UrPTqFXOpS8R4NZABt/pG1txLnHyH4xPOWuAFx/l7FXJh/GdicixX9tm52/Bz+CUkrMO Ty4cjFvb8FVr69GJ6yfR/PnBocacUnFaknWrWVbNYk+TqimaNLafv4fAjdkb/meDFb/6 SHeOVF9NZQRDp+BJp19n0JqYYyxxaEUoJ2CtY34v7bmYfx2AvmtifhPJSRYwt0tJNIUT vk7slqIp6c0M2KxKMiGEV0ecpVkurZc3XjDPuqYdIvvy45kPIGBsPJ4wmn4Esltwsqlr huwA== X-Gm-Message-State: AO0yUKWIwFuuL8IiG1UMNAxvggLPPvdX/BsBp/UzRI8CpCcFF/TsBVUU eE44bOepPdqZqDOlXwyq88LzkzZwBWI= X-Google-Smtp-Source: AK7set/ylQ/PQji8eu82rVL+cnVJH8tHIAuONxM6HBAnKUG3LJo3V98up/3kCexzEsLQ98EPMNGphQ== X-Received: by 2002:a50:ed16:0:b0:4ae:eb0f:4273 with SMTP id j22-20020a50ed16000000b004aeeb0f4273mr15463793eds.15.1677236511214; Fri, 24 Feb 2023 03:01:51 -0800 (PST) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::6fd0]) by smtp.gmail.com with ESMTPSA id z5-20020a509e05000000b004ad03b18ae3sm5531159ede.62.2023.02.24.03.01.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 03:01:50 -0800 (PST) In-Reply-To: ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Fri, 24 Feb 2023 10:20:36 +0000") 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:256562 Archived-At: On Fri, 24 Feb 2023 at 10:20, Jo=C3=A3o T=C3=A1vora wrote: > The second thing I don't like is also due to the late-binding idea. > This is a hotspot in Eglot, some of these functions are called > many many times, for each LSP server interaction depending > on how many document positions are exchanged (and they can > be a lot). I do remember benchmarking strategies at the time > and seeing a perceptible difference. Plus, this late-binding is > really useless as a server will guaranteedly _not_ change its > column-counting standard during the LSP session. `eglot-lsp-abiding-column' allocates a new string! I doubt that looking up a few plists makes much of a difference compared to that. But when using the better offset counting styles, I think it might indeed make a difference. OTOH it might as well be premature optimization. > Finally, here's a patch that doesn't use late-binding, doesn't > introduce new strategies and supports "utf-32" and "utf-16" > today. As you can see, the patch is nearly trivial. I'm fine with that way of doing things, but please respond to my concern from the other message: do you really want to store a server capability in a buffer-local variable? What about your plans to support multiple servers? I suggest you to guard against future headaches. We can store the offset functions in two slots of the server class if you don't like to traverse the capabilities plist each time. > diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el > index eea8be6d1aa..ae8afa69651 100644 > --- a/lisp/progmodes/eglot.el > +++ b/lisp/progmodes/eglot.el > @@ -807,6 +807,7 @@ eglot-client-capabilities > :rangeFormatting `(:dynamicRegistration :json-false) > :rename `(:dynamicRegistration :json-false) > :inlayHint `(:dynamicRegistration :json-false) > + :general `(:positionEncodings ["utf-32" "utf-16"= ]) > :publishDiagnostics (list :relatedInformation :json-false > ;; TODO: We can support > :codeDescription after > ;; adding an appropriate UI to > @@ -1789,6 +1790,9 @@ eglot--managed-mode > (add-hook 'eldoc-documentation-functions #'eglot-signature-eldoc-f= unction > nil t) > (eldoc-mode 1)) > + (when (eq (eglot--server-capable :positionEncoding) "utf-16") > + (eglot--setq-saving eglot-move-to-column-function #'eglot-move-to-= column) > + (eglot--setq-saving eglot-current-column-function > #'eglot-current-column)) > (cl-pushnew (current-buffer) (eglot--managed-buffers > (eglot-current-server)))) > (t > (remove-hook 'after-change-functions 'eglot--after-change t) > > As I said, enhancing this patch with a new pair of "current/move-to" > functions that add in utf-8 support is acceptable. > > Jo=C3=A3o