Skip to content

Commit

Permalink
Minor refactorings.
Browse files Browse the repository at this point in the history
  • Loading branch information
nominolo committed Apr 8, 2009
1 parent 9b8962b commit 807df2e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
22 changes: 13 additions & 9 deletions src/Scion/Session.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Exception


import Scion.Types import Scion.Types
import Scion.Types.Notes import Scion.Types.Notes
import Scion.Utils() import Scion.Utils


import qualified Data.MultiSet as MS import qualified Data.MultiSet as MS
import Control.Monad import Control.Monad
Expand Down Expand Up @@ -523,16 +523,18 @@ backgroundTypecheckFile ::
FilePath FilePath
-> ScionM (Bool, CompilationResult) -> ScionM (Bool, CompilationResult)
-- ^ First element is @False@ <=> step 1 above failed. -- ^ First element is @False@ <=> step 1 above failed.
backgroundTypecheckFile fname = do backgroundTypecheckFile fname =
ok <- isRelativeToProjectRoot fname ifM (not `fmap` isRelativeToProjectRoot fname)
if not ok then return (False, mempty) (return (False, mempty))
else do prepareContext
-- check whether it's cached where
prepareContext = do
-- if it's the focused module, we know that the context is right
mb_focusmod <- gets focusedModule mb_focusmod <- gets focusedModule
case mb_focusmod of case mb_focusmod of
Just ms | Just f <- ml_hs_file (ms_location ms) Just ms | Just f <- ml_hs_file (ms_location ms), f == fname ->
, f == fname ->
backgroundTypecheckFile' mempty backgroundTypecheckFile' mempty

_otherwise -> do _otherwise -> do
mb_modsum <- filePathToProjectModule fname mb_modsum <- filePathToProjectModule fname
case mb_modsum of case mb_modsum of
Expand All @@ -542,7 +544,7 @@ backgroundTypecheckFile fname = do
if compilationSucceeded rslt if compilationSucceeded rslt
then backgroundTypecheckFile' rslt then backgroundTypecheckFile' rslt
else return (True, rslt) else return (True, rslt)
where
backgroundTypecheckFile' comp_rslt = do backgroundTypecheckFile' comp_rslt = do
message verbose $ "Background type checking: " ++ fname message verbose $ "Background type checking: " ++ fname
clearWarnings clearWarnings
Expand Down Expand Up @@ -622,6 +624,8 @@ isPartOfProject fname = fmap isJust (filePathToProjectModule fname)
-- Sets 'focusedModule' if it was successful. -- Sets 'focusedModule' if it was successful.
setContextForBGTC :: ModSummary -> ScionM (Maybe ModuleName, CompilationResult) setContextForBGTC :: ModSummary -> ScionM (Maybe ModuleName, CompilationResult)
setContextForBGTC modsum = do setContextForBGTC modsum = do
message deafening $ "Setting context for: " ++
moduleNameString (moduleName (ms_mod modsum))
let mod_name = ms_mod_name modsum let mod_name = ms_mod_name modsum
start_time <- liftIO $ getCurrentTime start_time <- liftIO $ getCurrentTime
r <- load (LoadDependenciesOf mod_name) r <- load (LoadDependenciesOf mod_name)
Expand Down
7 changes: 6 additions & 1 deletion src/Scion/Utils.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ unqualifiedForModule tcm = do
fromMaybe alwaysQualify `fmap` mkPrintUnqualifiedForModule (moduleInfo tcm) fromMaybe alwaysQualify `fmap` mkPrintUnqualifiedForModule (moduleInfo tcm)


second :: (a -> b) -> (c, a) -> (c, b) second :: (a -> b) -> (c, a) -> (c, b)
second f (x,y) = (x, f y) second f (x,y) = (x, f y)

ifM :: Monad m => m Bool -> m a -> m a -> m a
ifM cm tm em = do
c <- cm
if c then tm else em

0 comments on commit 807df2e

Please sign in to comment.