Subject: bug#73857: closed (Re: bug#73857: [PATCH] * lisp/progmodes/eglot.el: add support for insertReplaceEdit)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 13 Feb 2025 10:48:02 +0000

Your bug report

#73857: [PATCH] * lisp/progmodes/eglot.el: add support for insertReplaceEdit

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
73857: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=73857
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#73857: [PATCH] * lisp/progmodes/eglot.el: add support for insertReplaceEdit
From: Stefan Kangas <[email-masked]>
To: João Távora <[email-masked]>
Cc: Dmitry Gutov <[email-masked]>, Eli Zaretskii <[email-masked]>, [email-masked], [email-masked]
Date: Thu, 13 Feb 2025 02:47:02 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

João Távora <[email-masked]> writes:

> I've added a variation on Casey's patch, perhaps I forgot to send
> email to close this bug:
>
> commit 1143cf09a339d57051a4341103c9e342d8876649
> Author: João Távora <[email-masked]>
> Date:   Mon Jan 20 18:58:05 2025 +0000
>
>     Eglot: add support for insertReplaceEdit (bug#73857)
>
>     * lisp/progmodes/eglot.el (eglot-server-programs): Mention zig-ts-mode.
>     (eglot--lsp-interface-alist): Describe 'InsertReplaceEdit'.
>     (eglot-client-capabilities): Advertise 'insertReplaceSupport'.
>     (eglot-completion-at-point): Consider 'InsertReplaceEdit'.
>     (eglot--apply-text-edits): Consider 'InsertReplaceEdit'.
>
>     * test/lisp/progmodes/eglot-tests.el
>     (eglot-test-zig-insert-replace-completion): New test.
>
>     Special thanks to [email-masked]
>
> Added a zig test, too.

OK, thanks.  I'm therefore closing this bug report now.

Subject: [PATCH] * lisp/progmodes/eglot.el: add support for insertReplaceEdit
From: Casey Banner <[email-masked]>
To: [email-masked]
Date: Thu, 17 Oct 2024 20:54:38 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Since 3.16, LSP supports the capability `insertReplaceSupport`. This
allows textEdit to be an `InsertReplaceEdit` see:
(
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#insertReplaceEdit
)

This patch adds support for this capability, and uses the `replace`
field of the `InsertReplaceEdit`. Original functionality (ie.
`TextEdit`) is preserved.

The benefits of this were originally discussed here:
https://github.com/joaotavora/eglot/discussions/1456, but this is a summary:

Consider this file:

```
const Foo = struct {
    correct_name: u32,
};

fn example(foo: Foo) u32 {
    return foo.correct_name;
}
```

1. Place the cursor on 6:22 (the _ in correct_name)
2. Backspace once to delete the t
3. Receive the following LSP message: `<-- textDocument/completion[20]
{"jsonrpc":"2.0","id":20,"result":{"isIncomplete":false,"items":[{"label":"correct_name","kind":5,"detail":"u32","documentation":{"kind":"plaintext","value":""},"sortText":"2_correct_name","textEdit":{"range":{"start":{"line":5,"character":15},"end":{"line":5,"character":21}},"newText":"correct_name"}}]}}`
4. Accept the completion
5. The buffer now contains `    return foo.correct_name_name;` on line 6

I expected it to replace the entire token, resulting in `    return
foo.correct_name;`.

Indeed with this patch applied (and an LSP that supports the
capability), the behaviour I expected is now what happens.

This is the first real elisp that I've written besides configuration, so
I'm not sure if this is the correct way, but it seems to work for me.

Patch is attached.

Thanks!
Casey

In GNU Emacs 30.0.91 (build 1, x86_64-w64-mingw32) of 2024-10-17 built
 on DESKTOP-EK25TL1
Repository revision: 50620e96d763bd21854a95c580b572687eebc319
Repository branch: eglot_insert_replace_edit
Windowing system distributor 'Microsoft Corp.', version 10.0.19045
System Description: Microsoft Windows 10 Pro (v10.0.2009.19045.5011)

Configured using:
 'configure -prefix=/e/dev/emacs-src --without-dbus --without-pop
 --with-native-compilation --with-xml2 --with-wide-int
 --without-compress-install 'CFLAGS=-O2 -mtune=native -march=native
 -fomit-frame-pointer -ftree-vectorize'
 PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig'