>From 94d5b3a6f6c44b7e60ea46076638a50b203bf0ac Mon Sep 17 00:00:00 2001 From: Brian Leung Date: Tue, 2 Feb 2021 11:23:25 -0800 Subject: [PATCH 1/2] eglot-register-capability: Filter events per FileSystemWatcher.kind * eglot.el (eglot-register-capability): Only send notifications of interest, as determined by the optional FileSystemWatcher.kind bitmask. 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). --- eglot.el | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 901bf30..4040d07 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -3253,8 +3253,10 @@ 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) + (or kind 7))) watchers)) (dirs-to-watch (delete-dups (mapcar #'file-name-directory @@ -3263,17 +3265,22 @@ 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.37.3