emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master c833892140f: (eglot--signal-textDocument/didChange): Fix tests


From: Stefan Monnier
Subject: master c833892140f: (eglot--signal-textDocument/didChange): Fix tests
Date: Thu, 18 Apr 2024 23:39:39 -0400 (EDT)

branch: master
commit c833892140fbf4be45161bf85d4c1253c5503949
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    (eglot--signal-textDocument/didChange): Fix tests
    
    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.
---
 lisp/progmodes/eglot.el            |  7 ++++---
 test/lisp/progmodes/eglot-tests.el | 12 +++++++++++-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 90a607075d3..d8eb1f1ee83 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -2625,6 +2625,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)
@@ -2658,6 +2659,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))
@@ -2668,7 +2670,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.
@@ -2789,9 +2790,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
diff --git a/test/lisp/progmodes/eglot-tests.el 
b/test/lisp/progmodes/eglot-tests.el
index 4725885038e..e501e24f5d2 100644
--- a/test/lisp/progmodes/eglot-tests.el
+++ b/test/lisp/progmodes/eglot-tests.el
@@ -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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]