-
Notifications
You must be signed in to change notification settings - Fork 13
Description
What happened?
I am watching an individual file:
ghciwatch --command "cabal repl day14" --watch day14.hs --error-file errors.err --clear --test-ghci main
After making edits in vim, I get this behavior from ghciwatch:
• Removing modules from ghci:
• day14.hs
Ok, 8 modules loaded.
• All good! Finished reloading in 70.28ms
• Running test command command=main
<interactive>:7:1: error: [GHC-88464]
Variable not in scope: main
Suggested fix: Perhaps use ‘min’ (imported from Prelude)
• Finished running tests in 55.47ms
This kills the ghciwatch workflow, naturally. :)
What did you expect to happen?
ghciwatch should see the file change (not get deleted) and reload it.
Hypothesis
Here's what I think is happening. For atomicity, vim does a little dance when writing a file: Write to a temp file, delete the real file, move the temp file to the real file. I assume ghciwatch sees the deletion and stops tracking the file. I've seen this problem with similar tool in the past.
If that is the case (and I haven't looked, sorry), then it might be better to debounce the deletion: Keep tracking the file until the debounce period is over.
Workaround
Watch the directory instead of the file.
ghciwatch --command 'ghci main.hs' --watch . --test-ghci main
Steps to reproduce the issue
$ echo 'main = putStrLn "hello world!"' > main.hs
$ ghciwatch main.hs --test-ghci main
(in a separate shell)
$ vim +wq main.hs
The version of ghciwatch with the bug
ghciwatch 1.0.1