From be1745606354e8b34325bc9526c9bad9f7302cce Mon Sep 17 00:00:00 2001 From: Brian Leung Date: Tue, 2 Feb 2021 11:23:25 -0800 Subject: [PATCH] Make Eglot consider FileSystemWatcher.kind when watching files bug#58677 * eglot.el (eglot-register-capability workspace/didChangeWatchedFiles): Rework Only send notifications of interest, as determined by the optional LSP FileSystemWatcher.kind bitmask provided by the server. When the FileSystemWatcher.kind property is omitted, use the default value of 7, which is computed from taking the bitwise OR operation WatchKind.Create (1) | WatchKind.Change (2) | WatchKind.Delete (4). --- lisp/progmodes/eglot.el | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 167fd129a5c..63ebbe6caba 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -3265,8 +3265,12 @@ at point. With prefix argument, prompt for ACTION-KIND." (eglot-unregister-capability server method id) (let* (success (globs (mapcar - (eglot--lambda ((FileSystemWatcher) globPattern) - (eglot--glob-compile globPattern t t)) + (eglot--lambda ((FileSystemWatcher) globPattern kind) + (cons (eglot--glob-compile globPattern t t) + ;; the default "7" means bitwise OR of + ;; WatchKind.Create (1), WatchKind.Change + ;; (2), WatchKind.Delete (4) + (or kind 7))) watchers)) (dirs-to-watch (delete-dups (mapcar #'file-name-directory @@ -3275,17 +3279,20 @@ at point. With prefix argument, prompt for ACTION-KIND." (cl-labels ((handle-event (event) - (pcase-let ((`(,desc ,action ,file ,file1) event)) + (pcase-let* ((`(,desc ,action ,file ,file1) event) + (action-type (cl-case action + (created 1) (changed 2) (deleted 3))) + (action-bit (when action-type + (ash 1 (1- action-type))))) (cond ((and (memq action '(created changed deleted)) - (cl-find file globs :test (lambda (f g) (funcall g f)))) + (cl-loop for (glob . kind-bitmask) in globs + thereis (and (> (logand kind-bitmask action-bit) 0) + (funcall glob file)))) (jsonrpc-notify server :workspace/didChangeWatchedFiles `(:changes ,(vector `(:uri ,(eglot--path-to-uri file) - :type ,(cl-case action - (created 1) - (changed 2) - (deleted 3))))))) + :type ,action-type))))) ((eq action 'renamed) (handle-event `(,desc 'deleted ,file)) (handle-event `(,desc 'created ,file1))))))) -- 2.39.5