]> git.eshelyaron.com Git - emacs.git/commitdiff
More correctly keep track of didopen/didclose per buffer
authorJoão Távora <joaotavora@gmail.com>
Fri, 4 May 2018 00:20:13 +0000 (01:20 +0100)
committerJoão Távora <joaotavora@gmail.com>
Fri, 4 May 2018 10:14:49 +0000 (11:14 +0100)
* eglot.el (eglot--buffer-open-count): Now a process-local var.
(eglot--signal-textDocument/didOpen, eglot--signal-textDocument/didClose):
Use it.

lisp/progmodes/eglot.el

index bdd339d97151146bff2c79f3ec8ca146b5cb1f3e..ac52b9adab92827309a9bbb23987e6179ef1664a 100644 (file)
@@ -138,6 +138,9 @@ A list (WHAT SERIOUS-P)." t)
 Must be a function of one arg, a name, returning a process
 object.")
 
+(eglot--define-process-var eglot--buffer-open-count (make-hash-table)
+  "Keeps track of didOpen/didClose notifs for each buffer.")
+
 (defun eglot-make-local-process (name command)
   "Make a local LSP process from COMMAND.
 NAME is a name to give the inferior process or connection.
@@ -1026,26 +1029,35 @@ Records START, END and PRE-CHANGE-LENGTH locally."
   (setq eglot--recent-before-changes nil
         eglot--recent-after-changes nil))
 
-(defvar-local eglot--buffer-open-count 0)
 (defun eglot--signal-textDocument/didOpen ()
   "Send textDocument/didOpen to server."
-  (cl-incf eglot--buffer-open-count)
-  (when (> eglot--buffer-open-count 1)
-    (error "Too many textDocument/didOpen notifs for %s" (current-buffer)))
-  (eglot--notify (eglot--current-process-or-lose)
-                 :textDocument/didOpen
-                 (eglot--obj :textDocument
-                             (eglot--current-buffer-TextDocumentItem))))
+  (let* ((proc (eglot--current-process-or-lose))
+         (count (1+ (or (gethash (current-buffer)
+                                 (eglot--buffer-open-count proc))
+                        0))))
+    (when (> count 1)
+      (eglot--error "Too many textDocument/didOpen notifs for %s" (current-buffer)))
+    (setf (gethash (current-buffer) (eglot--buffer-open-count proc))
+          count)
+    (eglot--notify proc
+                   :textDocument/didOpen
+                   (eglot--obj :textDocument
+                               (eglot--current-buffer-TextDocumentItem)))))
 
 (defun eglot--signal-textDocument/didClose ()
   "Send textDocument/didClose to server."
-  (cl-decf eglot--buffer-open-count)
-  (when (< eglot--buffer-open-count 0)
-    (error "Too many textDocument/didClose notifs for %s" (current-buffer)))
-  (eglot--notify (eglot--current-process-or-lose)
-                 :textDocument/didClose
-                 (eglot--obj :textDocument
-                             (eglot--current-buffer-TextDocumentItem))))
+  (let* ((proc (eglot--current-process-or-lose))
+         (count (1- (or (gethash (current-buffer)
+                                 (eglot--buffer-open-count proc))
+                        0))))
+    (when (< count 0)
+      (eglot--error "Too many textDocument/didClose notifs for %s" (current-buffer)))
+    (setf (gethash (current-buffer) (eglot--buffer-open-count proc))
+          count)
+    (eglot--notify proc
+                   :textDocument/didClose
+                   (eglot--obj :textDocument
+                               (eglot--current-buffer-TextDocumentItem)))))
 
 (defun eglot--signal-textDocument/willSave ()
   "Send textDocument/willSave to server."