Fix re-init of ghc-modi session after environment change

Using `dropSession` instead of a weird exception cludge
This commit is contained in:
Daniel Gröber
2015-08-05 08:52:52 +02:00
parent 20bccae1fc
commit f61dd0a9e6
4 changed files with 14 additions and 49 deletions

View File

@@ -28,6 +28,7 @@ module Language.Haskell.GhcMod (
-- * Monad utilities
, runGhcModT
, withOptions
, dropSession
-- * 'GhcMod' utilities
, boot
, browse
@@ -73,3 +74,4 @@ import Language.Haskell.GhcMod.Modules
import Language.Haskell.GhcMod.Monad
import Language.Haskell.GhcMod.PkgDoc
import Language.Haskell.GhcMod.Types
import Language.Haskell.GhcMod.Target

View File

@@ -110,6 +110,8 @@ initSession opts mdf = do
_ <- setSessionDynFlags =<< setDf =<< getSessionDynFlags
getSession
-- | Drop the currently active GHC session, the next that requires a GHC session
-- will initialize a new one.
dropSession :: IOish m => GhcModT m ()
dropSession = do
s <- gmsGet
@@ -120,10 +122,10 @@ dropSession = do
liftIO $ writeIORef ref (error "HscEnv: session was dropped")
-- Not available on ghc<7.8; didn't really help anyways
-- liftIO $ setUnsafeGlobalDynFlags (error "DynFlags: session was dropped")
gmsPut s { gmGhcSession = Nothing }
Nothing -> return ()
gmsPut s { gmGhcSession = Nothing }
runGmlT :: IOish m => [Either FilePath ModuleName] -> GmlT m a -> GhcModT m a
runGmlT fns action = runGmlT' fns return action