From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#60338: [PATCH] Add option to present server changes as diffs Date: Fri, 01 Sep 2023 23:12:59 +0200 Message-ID: References: <87ilhy1dub.fsf@posteo.net> <877cs97kgb.fsf@posteo.net> <83jzw8yjv5.fsf@gnu.org> <877cs8g8oy.fsf@posteo.net> <83fs6wyhak.fsf@gnu.org> <87y1koerm6.fsf@posteo.net> <83bkhkyeze.fsf@gnu.org> <87v8fr6o86.fsf@posteo.net> <87zg52e12n.fsf@posteo.net> <871qi9q9uc.fsf@posteo.net> <87a5ww7qa3.fsf@gmail.com> <87jzvsdco1.fsf@posteo.net> <87zg2669kk.fsf@gmail.com> Reply-To: Eshel Yaron 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="25603"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: dmitry@gutov.dev, Philip Kaludercic , 60338@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 Sep 01 23:14:05 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 1qcBSt-0006U2-Bf for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 01 Sep 2023 23:14:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qcBSo-00026h-BR; Fri, 01 Sep 2023 17:13:58 -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 1qcBSj-0001pz-9W for bug-gnu-emacs@gnu.org; Fri, 01 Sep 2023 17:13:53 -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 1qcBSj-0004a4-1V for bug-gnu-emacs@gnu.org; Fri, 01 Sep 2023 17:13:53 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qcBSs-0000Ky-Ba for bug-gnu-emacs@gnu.org; Fri, 01 Sep 2023 17:14:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eshel Yaron Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 01 Sep 2023 21:14:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60338 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 60338-submit@debbugs.gnu.org id=B60338.16936028041244 (code B ref 60338); Fri, 01 Sep 2023 21:14:02 +0000 Original-Received: (at 60338) by debbugs.gnu.org; 1 Sep 2023 21:13:24 +0000 Original-Received: from localhost ([127.0.0.1]:34264 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qcBSF-0000Jz-Og for submit@debbugs.gnu.org; Fri, 01 Sep 2023 17:13:24 -0400 Original-Received: from mail.eshelyaron.com ([107.175.124.16]:38524 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qcBSD-0000Jr-Oh for 60338@debbugs.gnu.org; Fri, 01 Sep 2023 17:13:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1693602791; bh=p7+2tpnFQrb/04j8/aR1nUasHtcgaQcE3Xxk1CsBBps=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=B0OaMKpkoMFlKg8kU35Yyvm3L84CtbLQIdaot+YihNKZGOhkYttPQKe1LUwg8+Od2 VFPeHbCMKSAx3yGQlhcJWzIwhzhZ8dBem/6XqqhPdSUhI8NW5QoxwweniSbE9OMewx tfN96C4JnfG3t/c/iFDsIf8dIweK8YsNtLjRtgnFbmeWsUl/+6i2fWjRmwoatSw2MR +/SJz+2+Ll0hpRqialgIQiPZWuVBJyuXUSyREMGArugudiMjAltghbSRtRaKMKRHzX Akn8WkFvMYbixp15V1Cq3YvhYHsOli3Wxf8ZU3Z1QKXtFiCsOxI5e5oRS0CkzSdA3U PKM4sVo+DntlQ== In-Reply-To: <87zg2669kk.fsf@gmail.com> ("=?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?="'s message of "Fri, 01 Sep 2023 01:06:35 +0100") 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:268931 Archived-At: Jo=C3=A3o T=C3=A1vora writes: > I've finally pushed this to master, after working on mostly on the user > confirmation logic. I deprecated `eglot-confirm-server-initiated-edits' > (had crap semantics anyway) and replaced it with a shiny new > 'eglot-confirm-server-edits', with a simpler name but much more powerful > (see its docstring). > [...] > > Please have a look, give it some testing, and tell me if I missed > anything. Great stuff! One issue I came across is with unsaved buffers. Here's a recipe: With emacs -Q, set `eglot-confirm-server-edits` to `diff`. In a fresh git repository, create a new file `foo.go` and insert the following: --8<---------------cut here---------------start------------->8--- package baz type Foobar interface {} --8<---------------cut here---------------end--------------->8--- Now save the file, and do `M-x go-ts-mode` followed by `M-x eglot` to connect to an LSP server (`gopls` in my case). Without saving the buffer, insert `type Baz interface {}` after the last line: --8<---------------cut here---------------start------------->8--- package baz type Foobar interface {} type Baz interface {} --8<---------------cut here---------------end--------------->8--- With point on `Baz`, do `M-x eglot-rename RET Spam RET`. Emacs displays the following diff in *EGLOT proposed server changes*: --8<---------------cut here---------------start------------->8--- diff -u /Users/eshelyaron/tmp/bug/foo.go /var/folders/q1/h0vdt_hx00zgbv3bpy= x2vdr00000gp/T/buffer-content-sgzkbC --- /Users/eshelyaron/tmp/bug/foo.go 2023-09-01 20:55:02 +++ /var/folders/q1/h0vdt_hx00zgbv3bpyx2vdr00000gp/T/buffer-content-sgzkbC = 2023-09-01 20:55:07 @@ -1,3 +1,4 @@ package baz =20 type Foobar interface {} +Spam \ No newline at end of file Diff finished. Fri Sep 1 20:55:08 2023 --8<---------------cut here---------------end--------------->8--- We clearly get an incorrect patch. It seems like the patch is produced by comparing the modified version of the buffer to the visited file, instead of comparing it to the current buffer contents. Another, smaller issue is that while `eglot-rename` is creating the patch it prints messages along the lines of: [eglot] applying 1 edits to `*temp*-207900' Which feels less appropriate in these settings. Lastly, I have an improvement suggestion for the `:type` of `eglot-confirm-server-edits` to make it nicer to deal with via Custom: diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 8d95019c3ed..afb99e4b9ca 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -413,12 +413,17 @@ eglot-confirm-server-edits `eglot-code-actions', `eglot-code-action-quickfix', etc. ACTION is one of the symbols described above. The value `t' for COMMAND is accepted and its ACTION is the default value." - :type '(choice (const :tag "Use diff" diff) + :type (let ((basic-choices + '((const :tag "Use diff" diff) (const :tag "Summarize and prompt" summary) (const :tag "Maybe use diff" maybe-diff) (const :tag "Maybe summarize and prompt" maybe-summary) - (const :tag "Don't confirm" nil) - (alist :tag "Per-command alist"))) + (const :tag "Don't confirm" nil)))) + `(choice ,@basic-choices + (alist :tag "Per-command alist" + :key-type (choice (function :tag "Command") + (const :tag "Default" t)) + :value-type (choice . ,basic-choices))))) =20 (defcustom eglot-extend-to-xref nil "If non-nil, activate Eglot in cross-referenced non-project files."