Subject: bug#70929: 30.0.50; eglot--apply-text-edits prevents point adjustment

From: Felician Nemeth <[email-masked]>
Date: Tue, 14 May 2024 07:30:04 +0200

Troy Brown <[email-masked]> writes:

> 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.

If I remember correctly, the LSP specification does not say where the
point should be after onTypeFormatting.  Something like this motivated
the rust-analyzer developers to introduce their own SnippetTextEdit
extension.  The upcoming LSP version is going to contain a slightly
different version of the SnippetTextEdit.

If my memories are correct, Ada Language Server should use this
SnippetTextEdit to unambiguously communicate its intent here.  (However,
Eglot does not currently supports SnippetTextEdit.)