-
Notifications
You must be signed in to change notification settings - Fork 625
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
slint-viewer --auto-reload does not work well with Neovim (and potentially other editors) #3641
Comments
I always use the preview build into the language server: That works great with neovim. I'll need to take a look at the slint-viewer... |
With Sublime Text, on some saves it would successfully reload, and on other saves it would tell me "No component found".
|
Accroding to LeonMatthes/Dotfiles@d7ff39f#diff-aacb5e1be9b006044db0bfd005e040928e33b550a9d44e60d80b7e1e0855b638R37-R39 , it seems that neovim will first move the old file to a backup file, then re-create a new file with the given name. And this doesn't work well with the way the slint-viewer uses the file system watcher. |
I was told We should also watch the parent directory and reload the view if a file that matches the file we're watching is added (and watch that) The code that do the watcher is around there Line 184 in 2b81d53
|
Some editors may backup a file by renaming it to append ~, then saving the new file contents to a new file. notify-rs/notify#166 explains that a non-recursive watcher on the parent directory is the recommended way to deal with this situation. Closes: slint-ui#3641
Some editors, such as vim, rename (move) a file to a backup location, then write the new contents to a new location when the user saves their changes. notify stops watching the renamed file, and does not automatically start watching the new file created. Additionally, slint-viewer attempts to reload before the editor has written the new file, which causes an error. The file is then never reloaded because the watcher was lost. This patch solves the problem by attempting to watch the file again, if the previous watch failed due to a Generic or PathNotFound error. Generic is required because this is error type we get on macOS for "No such file or directory.". We delay the retry by a small timeout to give the editor a chance to write the new file. Note that this still results in an error being printed about the missing file. Tested manually by editing both root .slint file, and .slint files imported from sub-directories. Closes: slint-ui#3641
Some editors, such as vim, rename (move) a file to a backup location, then write the new contents to a new location when the user saves their changes. notify stops watching the renamed file, and does not automatically start watching the new file created. Additionally, slint-viewer attempts to reload before the editor has written the new file, which causes an error. The file is then never reloaded because the watcher was lost. This patch solves the problem by attempting to watch the file again, if the previous watch failed due to a Generic or PathNotFound error. Generic is required because this is error type we get on macOS for "No such file or directory.". We delay the retry by a small timeout to give the editor a chance to write the new file. Note that this still results in an error being printed about the missing file. Tested manually by editing both root .slint file, and .slint files imported from sub-directories. Closes: #3641
Neovim on Linux and potentially other editors may have surprising behavior when saving files.
notify, the library used to watch files in slint-viewer, mentions this behavior here and links to related issues.
I suspect this to be the reason that
slint-viewer --auto-reload <file>
fails to reload on save after a few saves (sometimes it works once, sometimes a few more times).I tried some of the suggested fixes in the referenced issues such as setting
backupcopy=yes
in Neovim and can confirm that this changes which events notify reports, fixing the issue.It's just unfortunate that the default Neovim behavior breaks auto-reloading and the issue isn't easy to discover.
One suggested fix applications could employ is watching the parent directory instead.
I don't know if that approach would work for slint-viewer or how relevant this issue is. Maybe documenting this somewhere is enough.
Personally, I'll just use the LSP preview which works very well in Neovim.
The text was updated successfully, but these errors were encountered: