From f18137499d46ab4e2210d8190d09cea84834f8d3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20H=C3=B6tzel?= Date: Mon, 12 Aug 2019 22:13:47 +0200 Subject: [PATCH] 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 --- lisp/progmodes/eglot.el | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) 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)))))) -- 2.39.2