GNU bug report logs - #73857
[PATCH] * lisp/progmodes/eglot.el: add support for insertReplaceEdit

Previous Next

Package: emacs;

Reported by: Casey Banner <kcbanner <at> gmail.com>

Date: Fri, 18 Oct 2024 00:56:02 UTC

Severity: wishlist

Tags: patch

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#73857: closed ([PATCH] * lisp/progmodes/eglot.el: add support
 for insertReplaceEdit)
Date: Thu, 13 Feb 2025 10:48:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Thu, 13 Feb 2025 02:47:02 -0800
with message-id <CADwFkmnMuX+yARnq=S3NUQrhkC9D9qAvEct5oXTQH8mJ_JEgsw <at> mail.gmail.com>
and subject line Re: bug#73857: [PATCH] * lisp/progmodes/eglot.el: add support for insertReplaceEdit
has caused the debbugs.gnu.org bug report #73857,
regarding [PATCH] * lisp/progmodes/eglot.el: add support for insertReplaceEdit
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
73857: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=73857
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Casey Banner <kcbanner <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] * lisp/progmodes/eglot.el: add support for insertReplaceEdit
Date: Thu, 17 Oct 2024 20:54:38 -0400
[Message part 3 (text/plain, inline)]
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'
[Message part 4 (text/html, inline)]
[0001-lisp-progmodes-eglot.el-add-support-for-insertReplac.patch (application/octet-stream, attachment)]
[Message part 6 (message/rfc822, inline)]
From: Stefan Kangas <stefankangas <at> gmail.com>
To: João Távora <joaotavora <at> gmail.com>
Cc: Dmitry Gutov <dmitry <at> gutov.dev>, Eli Zaretskii <eliz <at> gnu.org>,
 73857-done <at> debbugs.gnu.org, kcbanner <at> gmail.com
Subject: Re: bug#73857: [PATCH] * lisp/progmodes/eglot.el: add support for
 insertReplaceEdit
Date: Thu, 13 Feb 2025 02:47:02 -0800
João Távora <joaotavora <at> gmail.com> 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 <joaotavora <at> gmail.com>
> 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 kcbanner <at> gmail.com
>
> Added a zig test, too.

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


This bug report was last modified 156 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.