-
-
Notifications
You must be signed in to change notification settings - Fork 625
chore(watchers): Watcher shares single fs_event from Event, node watchers use unique path prefixed debounce context #1453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…hers use unique path prefixed debounce context
end | ||
end | ||
|
||
return M.pathexts[ext:upper()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to the change, however this hurt my eyes and I could not help tidying it.
|
||
M.uid = M.uid + 1 | ||
return Watcher:new(absolute_path, callback, { | ||
context = "explorer:watch:" .. absolute_path .. ":" .. M.uid, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unique debouncer context added so that the real/link jobs do not clobber each other.
w:destroy() | ||
end | ||
|
||
for _, e in pairs(Event._events) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary however it does not hurt.
end | ||
|
||
function Watcher:start() | ||
self._listener = function() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to call back to a member function like Watcher:on_event
however it doesn't seem possible.
watcher:destroy() | ||
log.line("watcher", "purge_watchers") | ||
|
||
for _, w in ipairs(utils.array_shallow_clone(Watcher._watchers)) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure i understand why a shallow clone is needed here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watcher:destroy
will remove self from Watcher._watchers
. That confuses the iterator.
LGTM, i wonder if we should move the debouncing inside the watcher event listener to avoid repeating the logic everytime we want to introduce a new watcher. Maybe for a followup PR. Looks good to me, let's merge this. |
That makes sense: Debounce would still be used "standalone" by diagnostics and anything else. On my list. |
…hers use unique path prefixed debounce context (nvim-tree#1453)
Split Watcher into Watcher and Event.
Event owns the fs_event for an absolute path.
Watcher:new
always creates a new Watcher which may share an existing Event.Node watchers use a unique context: absolute path + incremennting index
Example:
/path/to/real
. Two node Watchers created:/path/to/real:1
,/path/to/real:2
.real/file
: one event fires, two watchers fire./path/to/real:3
real/file
: one Event fires, three watchers fire.link1
: node Watcher destroyed:/path/to/real:2
real/file
: one Event fires, two watchers fire.All the refresh/draw events will now correctly occur for each affected link/directory, along with the associated git event. This extra git event could be optimised away, however the added complexity is not worth it for the rare cases in which this will actually occur.