Skip to content

didChangeWatchedFiles does not work recursively, LSP server goes out of sync for new directories #1411

Closed
@stapelberg

Description

@stapelberg

Steps to reproduce:

  1. I compiled Emacs at git revision 6a9f1b504a5a3c096afd17f3b8f8ebeca6a03ed5
  2. Then I started emacs -q ~/repro-emacs/hello1 (a directory)
  3. (Only relevant for diagnosis) I switched to the scratch buffer and evaluated the following LISP code:
    (defun my-file-notify-add-watch-logger (file event &rest args)
      "log a message whenever file-notify-add-watch is called"
      (message "file-notify-add-watch called with file: %s, event: %s" file event))
    
    (advice-add 'file-notify-add-watch :before #'my-file-notify-add-watch-logger)
  4. Open hello1.go
  5. M-x eglot gopls RET
  6. In a terminal, I run touch extra.go and I see a didChangeWatchedFiles event in the *EGLOT …* buffer — good!
  7. In a terminal, I run mkdir newinternal, then touch newinternal/extra.go and I see no event — this is unexpected.
  8. In the *Messages* buffer, I see:
file-notify-add-watch called with file: /home/stapelberg/repro-emacs/hello1/, event: (change)
file-notify-add-watch called with file: /home/stapelberg/repro-emacs/hello1/internal/, event: (change)
  1. Notably, when creating the newinternal directory from my terminal, I see no file-notify-add-watch. I conclude that Eglot does not re-evaluate recursive glob patterns when new directories are created.
    • The Emacs “File Notifications” documentation states:

      If file is a directory, change watches for file creation and deletion in that directory. Some of the native file notification libraries also report file changes in that case. This does not work recursively.

    • …which I think is the reason why Eglot expands recursive glob patterns to directories in the first place.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions