Skip to content

Commit

Permalink
Expand directory watcher globs containing ** (#293)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
juergenhoetzel authored and joaotavora committed Aug 12, 2019
1 parent f45fdc6 commit 6a7ce66
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions eglot.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))))))

Expand Down

0 comments on commit 6a7ce66

Please sign in to comment.