Skip to content

Conversation

@BK1603
Copy link
Contributor

@BK1603 BK1603 commented Jul 4, 2020

Using libUVs filesystem notifications to notify about the files changed outside neovim.

@teto teto added the gsoc community: Google Summer of Code project label Jul 4, 2020
@marvim marvim added the WIP label Jul 5, 2020
@tjdevries
Copy link
Contributor

Nice work so far!

@BK1603
Copy link
Contributor Author

BK1603 commented Jul 6, 2020

Thanks a lot for the reviews! @tjdevries
Also apologies for responding so late, I can't seem to get github notifications to work :/
I will make the relevant changes and make a commit again.

@BK1603 BK1603 force-pushed the fswatch-autoread branch from b21a0dc to 864a760 Compare July 17, 2020 16:12
@teto
Copy link
Member

teto commented Jul 19, 2020

@erw7 what's the status of libuv file watching on windows ? any comment ? we would like to fallback on autoread for platforms where libuv's file watching doesn't work as well as on linux.

@erw7
Copy link
Contributor

erw7 commented Jul 21, 2020

what's the status of libuv file watching on windows ? any comment ? we would like to fallback on autoread for platforms where libuv's file watching doesn't work as well as on linux.

It seems to work. However, there are the following problems. If I select (S)how diff at the prompt, I get the following error.

Error executing vim.schedule lua callback: .../neovim/neovim/runtime/lua/vim/fcnotify/init.lua:38: Vim(execute):E121: Undefined variable: a:buf

As far as the CI build logs are concerned, these may not be Windows-specific issues.

https://builds.sr.ht/~jmk/job/258982#task-functionaltest-617

Also, if I use :edit, :bd, the following code will be executed and not exists will be output to the message.

-- shouldn't happen
if WatcherList[fname] == nil then
print(fname..' not exists')
return
end

@BK1603
Copy link
Contributor Author

BK1603 commented Jul 21, 2020

@erw7
Thank you for the insight!
I think the commit that you tried didn't have the buf parameter defined. Sorry for that.
Also hmm, the test seemed to run fine on my machine. I will take a look at it immediately.

And thanks a lot for pointing out the last part. I do need to add some more autocommands for the file watcher. :)

if choice == 1
call fcnotify#Reload(a:buf)
elseif choice == 2
call fcnotify#DiffOrig(a:buf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens after showing the diff, I should be able to choose to reload or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the user can use the diff tools to resolve the issue. He could either pull everything or pull selectively and write to the file then. Does this work? Or should there be a prompt after showing the diff too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I don't want to add too much complexity for now. Just looking at ways to make it more user-friendly.
For instance recover.vim detects when there are no changes and it also explicitly differentiates between the on-disk file and inmemory buffer https://github.com/chrisbra/Recover.vim/blob/master/autoload/recover.vim#L299

@BK1603 BK1603 force-pushed the fswatch-autoread branch from ee70ec8 to 4ddb011 Compare April 8, 2021 21:13
@BK1603 BK1603 force-pushed the fswatch-autoread branch from afc5485 to b9d465b Compare April 9, 2021 07:59
the 'paste' option is reset.

*'filechangenotify'* *'fcnotify'*
'filechangenotify' 'fcnotify' string (default "off")
Copy link
Member

