slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.94k stars 568 forks source link

slint-viewer --auto-reload does not work well with Neovim (and potentially other editors) #3641

Closed necabo closed 5 months ago

necabo commented 11 months ago

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.

hunger commented 11 months ago

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...

codecat commented 9 months ago

With Sublime Text, on some saves it would successfully reload, and on other saves it would tell me "No component found".

Successful reload of ui/main_window.slint
error: No component found
ogoffart commented 8 months ago

Accroding to https://github.com/LeonMatthes/Dotfiles/commit/d7ff39fb88397f2fcaac9b6cc21d1e31a16fe7e4#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.

ogoffart commented 5 months ago

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 https://github.com/slint-ui/slint/blob/2b81d5359d598393c2b4b4386e613b7958cff28f/tools/viewer/main.rs#L184