refactoring.
This commit is contained in:
parent
2aa47fc449
commit
8142ccbc64
@ -167,27 +167,32 @@ checkStx :: Options
|
|||||||
-> FilePath
|
-> FilePath
|
||||||
-> Ghc (String, Bool, Set FilePath)
|
-> Ghc (String, Bool, Set FilePath)
|
||||||
checkStx opt set file = do
|
checkStx opt set file = do
|
||||||
let add = not $ S.member file set
|
|
||||||
GE.ghandle handler $ do
|
GE.ghandle handler $ do
|
||||||
mdel <- removeMainTarget
|
(set',add) <- removeMainTarget file set
|
||||||
ret <- withLogger opt $ do
|
ret <- withLogger opt $ do
|
||||||
when add $ addTargetFiles [file]
|
when add $ addTargetFiles [file]
|
||||||
void $ G.load LoadAllTargets
|
void $ G.load LoadAllTargets
|
||||||
let set1 = if add then S.insert file set else set
|
return (ret, True, set')
|
||||||
set2 = case mdel of
|
|
||||||
Nothing -> set1
|
|
||||||
Just delfl -> S.delete delfl set1
|
|
||||||
return (ret, True, set2)
|
|
||||||
where
|
where
|
||||||
handler :: SourceError -> Ghc (String, Bool, Set FilePath)
|
handler :: SourceError -> Ghc (String, Bool, Set FilePath)
|
||||||
handler err = do
|
handler err = do
|
||||||
ret <- handleErrMsg opt err
|
ret <- handleErrMsg opt err
|
||||||
return (ret, True, set)
|
return (ret, True, set)
|
||||||
removeMainTarget = do
|
|
||||||
|
removeMainTarget :: FilePath -> Set FilePath -> Ghc (Set FilePath, Bool)
|
||||||
|
removeMainTarget file set = do
|
||||||
mx <- find isMain <$> G.getModuleGraph
|
mx <- find isMain <$> G.getModuleGraph
|
||||||
case mx of
|
mdel <- tryRemove mx
|
||||||
Nothing -> return Nothing
|
let set' = del mdel
|
||||||
Just x -> do
|
return (set',add)
|
||||||
|
where
|
||||||
|
add = not $ S.member file set
|
||||||
|
set1 = if add then S.insert file set else set
|
||||||
|
del Nothing = set1
|
||||||
|
del (Just delfl) = S.delete delfl set1
|
||||||
|
isMain m = G.moduleNameString (G.moduleName (G.ms_mod m)) == "Main"
|
||||||
|
tryRemove Nothing = return Nothing
|
||||||
|
tryRemove (Just x) = do
|
||||||
let mmainfile = G.ml_hs_file (G.ms_location x)
|
let mmainfile = G.ml_hs_file (G.ms_location x)
|
||||||
-- G.ms_hspp_file x is a temporary file with CPP.
|
-- G.ms_hspp_file x is a temporary file with CPP.
|
||||||
-- this is a just fake.
|
-- this is a just fake.
|
||||||
@ -198,7 +203,6 @@ checkStx opt set file = do
|
|||||||
let target = TargetFile mainfile Nothing
|
let target = TargetFile mainfile Nothing
|
||||||
G.removeTarget target
|
G.removeTarget target
|
||||||
return $ Just mainfile
|
return $ Just mainfile
|
||||||
isMain m = G.moduleNameString (G.moduleName (G.ms_mod m)) == "Main"
|
|
||||||
|
|
||||||
findSym :: Options -> Set FilePath -> String -> MVar SymMdlDb
|
findSym :: Options -> Set FilePath -> String -> MVar SymMdlDb
|
||||||
-> Ghc (String, Bool, Set FilePath)
|
-> Ghc (String, Bool, Set FilePath)
|
||||||
@ -240,7 +244,7 @@ showInfo :: Options
|
|||||||
-> Ghc (String, Bool, Set FilePath)
|
-> Ghc (String, Bool, Set FilePath)
|
||||||
showInfo opt set fileArg = do
|
showInfo opt set fileArg = do
|
||||||
let [file, expr] = words fileArg
|
let [file, expr] = words fileArg
|
||||||
(_, _, set') <- checkStx opt set file
|
(set',_) <- removeMainTarget file set
|
||||||
ret <- info opt file expr
|
ret <- info opt file expr
|
||||||
return (ret, True, set')
|
return (ret, True, set')
|
||||||
|
|
||||||
@ -250,7 +254,7 @@ showType :: Options
|
|||||||
-> Ghc (String, Bool, Set FilePath)
|
-> Ghc (String, Bool, Set FilePath)
|
||||||
showType opt set fileArg = do
|
showType opt set fileArg = do
|
||||||
let [file, line, column] = words fileArg
|
let [file, line, column] = words fileArg
|
||||||
(_, _, set') <- checkStx opt set file
|
(set',_) <- removeMainTarget file set
|
||||||
ret <- types opt file (read line) (read column)
|
ret <- types opt file (read line) (read column)
|
||||||
return (ret, True, set')
|
return (ret, True, set')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user