From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Newsgroups: gmane.emacs.bugs Subject: bug#61726: [PATCH] Eglot: Support positionEncoding capability Date: Sun, 26 Feb 2023 15:15:57 +0000 Message-ID: <87zg90o3te.fsf@gmail.com> References: <87a614g628.fsf@gmail.com> <874jrb9l6d.fsf@gmail.com> <834jrbnlaf.fsf@gnu.org> <87v8jr83ic.fsf@gmail.com> <83v8jrm4r0.fsf@gnu.org> <87fsav7x81.fsf@gmail.com> <83a612ko73.fsf@gnu.org> <87ttza3rwh.fsf@gmail.com> <83356tluvq.fsf@gnu.org> <87a61125ox.fsf@gmail.com> <83wn45k8yu.fsf@gnu.org> <874jr9z94m.fsf@gmail.com> <87y1olv0h1.fsf@gmail.com> <87sfetgux5.fsf@gmail.com> <83pm9xj74q.fsf@gnu.org> <83v8joimo9.fsf@gnu.org> <87r0ucpl30.fsf@gmail.com> <83r0uciiqi.fsf@gnu.org> 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="16289"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 61726@debbugs.gnu.org, arstoffel@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 26 16:15:20 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 1pWIkB-00046M-KW for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 Feb 2023 16:15:19 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pWIjv-0002Fx-Oj; Sun, 26 Feb 2023 10:15:03 -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 1pWIju-0002Fg-TG for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 10:15: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 1pWIju-0008Ej-K9 for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 10:15:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pWIju-0002p2-BI for bug-gnu-emacs@gnu.org; Sun, 26 Feb 2023 10:15:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 26 Feb 2023 15:15:02 +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.167742445310765 (code B ref 61726); Sun, 26 Feb 2023 15:15:02 +0000 Original-Received: (at 61726) by debbugs.gnu.org; 26 Feb 2023 15:14:13 +0000 Original-Received: from localhost ([127.0.0.1]:44818 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pWIj6-0002nY-Ux for submit@debbugs.gnu.org; Sun, 26 Feb 2023 10:14:13 -0500 Original-Received: from mail-wr1-f51.google.com ([209.85.221.51]:37537) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pWIj4-0002nK-5l for 61726@debbugs.gnu.org; Sun, 26 Feb 2023 10:14:12 -0500 Original-Received: by mail-wr1-f51.google.com with SMTP id h14so3763429wru.4 for <61726@debbugs.gnu.org>; Sun, 26 Feb 2023 07:14:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677424444; 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=qc1YvCwCQKA1+lLoFwe3XjECgCHEm87vChgGn6RVEps=; b=mbnDe/rFJh+EuZv+bP/lEkMKJT0FAitvsHlF3p0ZjngIsuiWzhW+nn/CBastTBnShh K1fSRlrxucpaBMCp88891kr22c54hk5jHBAcbR5IEvRh8uXQLlkdDiUBNa7GT8tA66tb o40O2HV7GugsSlzgXVm1HDDHnk6bLfpc0BxXUzFP2c4NmxIeAl8hiy8DGnvXuJfhU749 gRTiM0ls9yCZy80NrFsU2cd57q3vFLem/NoevKIaOm6EEaA/bPW7N9RaMv6MkUV3X3mJ EbsRfd22CI68w6YvyUSdncMumSdotXNgUeKH+rZAhLx25FwudTdhQM3Hj/MWiXDuFDEE Kp9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677424444; 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=qc1YvCwCQKA1+lLoFwe3XjECgCHEm87vChgGn6RVEps=; b=qnocflsucDopSTOPr+3Vc0EcZxtlZVPqIa0PsJVvmRK77/V2cwbkkPqsPymfQ4Co0X QpBo7Ryb2AT7AckahacTk/sRrXS3Fwj/Dd96xO5o7SbWC/F8GVxnrZFG+WKJxLcvTT5t fPu8D4yX7xvUJBWRmfozSxI7hSIKhR0IFOPj9w1IYe/RDMs6xxRgjosBtWHdBSEohOIj OXwmwwAX47NA8/cOL0PVCR8nOf4qpRZdLfkfBak//pr8t8C4WW4BALhSHwiG+k8hGgeA Fj2tisoexXE6EVsozxD5dBZ12VN0rb99K09DbyambuLLes1gcaB1g9j9YUphcdxhuTP0 gLBQ== X-Gm-Message-State: AO0yUKUDPHESm22ISV8LWpnKrypVmVM5CLB2rPneyqi+29X6sOFvtZUM 4UAsgkwwNkBbARuLfuUFyDgbQA50UUo= X-Google-Smtp-Source: AK7set+MlDwuw4egrgjQ0Za5Ivt4ICKrfIih9M2vsXqpvZ5oZoz9+2FY6tYfe+sR6310tE6M61yZ7Q== X-Received: by 2002:adf:fa0a:0:b0:2c7:851:c0bf with SMTP id m10-20020adffa0a000000b002c70851c0bfmr13593643wrr.0.1677424443989; Sun, 26 Feb 2023 07:14:03 -0800 (PST) Original-Received: from krug (87-196-72-142.net.novis.pt. [87.196.72.142]) by smtp.gmail.com with ESMTPSA id ay26-20020a05600c1e1a00b003e21f20b646sm6274363wmb.21.2023.02.26.07.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Feb 2023 07:14:03 -0800 (PST) In-Reply-To: <83r0uciiqi.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 26 Feb 2023 16:50:13 +0200") 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:256813 Archived-At: Eli Zaretskii writes: >> But as I said this is just a nit. > > I made one more fix. FTR, I think it's way worse now. The function variable has no clear protocol: it's very odd to state its return type as number of code units _or_ bytes _or_ code points. A good docstring for such a variable notes that, for any buffer position, a plugged-in function must return the same _type_ but may return a different _value_ to match the unit-counting strategy being used by the LSP server. I haven't reverted to avoid a commit war, and because I'm a bit weary of this bug. I leave a patch for consideration and for the record, feel free to ignore it. Jo=C3=A3o diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index dd84f545ed4..12fb72503aa 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1453,11 +1453,20 @@ eglot--warn (defvar eglot-current-linepos-function #'eglot-utf-16-linepos "Function calculating position relative to line beginning. =20 -This is the inverse of `eglot-move-to-linepos-function' (which see). -It is a function of no arguments returning the number of code units -or bytes or codepoints corresponding to the current position of point, -relative to line beginning, as expected by the function that is the -value of `eglot-move-to-linepos-function'.") +This is the inverse operation of +`eglot-move-to-linepos-function' (which see). The value is a +nullary function that examines current `point' and computes the +number of code units relative to line beginning in such a way +that it matches how the LSP server also counts code units. For +example, if the LSP server is using UTF-16 encoding, and point is +on the \"b\" of a line containing just \"aXbc\" where \"X\" is a +funny looking character in the UTF-16 \"supplementary plane\", +this function has to return 3 code points instead of 2. If the +server is using UTF-32 encoding, this function should return 2 +code points. + +Since LSP 3.17 server and client may agree on an encoding and +Eglot will set this variable automatically.") =20 (defun eglot-utf-8-linepos () "Calculate number of UTF-8 bytes from line beginning." @@ -1496,11 +1505,11 @@ eglot-move-to-linepos-function "Function to move to a position within a line reported by the LSP server. =20 Per the LSP spec, character offsets in LSP Position objects count -UTF-16 code units, not actual code points. So when LSP says -position 3 of a line containing just \"aXbc\", where X is a funny -looking character in the UTF-16 \"supplementary plane\", it -actually means `b', not `c'. The default value -`eglot-move-to-utf-16-linepos' accounts for this. +code units, not actual code points. The default is to use UTF-16 +encoding, so when LSP says position 3 of a line containing just +\"aXbc\", where \"X\" is a funny looking character in the UTF-16 +\"supplementary plane\", it actually means \"b\", not \"c\". The +default value `eglot-move-to-utf-16-linepos' accounts for this. =20 This variable can also be set to `eglot-move-to-utf-8-linepos' or `eglot-move-to-utf-32-linepos' for servers not closely following