From: João Távora Date: Thu, 8 Jun 2023 12:12:49 +0000 (+0100) Subject: Eglot: also add watches for newly created directories X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=976cb7e0e6561e10cebcf89c861b8f9f0e2934cb;p=emacs.git 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 --- 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"