Rearrange loadTargets code.

The loadTargets function is exposed via the Internal module for use by
external programmes, such as HaRe.

Re-arrange to code so that it can still be called with a list of string
targets, as it was before.
This commit is contained in:
Alan Zimmerman 2015-08-18 10:54:55 +02:00 committed by Daniel Gröber
parent bb3a948912
commit e198f68f2a
2 changed files with 17 additions and 15 deletions

View File

@ -40,6 +40,7 @@ module Language.Haskell.GhcMod.Internal (
, cradle
, getCompilerMode
, setCompilerMode
, targetGhcOptions
, withOptions
-- * 'GhcModError'
, gmeDoc

View File

@ -137,20 +137,8 @@ runGmlTWith efnmns' mdf wrapper action = do
let targetStrs = mappedStrs ++ map moduleNameString mns ++ cfns
unGmlT $ wrapper $ do
targets <-
withLightHscEnv opts $ \env ->
liftM (nubBy ((==) `on` targetId))
(mapM ((`guessTarget` Nothing) >=> mapFile env) targetStrs)
>>= mapM relativize
loadTargets targets
loadTargets opts targetStrs
action
where
relativize (Target (TargetFile filePath phase) taoc src) = do
crdl <- cradle
let tid = TargetFile relativeFilePath phase
relativeFilePath = makeRelative (cradleRootDir crdl) filePath
return $ Target tid taoc src
relativize tgt = return tgt
targetGhcOptions :: forall m. IOish m
=> Cradle
@ -413,8 +401,14 @@ resolveGmComponents mumns cs = do
same f a b = (f a) == (f b)
-- | Set the files as targets and load them.
loadTargets :: IOish m => [Target] -> GmlT m ()
loadTargets targets = do
loadTargets :: IOish m => [GHCOption] -> [FilePath] -> GmlT m ()
loadTargets opts targetStrs = do
targets <-
withLightHscEnv opts $ \env ->
liftM (nubBy ((==) `on` targetId))
(mapM ((`guessTarget` Nothing) >=> mapFile env) targetStrs)
>>= mapM relativize
gmLog GmDebug "loadTargets" $
text "Loading" <+>: fsep (map (text . showTargetId) targets)
@ -435,6 +429,13 @@ loadTargets targets = do
else
loadTargets' Simple
where
relativize (Target (TargetFile filePath phase) taoc src) = do
crdl <- cradle
let tid = TargetFile relativeFilePath phase
relativeFilePath = makeRelative (cradleRootDir crdl) filePath
return $ Target tid taoc src
relativize tgt = return tgt
loadTargets' Simple = do
void $ load LoadAllTargets
mapM_ (parseModule >=> typecheckModule >=> desugarModule) =<< getModuleGraph