]> git.eshelyaron.com Git - emacs.git/commitdiff
Eglot: also add watches for newly created directories
authorJoão Távora <joaotavora@gmail.com>
Thu, 8 Jun 2023 12:12:49 +0000 (13:12 +0100)
committerJoão Távora <joaotavora@gmail.com>
Thu, 8 Jun 2023 14:09:45 +0000 (15:09 +0100)
GitHub-reference: https://github.com/joaotavora/eglot/pull/1228
GitHub-reference: https://github.com/joaotavora/eglot/discussions/1226

* lisp/progmodes/eglot.el (eglot-register-capability): Rework.

Suggested by: https://github.com/thejeffphil

lisp/progmodes/eglot.el

index c171cc2597a152bf2b4ae64ebe814e2294b6e741..c5a58d7ace643dc0db436653edb52e1a89b254c8 100644 (file)
@@ -3543,8 +3543,7 @@ at point.  With prefix argument, prompt for ACTION-KIND."
                                (project-files
                                 (eglot--project server))))))
     (cl-labels
-        ((handle-event
-           (event)
+        ((handle-event (event)
            (pcase-let* ((`(,desc ,action ,file ,file1) event)
                         (action-type (cl-case action
                                        (created 1) (changed 2) (deleted 3)))
@@ -3558,19 +3557,24 @@ at point.  With prefix argument, prompt for ACTION-KIND."
                (jsonrpc-notify
                 server :workspace/didChangeWatchedFiles
                 `(:changes ,(vector `(:uri ,(eglot--path-to-uri file)
-                                           :type ,action-type)))))
+                                           :type ,action-type))))
+               (when (and (eq action 'created)
+                          (file-directory-p file))
+                 (watch-dir file)))
               ((eq action 'renamed)
                (handle-event `(,desc 'deleted ,file))
-               (handle-event `(,desc 'created ,file1)))))))
+               (handle-event `(,desc 'created ,file1))))))
+         (watch-dir (dir)
+           (when-let ((probe
+                       (and (file-readable-p dir)
+                            (or (gethash dir (eglot--file-watches server))
+                                (puthash dir (list (file-notify-add-watch
+                                                    dir '(change) #'handle-event))
+                                         (eglot--file-watches server))))))
+             (push id (cdr probe)))))
       (unwind-protect
           (progn
-            (cl-loop for dir in dirs-to-watch
-                     for probe =
-                     (and (file-readable-p dir)
-                          (or (gethash dir (eglot--file-watches server))
-                              (puthash dir (list (file-notify-add-watch dir '(change) #'handle-event))
-                                       (eglot--file-watches server))))
-                     when probe do (push id (cdr probe)))
+            (mapc #'watch-dir dirs-to-watch)
             (setq
              success
              `(:message ,(format "OK, watching %s directories in %s watchers"