Subject: Re: bug#61478: 28.2; eglot keeps sending `didSave` notifications despite the active server not supporting `textDocumentSync`

From: ~kby <[email-masked]>
Date: Mon, 13 Feb 2023 20:00:37 +0100

This should suffice, no?

On 13.02.23 19:44, João Távora wrote:
> Yep, Felician, that is exactly it. Should be a straightforward patch. 
> I'll do it, if noone beats me to it.
>
> João
>
> On Mon, Feb 13, 2023, 18:30 Felician Nemeth 
> <[email-masked]> wrote:
>
>     > - Following text appears in the minibuffer area: `[eglot] Server
>     >   reports (type=1): Unknown method textDocument/didSave`
>
>     Without actually looking into the details, this feels similar to an
>     earlier issue, which I unfortunately closed:
>     https://github.com/joaotavora/eglot/issues/360
>
>     The commit referenced in #360 only fixed the willSave part.  I
>     guess the
>     solution to this bug report should be probably similar to that fix:
>     Eglot should check (eglot--server-capable :textDocumentSync :save)
>     before sending a textDocument/didSave.
>

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 8ecdefd490d..267a7a5ea23 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2496,13 +2496,14 @@ When called interactively, use the currently active server"
 (defun eglot--signal-textDocument/didSave ()
   "Send textDocument/didSave to server."
   (eglot--signal-textDocument/didChange)
-  (jsonrpc-notify
-   (eglot--current-server-or-lose)
-   :textDocument/didSave
-   (list
-    ;; TODO: Handle TextDocumentSaveRegistrationOptions to control this.
-    :text (buffer-substring-no-properties (point-min) (point-max))
-    :textDocument (eglot--TextDocumentIdentifier))))
+  (when (eglot--server-capable :textDocumentSync :save)
+    (jsonrpc-notify
+     (eglot--current-server-or-lose)
+     :textDocument/didSave
+     (list
+      ;; TODO: Handle TextDocumentSaveRegistrationOptions to control this.
+      :text (buffer-substring-no-properties (point-min) (point-max))
+      :textDocument (eglot--TextDocumentIdentifier)))))
 
 (defun eglot-flymake-backend (report-fn &rest _more)
   "A Flymake backend for Eglot.