From: Jürgen Hötzel <juergen@archlinux.org>
Date: Mon, 12 Aug 2019 20:13:47 +0000 (+0200)
Subject: Expand directory watcher globs containing ** ()
X-Git-Tag: emacs-29.0.90~1616^2~524^2~4^2~321
X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f18137499d46ab4e2210d8190d09cea84834f8d3;p=emacs.git

Expand directory watcher globs containing ** ()

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
---

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index a80be22e6ba..6078e97cdcd 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -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))))))