Skip to content

Debouncing file removal #334

@chreekat

Description

@chreekat

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    linearCreated by Linear-GitHub Sync

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions