Add newGhcModEnv for allowing multiple active sessions
Conflicts: Language/Haskell/GhcMod/Monad.hs
This commit is contained in:
parent
d696214816
commit
dc5ba6d00d
@ -1,5 +1,6 @@
|
|||||||
module Language.Haskell.GhcMod.Cradle (
|
module Language.Haskell.GhcMod.Cradle (
|
||||||
findCradle
|
findCradle
|
||||||
|
, findCradle'
|
||||||
, findCradleWithoutSandbox
|
, findCradleWithoutSandbox
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@ -22,8 +23,10 @@ import System.FilePath ((</>), takeDirectory)
|
|||||||
-- in a cabal directory.
|
-- in a cabal directory.
|
||||||
findCradle :: IO Cradle
|
findCradle :: IO Cradle
|
||||||
findCradle = do
|
findCradle = do
|
||||||
wdir <- getCurrentDirectory
|
findCradle' =<< getCurrentDirectory
|
||||||
cabalCradle wdir ||> sandboxCradle wdir ||> plainCradle wdir
|
|
||||||
|
findCradle' :: FilePath -> IO Cradle
|
||||||
|
findCradle' dir = cabalCradle dir ||> sandboxCradle dir ||> plainCradle dir
|
||||||
|
|
||||||
cabalCradle :: FilePath -> IO Cradle
|
cabalCradle :: FilePath -> IO Cradle
|
||||||
cabalCradle wdir = do
|
cabalCradle wdir = do
|
||||||
|
@ -9,6 +9,7 @@ module Language.Haskell.GhcMod.Monad (
|
|||||||
, GhcModState(..)
|
, GhcModState(..)
|
||||||
, runGhcMod'
|
, runGhcMod'
|
||||||
, runGhcMod
|
, runGhcMod
|
||||||
|
, newGhcModEnv
|
||||||
, withErrorHandler
|
, withErrorHandler
|
||||||
, toGhcMod
|
, toGhcMod
|
||||||
, options
|
, options
|
||||||
@ -53,6 +54,7 @@ import Control.Monad.Writer.Class
|
|||||||
import Data.IORef (IORef, readIORef, writeIORef, newIORef)
|
import Data.IORef (IORef, readIORef, writeIORef, newIORef)
|
||||||
import System.Exit (exitSuccess)
|
import System.Exit (exitSuccess)
|
||||||
import System.IO (hPutStr, hPrint, stderr)
|
import System.IO (hPutStr, hPrint, stderr)
|
||||||
|
import System.Directory (getCurrentDirectory)
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
|
|
||||||
@ -98,18 +100,23 @@ runGhcMod' r s a = do
|
|||||||
(a', s',w) <- runRWST (unGhcMod $ initGhcMonad (Just libdir) >> a) r s
|
(a', s',w) <- runRWST (unGhcMod $ initGhcMonad (Just libdir) >> a) r s
|
||||||
return (a',(s',w))
|
return (a',(s',w))
|
||||||
|
|
||||||
|
newGhcModEnv :: Options -> FilePath -> IO GhcModEnv
|
||||||
|
newGhcModEnv opt dir = do
|
||||||
|
session <- newIORef (error "empty session")
|
||||||
|
cradle <- findCradle' dir
|
||||||
|
return GhcModEnv {
|
||||||
|
gmGhcSession = session
|
||||||
|
, gmOptions = opt
|
||||||
|
, gmCradle = cradle
|
||||||
|
}
|
||||||
|
|
||||||
runGhcMod :: Options -> GhcMod a -> IO a
|
runGhcMod :: Options -> GhcMod a -> IO a
|
||||||
runGhcMod opt action = do
|
runGhcMod opt action = do
|
||||||
session <- newIORef (error "empty session")
|
env <- liftIO $ newGhcModEnv opt =<< getCurrentDirectory
|
||||||
cradle <- findCradle
|
|
||||||
let env = GhcModEnv { gmGhcSession = session
|
|
||||||
, gmOptions = opt
|
|
||||||
, gmCradle = cradle }
|
|
||||||
(a,(_,_)) <- runGhcMod' env defaultState $ do
|
(a,(_,_)) <- runGhcMod' env defaultState $ do
|
||||||
dflags <- getSessionDynFlags
|
dflags <- getSessionDynFlags
|
||||||
defaultCleanupHandler dflags $ do
|
defaultCleanupHandler dflags $ do
|
||||||
toGhcMod $ initializeFlagsWithCradle opt cradle
|
toGhcMod $ initializeFlagsWithCradle opt (gmCradle env)
|
||||||
action
|
action
|
||||||
return a
|
return a
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user