]> git.eshelyaron.com Git - emacs.git/commitdiff
Prefer documentchanges to changes in server-initiated edits
authorTheodor Thornhill <theo@thornhill.no>
Fri, 9 Sep 2022 21:25:50 +0000 (23:25 +0200)
committerGitHub <noreply@github.com>
Fri, 9 Sep 2022 21:25:50 +0000 (22:25 +0100)
Some servers return both.

PR: https://github.com/joaotavora/eglot/issues/949

* eglot.el (eglot--apply-workspace-edit): When both documentChanges
and changes are present, prefer the documentChanges.  By doing that we
ensure that we don't double edit, rendering the document in an
unusable state.

GitHub-reference: fix https://github.com/joaotavora/eglot/issues/704

lisp/progmodes/eglot.el

index 80f0b654706d202412ce9077f32c054fa4cbfa21..e399b29f09f429ea04836850be9e54e381df15f3 100644 (file)
@@ -3016,8 +3016,12 @@ Returns a list as described in docstring of `imenu--index-alist'."
                          textDocument
                        (list (eglot--uri-to-path uri) edits version)))
                    documentChanges)))
-      (cl-loop for (uri edits) on changes by #'cddr
-               do (push (list (eglot--uri-to-path uri) edits) prepared))
+      (unless (and changes documentChanges)
+        ;; We don't want double edits, and some servers send both
+        ;; changes and documentChanges.  This unless ensures that we
+        ;; prefer documentChanges over changes.
+        (cl-loop for (uri edits) on changes by #'cddr
+                 do (push (list (eglot--uri-to-path uri) edits) prepared)))
       (if (or confirm
               (cl-notevery #'find-buffer-visiting
                            (mapcar #'car prepared)))