From 782f234981c10993ba7aed609455628138688a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Wed, 17 Dec 2014 17:52:50 +0100 Subject: [PATCH] Fix ghc-mod tempdirs not being removed on exit --- Language/Haskell/GhcMod/Monad.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Language/Haskell/GhcMod/Monad.hs b/Language/Haskell/GhcMod/Monad.hs index b2f1d96..dd1fab3 100644 --- a/Language/Haskell/GhcMod/Monad.hs +++ b/Language/Haskell/GhcMod/Monad.hs @@ -270,16 +270,18 @@ runGhcModT :: IOish m => Options -> GhcModT m a -> m (Either GhcModError a, GhcModLog) -runGhcModT opt action = do - env <- liftBase $ newGhcModEnv opt =<< getCurrentDirectory +runGhcModT opt action = gbracket newEnv delEnv $ \env -> do r <- first (fst <$>) <$> (runGhcModT' env defaultState $ do dflags <- getSessionDynFlags defaultCleanupHandler dflags $ do initializeFlagsWithCradle opt (gmCradle env) action) - liftBase $ cleanupGhcModEnv env return r + where + newEnv = liftBase $ newGhcModEnv opt =<< getCurrentDirectory + delEnv = liftBase . cleanupGhcModEnv + -- | @hoistGhcModT result@. Embed a GhcModT computation's result into a GhcModT -- computation. Note that if the computation that returned @result@ modified the -- state part of GhcModT this cannot be restored.