-
Notifications
You must be signed in to change notification settings - Fork 525
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
File watcher breaks when using Helix editor #2131
Comments
oo interesting, thanks for the legwork researching this |
i installed helix and tried to reproduce but could not. is there a setting you're using to turn on backup files? Kapture.2024-10-01.at.12.42.50.mp4 |
Not really, no. if I read it right, the error shows up in os.Stat(path) [go.watch:356]. Does powershell do something different than zsh when trying to find a file? I don't have wsl setup right now to test with on the same machine... I only found out about the backup file writing through this issue, but my understanding is that it's a baseline for most editors that safeguards against file corruption if the editor crashes during write. |
i think related to #9 I wonder if this issue is circumvented if we just do atomic writes |
Let's see in the next version if this still is an issue: #2141 |
@LatjoLajbin Thank you for the swift followup. I just have to confirm, |
Yes, confirmed. Also tried building from source before this release but didn't yet step through sequentially or anything |
Hi, I managed to reproduce this in Windows and Neovim with d2 version 0.6.9. I also found a workaround, that points to a possible solution: It seems like the file watcher updates its pointer to a backup file that is created prior to writing, and this file is deleted after a successful write but the reference is never shifted back to the original file. I don't know enough about filesystem file reference handling, but this feels like it might be specific to Windows. Also speculating, but if other editors backup before save to a separate file instead of moving the original, this bug would not show up in those.
Next I tried to manually save the file as
This looked like the way Vim/Neovim cycles through swap files, so I checked if it is related to something similar. This turned out to be true: Disabling the setting "writebackup" (
@LatjoLajbin if you could be so kind as to see if Helix has a similar setting to disable write backups and write to the file directly instead, could you comment on this again if that solves the issue for you as well? |
@scajanus I might be about to spread some misinformation right now since I'm typing this out on my phone off the top of my head, but I believe I recall this discussion in the Helix repo. It was requested to add an option for disabling write back-ups, but it was rejected as the integrity of files was paramount as a design choice. As such, the option doesn't exist right now. I'll find the discussion and link it / modify this post when I'm able to. |
Can someone build from source on this branch and test? #2345 Going the Hugo route of just ignoring backup files, which should fix the issue. |
I don't have admin rights on my (client's) Windows laptop, which makes installing software a bit cumbersome. I can still try to setup Go and compile this sometime next week if no one else has easier access to a setup to try it out. Couldn't reproduce it on my Mac with Neovim, so looks like this is specific to Windows. In Vim/Neovim the backups generally append a tilde character, but it looks like if a file with that name (tilde appended) exists, it has some logic to decide on the new file name (e.g. in my example, the backup was first named I think the most general solution would to not follow the file around if it is renamed, and just stick with the original filename. Looking at the documentation of https://github.com/fsnotify/fsnotify, they mention:
I haven't programmed in Go so I didn't look at the MR too deeply -- are you watching the files directly? Looks like to library suggests to watch the whole folder, and simply ignore events that don't exactly match the original argument. |
Thank you @scajanus , yes that's basically what the PR is doing: ignore backup/temp-looking files. Not the most robust as that's a moving target, but good enough for now. |
Running d2 with filewatching breaks as soon as a save is performed, as helix creates and removes a backup file in case of crashes.
Found a similar report in the discord where the user was prompted to make a github issue, but I'm making this since I couldn't seem to find one.
OS: Windows
Shell: PowerShell
Editor: Helix
Installed via: Scoop (v0.6.7)
Wondering if this is related to the 16 milliseconds of event catching in d2cli/watch.go? It feels weird that it's receiving the file system event REMOVE and then immediately tries to ensure that it's being filewatched.
There's a discussion in the helix repo regarding a similar issue in Hugo, where it was solved in Hugo by adding .bck files as file type exceptions.
helix-editor/helix#11715
gohugoio/hugo#12856
The text was updated successfully, but these errors were encountered: