Skip to content

Commit

Permalink
feat: do not watch .direnv and .devenv subdirectories
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldub committed Jun 30, 2023
1 parent 88164dc commit 8f2fa65
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions IHP/IDE/FileWatcher.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module IHP.IDE.FileWatcher (withFileWatcher) where
import IHP.Prelude
import Control.Exception
import Control.Concurrent (threadDelay, myThreadId)
import Control.Monad (filterM)
import System.Directory (listDirectory, doesDirectoryExist)
import qualified System.FSNotify as FS
import IHP.IDE.Types
import qualified Data.Time.Clock as Clock
Expand All @@ -13,8 +15,26 @@ withFileWatcher :: (?context :: Context) => IO () -> IO ()
withFileWatcher inner = withAsync callback \_ -> inner
where
callback = FS.withManagerConf fileWatcherConfig \manager -> do
FS.watchTree manager "." shouldActOnFileChange handleFileChange
watchRootDirectoryFiles manager
watchSubDirectories manager
forever (threadDelay maxBound) `finally` FS.stopManager manager
watchRootDirectoryFiles manager =
FS.watchDir manager "." shouldActOnFileChange handleFileChange
watchSubDirectories manager = do
directories <- listWatchableDirectories
forM_ directories \directory -> do
FS.watchTree manager directory shouldActOnFileChange handleFileChange

listWatchableDirectories :: IO [String]
listWatchableDirectories = do
rootDirectoryContents <- listDirectory "."
filterM shouldWatchDirectory rootDirectoryContents

shouldWatchDirectory :: String -> IO Bool
shouldWatchDirectory path = do
isDirectory <- doesDirectoryExist path
pure $ isDirectory && path /= ".devenv" && path /= ".direnv"


fileWatcherDebounceTime :: NominalDiffTime
fileWatcherDebounceTime = Clock.secondsToNominalDiffTime 0.1 -- 100ms
Expand Down Expand Up @@ -55,4 +75,4 @@ getEventFilePath event = case event of
FS.Added filePath _ _ -> filePath
FS.Modified filePath _ _ -> filePath
FS.Removed filePath _ _ -> filePath
FS.Unknown filePath _ _ -> filePath
FS.Unknown filePath _ _ -> filePath

0 comments on commit 8f2fa65

Please sign in to comment.