@justinmk justinmk Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding an option for this? If users want/need to deal with these low-level details beyond simply setting 'autoread', they can do that by adding/deleting autocmds (which we can document if needed). I don't see why we would want to crystallize this in a new option (which is largely redundant with 'autoread').

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the reasons were that we might want to support different backends for watching the files. (Some backends support remote filesystems, while libuv doesn't.)

Also, we can either have a libuv based watcher for watching the files, or we could check for the changes on FocusGained (which came from: #12531). There's no point in having both of them active at the same time, and I don't think it is possible to verify if the watcher is working, so that we can turn the autoread tui pr "off". We can not decide what we should use if we have autoread set. Since the watcher might not work on some filesystems, (like remote filesystems,) setting autoread on those systems would render the option useless. It would be better if we could simply use your autoread tui PR for remote filesystems.

Autoread was, before the autoread-tui PR was merged, an option that dictated the behavior of checktime. I don't think we ever automatically reloaded a file just because it was changed outside neovim. That is what the issue was all about.

What I feel is, autoread currently is supposed to do two separate things:

  1. Checking for if a file was changed outside of neovim.
  2. In case the file was changed, seeing if we want to notify the user or if we want to reload the buffer.

What autoread has been doing initially is only number 2, although the documentation says it will be doing both 1 & 2, which is where the confusion and false expectations from autoread came from. I think we need to have 2 separate options for these since these are 2 separate things.

A user might not want to watch a file using the fs_watch handle at all, but might still want to reload the buffer everytime :checktime is executed, because of old configs. Or a user might want to watch a file using fs_watch, but might not want it to be reloaded automatically. He would like to be notified for the changes so that he could decide if he wants the file to be reloaded or not. Both of these things can not be controlled by autoread alone.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I have an idea. I would have to discuss it with others first though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

watcher Use filesystem notifications for watching a
file. Might not work on all filesystems.
onfocus Use aucmds to check for changes to a file on
the events `FocusGained`
Copy link
Member

@justinmk justinmk Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are low-level details. No reason to expose them as permanent options. The implementation might change/improve, and then these options are just noise.

Suggestion:

  • do the right thing based on 'autoread'.
  • if the implementation has limitations, document them and potential workarounds. Do not engrave them in stone for eternity by creating a new special-purpose option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of changing the option and having it accept a single value. The name of the backend we want to use for watching the files. OnFocus, fswatch or something else if we later support it. Having autoread here is redundant since we already have an autoread option that controls the behaviour of checktime.

So we could simply have fcnotify=watcher or fcnotify=onfocus or fcnotify=off.

@@ -0,0 +1,313 @@
local helpers = require('test.functional.helpers')(after_each)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related, why was test/functional/autoread/ created? Don't need a subdirectory for every feature.

@justinmk justinmk changed the title [RDY] fswatch autoread fswatch autoread Apr 12, 2021
@neovim-discourse
Copy link

This pull request has been mentioned on Neovim Discourse. There might be relevant details there:

https://neovim.discourse.group/t/fswatch-autoread-discussion/512/1

@clason clason modified the milestones: 0.5.1, 0.6 Jul 6, 2021
@bfredl bfredl modified the milestones: 0.6, 0.7 Oct 30, 2021
@clason clason added needs:response waiting for reply from the author and removed status:needs-approval labels Apr 17, 2022
@clason
Copy link
Member

clason commented Apr 17, 2022

@BK1603 sorry that this was left on the back burner for 0.7. Are you still available and interested in continuing this? A rebase would be a good start ;)

@BK1603
Copy link
Contributor Author

BK1603 commented Apr 20, 2022

@clason hey!
I'll try and get back at it over the weekend. I'd like to see this merged too :)

@neovim-discourse
Copy link

This pull request has been mentioned on Neovim Discourse. There might be relevant details there:

https://neovim.discourse.group/t/a-lua-based-auto-refresh-buffers-when-they-change-on-disk-function/2482/3

@BK1603
Copy link
Contributor Author

BK1603 commented Oct 21, 2022

Hey guys! Sorry for vanishing again. I got out of college and landed a new job this year 😬
Still trying to get a hang of things. Finally found some time, I will try rebasing and pushing to this branch. Although I think I have a lot of catching up to do.

@dundargoc
Copy link
Member

Related: #1380

@BK1603
Copy link
Contributor Author

BK1603 commented Oct 25, 2022

@teto @justinmk, since this branch is way far behind master, and since there have already been a lot of changes to the code base, I think it would be better to start with a new branch (that's already on top of master) instead.

Also I think this PR was trying to do 3 things at once:

  1. Modify the behavior of autoread using libuv
  2. A new option, fcnotify, which @justinmk advised against. I am dropping the additional option for now as I do see it getting really complicated.
  3. The show diff and load option.

2 is up for debate, but I am thinking of taking all of them up in separate PRs. We can track a progress of these PRs and
do discussions for what to/not to include in the original issue created during GSoC: #12605

Here is the new PR for 1: #20801

@dundargoc dundargoc removed the needs:response waiting for reply from the author label Oct 26, 2022
@justinmk
Copy link
Member

good plan, can we close this?

@BK1603
Copy link
Contributor Author

BK1603 commented Nov 18, 2022

@justinmk, yep, we can close this. We can continue further discussions on the issue or the new PR. Thanks!

@BK1603 BK1603 closed this Nov 18, 2022
@zeertzjq zeertzjq added the filesystem file metadata/attributes, filenames, path manipulation label Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

filesystem file metadata/attributes, filenames, path manipulation gsoc community: Google Summer of Code project

Projects

None yet

Development

Successfully merging this pull request may close these issues.