emacs-diffs
[Top][All Lists]
Advanced

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

master 976cb7e0e65 2/2: Eglot: also add watches for newly created direct


From: João Távora
Subject: master 976cb7e0e65 2/2: Eglot: also add watches for newly created directories
Date: Thu, 8 Jun 2023 10:09:59 -0400 (EDT)

branch: master
commit 976cb7e0e6561e10cebcf89c861b8f9f0e2934cb
Author: João Távora <joaotavora@gmail.com>
Commit: João Távora <joaotavora@gmail.com>

    Eglot: also add watches for newly created directories
    
    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 | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index c171cc2597a..c5a58d7ace6 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -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"



reply via email to

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