]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't rely on flymake's idle timer for textdocument/didchange
authorJoão Távora <joaotavora@gmail.com>
Sat, 26 May 2018 15:11:11 +0000 (16:11 +0100)
committerJoão Távora <joaotavora@gmail.com>
Sat, 26 May 2018 15:26:45 +0000 (16:26 +0100)
* eglot.el (eglot--after-change): Set idle timer here.
(eglot--change-idle-timer): New var.
(eglot--signal-textDocument/didChange): No seed to set spinner here.
(eglot-flymake-backend) Don't send didChange here.

lisp/progmodes/eglot.el

index 3d363444405d6f9dd3691921af71e96f3cec88be..8fe24ed19789dcce93a0a8eab664f0f3a5a1dcac 100644 (file)
@@ -1131,6 +1131,8 @@ THINGS are either registrations or unregisterations."
   (cl-plusp (+ (length (car eglot--recent-changes))
                (length (cdr eglot--recent-changes)))))
 
+(defvar eglot--change-idle-timer nil "Idle timer for textDocument/didChange.")
+
 (defun eglot--before-change (start end)
   "Hook onto `before-change-functions'.
 Records START and END, crucially convert them into
@@ -1149,7 +1151,12 @@ Records START, END and PRE-CHANGE-LENGTH locally."
   (setf (cdr eglot--recent-changes)
         (vconcat (cdr eglot--recent-changes)
                  `[(,pre-change-length
-                    ,(buffer-substring-no-properties start end))])))
+                    ,(buffer-substring-no-properties start end))]))
+  (when eglot--change-idle-timer (cancel-timer eglot--change-idle-timer))
+  (setq eglot--change-idle-timer
+        (run-with-idle-timer
+         0.5 nil (lambda () (eglot--signal-textDocument/didChange)
+                   (setq eglot--change-idle-timer nil)))))
 
 (defun eglot--signal-textDocument/didChange ()
   "Send textDocument/didChange to server."
@@ -1166,8 +1173,7 @@ Records START, END and PRE-CHANGE-LENGTH locally."
         (eglot--notify
          server :textDocument/didChange
          (eglot--obj
-          :textDocument
-          (eglot--VersionedTextDocumentIdentifier)
+          :textDocument (eglot--VersionedTextDocumentIdentifier)
           :contentChanges
           (if full-sync-p (vector
                            (eglot--obj
@@ -1180,7 +1186,6 @@ Records START, END and PRE-CHANGE-LENGTH locally."
                                             :rangeLength len
                                             :text after-text)])))))
       (setq eglot--recent-changes (cons [] []))
-      (setf (eglot--spinner server) (list nil :textDocument/didChange t))
       (eglot--call-deferred server))))
 
 (defun eglot--signal-textDocument/didOpen ()
@@ -1225,9 +1230,7 @@ Calls REPORT-FN maybe if server publishes diagnostics in time."
   ;; Report anything unreported
   (when eglot--unreported-diagnostics
     (funcall report-fn eglot--unreported-diagnostics)
-    (setq eglot--unreported-diagnostics nil))
-  ;; Signal a didChange that might eventually bring new diagnotics
-  (eglot--signal-textDocument/didChange))
+    (setq eglot--unreported-diagnostics nil)))
 
 (defun eglot-xref-backend ()
   "EGLOT xref backend."