-
-
Notifications
You must be signed in to change notification settings - Fork 629
feat(watcher): fs_poll -> fs_event, destroy nodes/watchers #1431
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,8 +29,8 @@ function M.reload_project(project_root, path) | |
return | ||
end | ||
|
||
if path and not path:match("^" .. project_root) then | ||
path = nil | ||
if path and path:find(project_root, 1, true) ~= 1 then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was pattern matching the file name 🤦 Resolves #1373 (comment) |
||
return | ||
end | ||
|
||
local git_status = Runner.run { | ||
|
@@ -43,7 +43,7 @@ function M.reload_project(project_root, path) | |
|
||
if path then | ||
for p in pairs(project.files) do | ||
if p:match("^" .. path) then | ||
if p:find(path, 1, true) == 1 then | ||
project.files[p] = nil | ||
end | ||
end | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,13 @@ local M = { | |
local Watcher = {} | ||
Watcher.__index = Watcher | ||
|
||
local FS_EVENT_FLAGS = { | ||
-- inotify or equivalent will be used; fallback to stat has not yet been implemented | ||
stat = false, | ||
-- recursive is not functional in neovim's libuv implementation | ||
recursive = false, | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put this in for documentation purposes. |
||
|
||
function Watcher.new(opts) | ||
for _, existing in ipairs(M._watchers) do | ||
if existing._opts.absolute_path == opts.absolute_path then | ||
|
@@ -35,48 +42,55 @@ function Watcher:start() | |
|
||
local rc, _, name | ||
|
||
self._p, _, name = uv.new_fs_poll() | ||
if not self._p then | ||
self._p = nil | ||
self._e, _, name = uv.new_fs_event() | ||
if not self._e then | ||
self._e = nil | ||
utils.warn( | ||
string.format("Could not initialize an fs_poll watcher for path %s : %s", self._opts.absolute_path, name) | ||
string.format("Could not initialize an fs_event watcher for path %s : %s", self._opts.absolute_path, name) | ||
) | ||
return nil | ||
end | ||
|
||
local poll_cb = vim.schedule_wrap(function(err) | ||
local event_cb = vim.schedule_wrap(function(err, filename, events) | ||
if err then | ||
log.line("watcher", "poll_cb for %s fail : %s", self._opts.absolute_path, err) | ||
log.line("watcher", "event_cb for %s fail : %s", self._opts.absolute_path, err) | ||
else | ||
log.line("watcher", "event_cb '%s' '%s' %s", self._opts.absolute_path, filename, vim.inspect(events)) | ||
self._opts.on_event(self._opts) | ||
end | ||
end) | ||
|
||
rc, _, name = uv.fs_poll_start(self._p, self._opts.absolute_path, self._opts.interval, poll_cb) | ||
rc, _, name = self._e:start(self._opts.absolute_path, FS_EVENT_FLAGS, event_cb) | ||
if rc ~= 0 then | ||
utils.warn(string.format("Could not start the fs_poll watcher for path %s : %s", self._opts.absolute_path, name)) | ||
utils.warn(string.format("Could not start the fs_event watcher for path %s : %s", self._opts.absolute_path, name)) | ||
return nil | ||
end | ||
|
||
return self | ||
end | ||
|
||
function Watcher:stop() | ||
log.line("watcher", "Watcher:stop '%s'", self._opts.absolute_path) | ||
if self._p then | ||
local rc, _, name = uv.fs_poll_stop(self._p) | ||
function Watcher:destroy() | ||
log.line("watcher", "Watcher:destroy '%s'", self._opts.absolute_path) | ||
if self._e then | ||
local rc, _, name = self._e:stop() | ||
if rc ~= 0 then | ||
utils.warn(string.format("Could not stop the fs_poll watcher for path %s : %s", self._opts.absolute_path, name)) | ||
utils.warn(string.format("Could not stop the fs_event watcher for path %s : %s", self._opts.absolute_path, name)) | ||
end | ||
self._e = nil | ||
end | ||
for i, w in ipairs(M._watchers) do | ||
if w == self then | ||
table.remove(M._watchers, i) | ||
break | ||
end | ||
self._p = nil | ||
end | ||
end | ||
|
||
M.Watcher = Watcher | ||
|
||
function M.purge_watchers() | ||
for _, watcher in pairs(M._watchers) do | ||
watcher:stop() | ||
watcher:destroy() | ||
end | ||
M._watchers = {} | ||
end | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
whoops