cosmetic change.
This commit is contained in:
parent
34f360fef7
commit
2f804f5de1
28
Info.hs
28
Info.hs
@ -23,9 +23,9 @@ typeExpr :: Options -> ModuleString -> Expression -> FilePath -> IO String
|
|||||||
typeExpr _ modstr expr file = (++ "\n") <$> typeOf file modstr expr
|
typeExpr _ modstr expr file = (++ "\n") <$> typeOf file modstr expr
|
||||||
|
|
||||||
typeOf :: FilePath -> ModuleString -> Expression -> IO String
|
typeOf :: FilePath -> ModuleString -> Expression -> IO String
|
||||||
typeOf fileName modstr expr =
|
typeOf fileName modstr expr = inModuleContext fileName modstr exprToType
|
||||||
inModuleContext fileName modstr (pretty <$> exprType expr)
|
|
||||||
where
|
where
|
||||||
|
exprToType = pretty <$> exprType expr
|
||||||
pretty = showSDocForUser neverQualify . pprTypeForUser False
|
pretty = showSDocForUser neverQualify . pprTypeForUser False
|
||||||
|
|
||||||
----------------------------------------------------------------
|
----------------------------------------------------------------
|
||||||
@ -34,9 +34,14 @@ infoExpr :: Options -> ModuleString -> Expression -> FilePath -> IO String
|
|||||||
infoExpr _ modstr expr file = (++ "\n") <$> info file modstr expr
|
infoExpr _ modstr expr file = (++ "\n") <$> info file modstr expr
|
||||||
|
|
||||||
info :: FilePath -> ModuleString -> FilePath -> IO String
|
info :: FilePath -> ModuleString -> FilePath -> IO String
|
||||||
info fileName modstr expr = inModuleContext fileName modstr (infoThing expr)
|
info fileName modstr expr = inModuleContext fileName modstr exprToInfo
|
||||||
where
|
where
|
||||||
-- ghc/InteractiveUI.hs
|
exprToInfo = infoThing expr
|
||||||
|
|
||||||
|
----------------------------------------------------------------
|
||||||
|
-- from ghc/InteractiveUI.hs
|
||||||
|
|
||||||
|
infoThing :: String -> Ghc String
|
||||||
infoThing str = do
|
infoThing str = do
|
||||||
names <- parseName str
|
names <- parseName str
|
||||||
mb_stuffs <- mapM getInfo names
|
mb_stuffs <- mapM getInfo names
|
||||||
@ -69,19 +74,13 @@ inModuleContext fileName modstr action = withGHC valid
|
|||||||
initSession ["-w"]
|
initSession ["-w"]
|
||||||
setTargetFile fileName
|
setTargetFile fileName
|
||||||
loadWithLogger (\_ -> return ()) LoadAllTargets
|
loadWithLogger (\_ -> return ()) LoadAllTargets
|
||||||
ok <- setContextFromTarget
|
mif setContextFromTarget action invalid
|
||||||
if ok
|
|
||||||
then action
|
|
||||||
else invalid
|
|
||||||
invalid = do
|
invalid = do
|
||||||
initSession ["-w"]
|
initSession ["-w"]
|
||||||
dummyModule
|
setTargetBuffer
|
||||||
loadWithLogger defaultWarnErrLogger LoadAllTargets
|
loadWithLogger defaultWarnErrLogger LoadAllTargets
|
||||||
ok <- setContextFromTarget
|
mif setContextFromTarget action (return errorMessage)
|
||||||
if ok
|
setTargetBuffer = do
|
||||||
then action
|
|
||||||
else return errorMessage
|
|
||||||
dummyModule = do
|
|
||||||
modgraph <- depanal [mkModuleName modstr] True
|
modgraph <- depanal [mkModuleName modstr] True
|
||||||
let imports = concatMap (map (showSDoc . ppr . unLoc)) $
|
let imports = concatMap (map (showSDoc . ppr . unLoc)) $
|
||||||
map ms_imps modgraph ++ map ms_srcimps modgraph
|
map ms_imps modgraph ++ map ms_srcimps modgraph
|
||||||
@ -90,6 +89,7 @@ inModuleContext fileName modstr action = withGHC valid
|
|||||||
importsBuf <- liftIO . stringToStringBuffer . unlines $ header
|
importsBuf <- liftIO . stringToStringBuffer . unlines $ header
|
||||||
clkTime <- liftIO getClockTime
|
clkTime <- liftIO getClockTime
|
||||||
setTargets [Target (TargetModule $ mkModuleName modstr) True (Just (importsBuf, clkTime))]
|
setTargets [Target (TargetModule $ mkModuleName modstr) True (Just (importsBuf, clkTime))]
|
||||||
|
mif m t e = m >>= \ok -> if ok then t else e
|
||||||
sanitize = fromMaybe "SomeModule" . listToMaybe . words
|
sanitize = fromMaybe "SomeModule" . listToMaybe . words
|
||||||
errorMessage = "Couldn't determine type"
|
errorMessage = "Couldn't determine type"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user