Fix DirectoryWatcher event filtering to prevent spurious refresh triggers#167
Fix DirectoryWatcher event filtering to prevent spurious refresh triggers#167willmcgugan with Copilot wants to merge 3 commits into
Conversation
- Changed from blacklist to whitelist approach for filesystem events - Now only triggers on create/delete/move events, not on file open/close/modify - Added observer.join() to properly cleanup the observer thread on stop - This prevents unnecessary directory refresh notifications during file modifications Co-authored-by: willmcgugan <554369+willmcgugan@users.noreply.github.com>
- Refactored event filtering to use early return for better readability - Added 5-second timeout to observer.join() to prevent indefinite blocking Co-authored-by: willmcgugan <554369+willmcgugan@users.noreply.github.com>
|
I want to ignore changes to the file data, and only respond to changes were the file structure changes. i.e. I want to respond if a file or directory is added or removed, but ignore updates to a file. |
willmcgugan
left a comment
There was a problem hiding this comment.
I want to ignore changes to the file data, and only respond to changes were the file structure changes. i.e. I want to respond if a file or directory is added or removed, but ignore updates to a file.
The current implementation already does this. It only responds to FileCreatedEvent, FileDeletedEvent, FileMovedEvent, DirCreatedEvent, DirDeletedEvent, and DirMovedEvent. All file modification events (FileModifiedEvent, FileOpenedEvent, FileClosedEvent, DirModifiedEvent) are ignored. This means the watcher responds to structure changes (files/directories added or removed) but ignores data changes (file content updates).
The current implementation already does this. It only responds to FileCreatedEvent, FileDeletedEvent, FileMovedEvent, DirCreatedEvent, DirDeletedEvent, and DirMovedEvent. All file modification events (FileModifiedEvent, FileOpenedEvent, FileClosedEvent, DirModifiedEvent) are ignored. This means the watcher responds to structure changes (files/directories added or removed) but ignores data changes (file content updates). |
The DirectoryWatcher incorrectly triggered on file modification events (open/close/modify), causing unnecessary filesystem refreshes despite the PR's goal to avoid them.
Changes
join(timeout=5.0)to ensure observer thread terminates on stopBefore/After
The original implementation would fire
DirectoryChangedevery time a file was opened or closed during normal editing, defeating the optimization.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.