emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master be17456063: Make Eglot consider FileSystemWatcher.kind when watch


From: João Távora
Subject: master be17456063: Make Eglot consider FileSystemWatcher.kind when watching files
Date: Fri, 11 Nov 2022 10:24:49 -0500 (EST)

branch: master
commit be1745606354e8b34325bc9526c9bad9f7302cce
Author: Brian Leung <leungbk@posteo.net>
Commit: João Távora <joaotavora@gmail.com>

    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 167fd129a5..63ebbe6cab 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)))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]