]> git.eshelyaron.com Git - emacs.git/commitdiff
(eglot--signal-textDocument/didChange): Fix tests
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 19 Apr 2024 03:39:30 +0000 (23:39 -0400)
committerEshel Yaron <me@eshelyaron.com>
Sat, 20 Apr 2024 11:08:24 +0000 (14:08 +0300)
The tests call `eglot--signal-textDocument/didChange` eagerly,
which means in the case where we use `track-changes` that they
call it before the tracker's signal has been called.
So make sure we fetch pending changes even if we haven't yet
been notified of them, and make sure `eglot--versioned-identifier`
is incremented even when the signal is not called.

* lisp/progmodes/eglot.el (eglot--track-changes-fetch)
(eglot--after-change): Increment `eglot--versioned-identifier` here...
(eglot--track-changes-signal): ...instead of here.
(eglot--signal-textDocument/didChange): Try and fetch changes even if the
tracker's signal wasn't called yet.

* test/lisp/progmodes/eglot-tests.el (eglot-tests--get): New function.
(eglot-tests--lsp-abiding-column-1): Use it.

(cherry picked from commit c833892140fbf4be45161bf85d4c1253c5503949)

lisp/progmodes/eglot.el
test/lisp/progmodes/eglot-tests.el

index 122a1d06435fa36e5c32ec4d9843060e9c3c3fc4..29a274fb338f2c6b3656541c5a77a15c823fb0c4 100644 (file)
@@ -2626,6 +2626,7 @@ buffer."
 (defun eglot--after-change (beg end pre-change-length)
   "Hook onto `after-change-functions'.
 Records BEG, END and PRE-CHANGE-LENGTH locally."
+  (cl-incf eglot--versioned-identifier)
   (pcase (car-safe eglot--recent-changes)
     (`(,lsp-beg ,lsp-end
                 (,b-beg . ,b-beg-marker)
@@ -2659,6 +2660,7 @@ Records BEG, END and PRE-CHANGE-LENGTH locally."
   (if (eq eglot--recent-changes :pending) (setq eglot--recent-changes nil))
   (track-changes-fetch
    id (lambda (beg end before)
+        (cl-incf eglot--versioned-identifier)
         (cond
          ((eq eglot--recent-changes :emacs-messup) nil)
          ((eq before 'error) (setf eglot--recent-changes :emacs-messup))
@@ -2669,7 +2671,6 @@ Records BEG, END and PRE-CHANGE-LENGTH locally."
                   eglot--recent-changes))))))
 
 (defun eglot--track-changes-signal (id &optional distance)
-  (cl-incf eglot--versioned-identifier)
   (cond
    (distance
     ;; When distance is <100, we may as well coalesce the changes.
@@ -2790,9 +2791,9 @@ When called interactively, use the currently active server"
 
 (defun eglot--signal-textDocument/didChange ()
   "Send textDocument/didChange to server."
+  (when eglot--track-changes
+    (eglot--track-changes-fetch eglot--track-changes))
   (when eglot--recent-changes
-    (when eglot--track-changes
-      (eglot--track-changes-fetch eglot--track-changes))
     (let* ((server (eglot--current-server-or-lose))
            (sync-capability (eglot-server-capable :textDocumentSync))
            (sync-kind (if (numberp sync-capability) sync-capability
index 4725885038e5d615f054fe6bb9fa53f34b016358..e501e24f5d21bb830688d689bf9c63ad512f2d1f 100644 (file)
@@ -821,6 +821,12 @@ int main() {
         (should (looking-back "\"foo.bar\": \""))
         (should (looking-at "fb\"$"))))))
 
+(defun eglot-tests--get (object path)
+  (dolist (op path)
+    (setq object (if (natnump op) (aref object op)
+                  (plist-get object op))))
+  object)
+
 (defun eglot-tests--lsp-abiding-column-1 ()
   (eglot--with-fixture
       '(("project" .
@@ -837,7 +843,11 @@ int main() {
           (insert "p ")
           (eglot--signal-textDocument/didChange)
           (eglot--wait-for (c-notifs 2) (&key params &allow-other-keys)
-            (should (equal 71 (cadddr (cadadr (aref (cadddr params) 0))))))
+            (message "PARAMS=%S" params)
+            (should (equal 71 (eglot-tests--get
+                               params
+                               '(:contentChanges 0
+                                 :range :start :character)))))
           (beginning-of-line)
           (should (eq eglot-move-to-linepos-function #'eglot-move-to-utf-16-linepos))
           (funcall eglot-move-to-linepos-function 71)