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#70929: 30.0.50; eglot--apply-text-edits prevents point adjustment Date: Tue, 14 May 2024 10:28:05 +0100 Message-ID: References: <86seykx66p.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="17703"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Troy Brown , 70929@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 14 11:30:18 2024 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 1s6oUE-0004PO-7s for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 14 May 2024 11:30:18 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s6oU0-0000xZ-8V; Tue, 14 May 2024 05:30:04 -0400 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 1s6oTy-0000wu-9m for bug-gnu-emacs@gnu.org; Tue, 14 May 2024 05:30:02 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s6oTy-0007EP-0y for bug-gnu-emacs@gnu.org; Tue, 14 May 2024 05:30:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s6oTy-0005Am-Mq for bug-gnu-emacs@gnu.org; Tue, 14 May 2024 05:30:02 -0400 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: Tue, 14 May 2024 09:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70929 X-GNU-PR-Package: emacs Original-Received: via spool by 70929-submit@debbugs.gnu.org id=B70929.171567896719834 (code B ref 70929); Tue, 14 May 2024 09:30:02 +0000 Original-Received: (at 70929) by debbugs.gnu.org; 14 May 2024 09:29:27 +0000 Original-Received: from localhost ([127.0.0.1]:38185 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s6oTP-00059q-4F for submit@debbugs.gnu.org; Tue, 14 May 2024 05:29:27 -0400 Original-Received: from mail-lj1-f170.google.com ([209.85.208.170]:58380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s6oTM-00059i-3v for 70929@debbugs.gnu.org; Tue, 14 May 2024 05:29:26 -0400 Original-Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2e3e18c240fso58508591fa.0 for <70929@debbugs.gnu.org>; Tue, 14 May 2024 02:29:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715678897; x=1716283697; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=FcnvQTbSmq+zeO1Zjt4HJ8VfikB1f9ZvZ1IIrnbz8uQ=; b=DypQ1x9afAHzfa+SUmvhSsHvwGtWBU+jc+0z30YrUJwfPGWhIfo2LHwTLTGbxbfMXD JT4HfT068P3QktekafO6cL0c4+dDaQ9cwQ/pJ86azzjlXXZMIINKO6VElZXWhgcYKcvh rHlwCSgbHmfaMVheLj53rmqJRBO1NAn2uP+A/yycBLMV2+JM/zxITCwFXOzvGq9v4bvk U3g4kHfosbygOtSYwwonfuukvhRAGnfIscUc31s7sxj5haDwCygGy+91qCTdsFbIUupT ykUhBNjw/S46GuNuGwQXAeeBN6HySHg3Fsb90jz2BPQ67wCBUFAN0P3jFzG7fUdGfyVJ X2YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715678897; x=1716283697; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FcnvQTbSmq+zeO1Zjt4HJ8VfikB1f9ZvZ1IIrnbz8uQ=; b=V3XAWcHzflHd4coIBYjRNcc9CB7FuKpR41XgaSM9zf/RaV4t33+m928eCXe7mk8l8R YmVzVsycDA50eGCzHJC3HiCJHiQMZU3C2W5Phm4jfWMZlo/4a0Zl7CuGKePoBvG1yb1b aHJzcUycAOH44kaVqnYTcjI8vWtrJQHYLQOv21XdVmqESl9BUJjKr6r9qV6lRGedYd8J RHJGuKcgZ0wExS1N7KkRA/R/BZ9e48cZGUawIADT/3vkPdIL5EdEH6DOkVHTdyTcyU+q 2eW2jWEH4p/P2CFyzPaMYWianJZZru9BSd+ZlNFdujjwCQFOdaeIaWK/ksr3UgrzpZfl jUfg== X-Forwarded-Encrypted: i=1; AJvYcCVwEjOy+B9XL//ZDb6+2JBsE80Jugn5ZdU1N+Ufa44ulJfLLeO9H802oOrZycQfGoM+UJywTrEFmlB7i3FvTwZ6O8F1NUw= X-Gm-Message-State: AOJu0YxIUiy7HDVcqJcycy48sJD9rPICACvOEIQjBXUynMLPoe6Tj+Zw aMj954LuMpEOGeLeGWcaCmsc9zJlqIrUe9LvKzPpiN+s3il3qpwObikTxWfHLCWWjOhjGiOv+9+ DksOdZ9b4gRHtp4MZcBqHP8PSZ+A= X-Google-Smtp-Source: AGHT+IEOTguMvuRJt2hlBeKE5MUYrHcgY5/qHJPGCAm06mROnCSrKO3B7/OXHSu4rqG94SkrVZ1G3qKKf6OWAytrYOM= X-Received: by 2002:a2e:751:0:b0:2e6:8b17:ca10 with SMTP id 38308e7fff4ca-2e68b17cd3bmr50853511fa.13.1715678896742; Tue, 14 May 2024 02:28:16 -0700 (PDT) In-Reply-To: <86seykx66p.fsf@gnu.org> 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:285003 Archived-At: On Tue, May 14, 2024 at 7:23=E2=80=AFAM Eli Zaretskii wrote: > > > From: Troy Brown > > Date: Mon, 13 May 2024 22:15:07 -0400 > > > > Language Servers may use onTypeFormatting to provide indentation for a > > buffer. When this happens, the language server will indicate a > > newline trigger character (in the DocumentOnTypeFormattingOptions). > > In the Emacs buffer, after hitting RET, point is moved to the next > > line and a textDocument/onTypeFormatting request is sent from Eglot to > > the server. The server responds back with the corresponding spacing > > prefix for the line in newText of the TextEdit response. However, > > when Eglot applies the text edit to insert this spacing, via > > eglot--apply-text-edits, it uses save-excursion, and this prevents the > > point from being pushed to the end of the inserted spacing. It would > > seem that save-excursion should be avoided when applying text edits. > > This issue has been observed with the Ada Language Server. I've reproduced this on the clangd server and c++-ts-mode, but only after turning _off_ electric indent-mode, which hides this effect. > eglot--apply-text-edits, it uses save-excursion, and this prevents the > point from being pushed to the end of the inserted spacing. It would > seem that save-excursion should be avoided when applying text edits. Doing that naively would lead to chaos. Edits can be supplied to arbitrary places in the buffer. Edits can happen in many situations, even when inser= ting completions, for example. If you circumscribe yourself to OnTypeFormatting= , even Clangd for example performs edits before the full expression that prec= edes the newline. There not even anything forcing the server to provide whitespace-only changes. The solution would have to be something like checking these specific edits in this specific situation supplied by the server one by one and upon finding one that is whitespace only and overlaps the points make that change a "push" change. This is simply too complex of a change (you can take a stab at it and provide ample testing, if you want). The workaround of enabling electric-indent-mode or just turning off OnTypeFormatting via eglot-ignored-server-capabilities is much better.