-
Notifications
You must be signed in to change notification settings - Fork 236
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
Autoreload Nagview #942
Autoreload Nagview #942
Conversation
7f39043
to
841371e
Compare
Great! 😆
I would say yes, it would be helpful to be able to undo those changes |
So, @jgmdev mentioned that there seems to be an issue here that was introduced when dmon introduced; basically if you're on a project that's at the file limit, autoreload doesn't actually reload things, because it's listening for dmon/dirmonitor events, even though those only fire on 'open' directories inside a project, and don't fire outside a project. Solution here is to add a thread in the cases where we're looking at an external file, and add poll the file. There's also strong consensus around putting |
OK; made those changes. Any thoughts? If none, I'll merge this as is on the 30th. |
Testing with a file from outside the project, it looks like refusing the changes doesn't work. |
This is fixable by moving check_prompt_reload(): local on_check = dirwatch.check
function dirwatch:check(change_callback, ...)
on_check(self, function(dir)
for _, doc in ipairs(core.docs) do
if dir == common.dirname(doc.abs_filename) then
check_if_modified(doc)
end
end
change_callback(dir)
end, ...)
check_prompt_reload() -- <--------------- from here
end local on_check = dirwatch.check
function dirwatch:check(change_callback, ...)
on_check(self, function(dir)
for _, doc in ipairs(core.docs) do
if dir == common.dirname(doc.abs_filename) then
check_if_modified(doc)
check_prompt_reload() -- <--------------- to here
end
end
change_callback(dir)
end, ...)
end
core.add_thread(function()
while core.active_view.doc == doc do
check_if_modified(doc)
coroutine.yield(0.25)
end
end)
core.add_thread(function()
if doc and core.active_view.doc == doc then
check_if_modified(doc)
end
end)
Second Edit: seems that check_prompt_reload() also needs a call to update_time at least for files external to project local function check_prompt_reload()
if core.active_view.doc and core.active_view.doc.deferred_reload then
local doc = core.active_view.doc
core.nag_view:show("File Changed", doc.filename .. " has changed. Reload this file?", {
{ font = style.font, text = "Yes", default_yes = true },
{ font = style.font, text = "No" , default_no = true }
}, function(item)
if item.text == "Yes" then
reload_doc(doc)
else
update_time(doc) -- <----------------------- here
end
doc.deferred_reload = false
end)
end
end |
would be better to send that as a patch |
I did those checks on a rush and just posted what I found, here is a patch if it is right: diff --git a/data/plugins/autoreload.lua b/data/plugins/autoreload.lua
index fba22a2..0882164 100644
--- a/data/plugins/autoreload.lua
+++ b/data/plugins/autoreload.lua
@@ -30,7 +30,11 @@ local function check_prompt_reload()
{ font = style.font, text = "Yes", default_yes = true },
{ font = style.font, text = "No" , default_no = true }
}, function(item)
- if item.text == "Yes" then reload_doc(doc) end
+ if item.text == "Yes" then
+ reload_doc(doc)
+ else
+ update_time(doc)
+ end
doc.deferred_reload = false
end)
end
@@ -53,11 +57,11 @@ function dirwatch:check(change_callback, ...)
for _, doc in ipairs(core.docs) do
if dir == common.dirname(doc.abs_filename) then
check_if_modified(doc)
+ check_prompt_reload()
end
end
change_callback(dir)
end, ...)
- check_prompt_reload()
end |
…nagview to verify that fs changes don't stomp on our changes, unless you want them to.
…ead to check the document, in the cases where it wouldn't be covered by dirwatch.
…s when we load a non-existent file, and added some checks.
177e75d
to
32ecf9a
Compare
OK; I actually realised there was an easier way to just cover all bases here; now that dirwatch is a modular class; we can actually just use that to efficiently check individual files outside the project, so that they too also reload with inotify. I'm also going to target this PR at 2.1, because autoreload is straight broken in 2.1 at present. |
OK, jgmdev tested this; seems to work. Squashing and merging. |
In addition to changing the plugin from the special core hook to a normal overload for detecting file changes, I've also done the following, based on some suggestions on discord:
This covers most of the cases; and should get rid of the issue where
autoreload.lua
will just stomp on changes you have if you're actively editing the file.This is not the end-behaviour; as there is some discussion about exactly how a file should be reloaded (should it go directly into the undo stack, so you can easily undo it?), but this is an incremental step in the right direction.