From: Philip Kaludercic <philipk@posteo.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 60338@debbugs.gnu.org, joaotavora@gmail.com
Subject: bug#60338: [PATCH] Add option to present server changes as diffs
Date: Mon, 12 Jun 2023 12:35:09 +0000 [thread overview]
Message-ID: <877cs8g8oy.fsf@posteo.net> (raw)
In-Reply-To: <83jzw8yjv5.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 12 Jun 2023 14:56:30 +0300")
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Philip Kaludercic <philipk@posteo.net>
>> Date: Sun, 11 Jun 2023 21:33:40 +0000
>>
>> + ((eq confirm 'diff)
>> + (with-current-buffer (get-buffer-create " *Changes*")
>> + (buffer-disable-undo (current-buffer))
>> + (let ((buffer-read-only t))
>> + (diff-mode))
>> + (let ((inhibit-read-only t)
>> + (target (current-buffer)))
>> + (erase-buffer)
>> + (pcase-dolist (`(,path ,edits ,_) prepared)
>> + (with-temp-buffer
>> + (let ((diff (current-buffer)))
>> + (with-temp-buffer
>> + (insert-file-contents path)
>> + (eglot--apply-text-edits edits)
>> + (diff-no-select path (current-buffer)
>> + nil t diff))
>
> Isn't there a better way of presenting the edits in human-readable
> form than apply them and then run Diff? What format is used by the
> server itself to send the edits?
The server sends a JSON message. Here is an example from a little toy
project of mine in C, where I intentionally uncommented a #include
directive:
--8<---------------cut here---------------start------------->8---
(:id 51 :jsonrpc "2.0" :result
[(:diagnostics
[(:code "-Wimplicit-function-declaration" :message "Implicitly declaring library function 'strcmp' with type 'int (const char *, const char *)' (fix available)" :range
(:end
(:character 21 :line 63)
:start
(:character 15 :line 63))
:severity 2 :source "clang")]
:edit
(:changes
(:file:///home/philip/Source/sgo/sgo.c
[(:newText "#include <string.h>\n" :range
(:end
(:character 0 :line 25)
:start
(:character 0 :line 25)))]))
:isPreferred t :kind "quickfix" :title "Include <string.h> for symbol strcmp")])
--8<---------------cut here---------------end--------------->8---
The server gives me a diagnostic and suggests a change. The change is
just a replacement of a text range with a string:
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textEdit
> Besides, this assumes the 'diff' command is available, which is not
> portable -- one more reason not to go that way, or at leas provide an
> alternative.
I am personally fond of this approach, because I get a regular text
buffer that I can store or send someone. The fact that diff is not
available everywhere (even though I would guess any system with a
language server /should/ have diff installed), is an argument against
enabling this behaviour by default, not against providing this interface.
--
Philip Kaludercic
next prev parent reply other threads:[~2023-06-12 12:35 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-26 13:42 bug#60338: [PATCH] Add option to present server changes as diffs Philip Kaludercic
2022-12-29 0:01 ` Yuan Fu
2022-12-29 14:28 ` Philip Kaludercic
2022-12-29 14:36 ` João Távora
2022-12-29 14:39 ` Philip Kaludercic
2022-12-30 13:13 ` João Távora
2022-12-30 15:09 ` Philip Kaludercic
2023-01-04 20:56 ` Felician Nemeth
2023-06-09 7:55 ` Philip Kaludercic
2023-06-11 21:33 ` Philip Kaludercic
2023-06-12 11:56 ` Eli Zaretskii
2023-06-12 12:35 ` Philip Kaludercic [this message]
2023-06-12 12:52 ` Eli Zaretskii
2023-06-12 13:29 ` Philip Kaludercic
2023-06-12 13:41 ` Eli Zaretskii
2023-06-13 21:34 ` Philip Kaludercic
2023-06-14 6:00 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-06-14 11:27 ` Philip Kaludercic
2023-06-18 11:38 ` Philip Kaludercic
2023-06-18 15:18 ` João Távora
2023-06-18 22:37 ` João Távora
2023-06-24 16:53 ` Philip Kaludercic
2023-09-01 0:06 ` João Távora
2023-09-01 5:18 ` Philip Kaludercic
2023-09-01 21:12 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-01 21:19 ` João Távora
2023-09-01 22:01 ` João Távora
2023-09-02 6:13 ` Eshel Yaron via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-02 9:55 ` João Távora
2023-09-07 1:00 ` Dmitry Gutov
2023-09-07 6:28 ` Juri Linkov
2023-09-07 12:41 ` Dmitry Gutov
2023-09-07 12:45 ` Dmitry Gutov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877cs8g8oy.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=60338@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=joaotavora@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.