]> git.eshelyaron.com Git - emacs.git/commitdiff
Expand directory watcher globs containing ** ()
authorJürgen Hötzel <juergen@archlinux.org>
Mon, 12 Aug 2019 20:13:47 +0000 (22:13 +0200)
committerJoão Távora <joaotavora@gmail.com>
Mon, 12 Aug 2019 20:13:47 +0000 (21:13 +0100)
Previously, if the server requested a glob pattern like foo/**/*
to be watched, we would just error.  Now we watch foo/bar/ and
foo/baz/ as if the server had requested those two watchers
instead of just the one with the **.

As a limitation, the implementation of file-expand-wildcards
doesn't fully handle ** globstars (** matches at most one path
segment).

* eglot.el (eglot-register-capability workspace/didChangeWatchedFiles):
Use file-expand-wildcards to make a ** glob into multiple **-less
globs.

GitHub-reference: https://github.com/joaotavora/eglot/issues/293

lisp/progmodes/eglot.el

index a80be22e6ba8001ba5da8d123056f088870190f3..6078e97cdcdddfcc21ebe1218d317293710966a5 100644 (file)
@@ -2371,7 +2371,10 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp."
   (let* (success
          (globs (mapcar (eglot--lambda ((FileSystemWatcher) globPattern)
                           globPattern)
-                        watchers)))
+                        watchers))
+        (glob-dirs
+         (delete-dups (mapcar #'file-name-directory
+                              (mapcan #'file-expand-wildcards globs)))))
     (cl-labels
         ((handle-event
           (event)
@@ -2394,13 +2397,14 @@ If SKIP-SIGNATURE, don't try to send textDocument/signatureHelp."
               (handle-event '(desc 'deleted file))
               (handle-event '(desc 'created file1)))))))
       (unwind-protect
-          (progn (dolist (dir (delete-dups (mapcar #'file-name-directory globs)))
-                   (push (file-notify-add-watch dir '(change) #'handle-event)
-                         (gethash id (eglot--file-watches server))))
-                 (setq
-                  success
-                  `(:message ,(format "OK, watching %s watchers"
-                                      (length watchers)))))
+          (progn
+           (dolist (dir glob-dirs)
+             (push (file-notify-add-watch dir '(change) #'handle-event)
+                   (gethash id (eglot--file-watches server))))
+           (setq
+            success
+            `(:message ,(format "OK, watching %s directories in %s watchers"
+                                (length glob-dirs) (length watchers)))))
         (unless success
           (eglot-unregister-capability server method id))))))