Skip to content

Commit 76aea30

Browse files
committed
Make hdevtools compatible with ghc-7.6
1 parent 82e9728 commit 76aea30

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

src/CommandLoop.hs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
{-# LANGUAGE CPP #-}
12
module CommandLoop
23
( startCommandLoop
34
) where
45

5-
import ErrUtils (Message, mkLocMessage)
6+
import qualified ErrUtils
67
import GHC (Ghc, GhcException, GhcLink(NoLink), HscTarget(HscInterpreted), LoadHowMuch(LoadAllTargets), Severity, SrcSpan, SuccessFlag(Succeeded, Failed), gcatch, getSessionDynFlags, ghcLink, guessTarget, handleSourceError, hscTarget, load, log_action, noLoc, parseDynamicFlags, printException, runGhc, setSessionDynFlags, setTargets, showGhcException)
8+
import qualified GHC
79
import GHC.Paths (libdir)
810
import MonadUtils (MonadIO, liftIO)
911
import Outputable (PprStyle, renderWithStyle)
@@ -116,9 +118,18 @@ runCommand clientSend (CmdType file (line, col)) = do
116118
, "\"", t, "\""
117119
]
118120

119-
logAction :: ClientSend -> Severity -> SrcSpan -> PprStyle -> Message -> IO ()
121+
#if __GLASGOW_HASKELL__ >= 706
122+
logAction :: ClientSend -> GHC.DynFlags -> Severity -> SrcSpan -> PprStyle -> ErrUtils.MsgDoc -> IO ()
123+
logAction clientSend dflags severity srcspan style msg =
124+
let out = renderWithStyle dflags fullMsg style
125+
_ = severity
126+
in clientSend (ClientStdout out)
127+
where fullMsg = ErrUtils.mkLocMessage severity srcspan msg
128+
#else
129+
logAction :: ClientSend -> Severity -> SrcSpan -> PprStyle -> ErrUtils.Message -> IO ()
120130
logAction clientSend severity srcspan style msg =
121131
let out = renderWithStyle fullMsg style
122132
_ = severity
123133
in clientSend (ClientStdout out)
124-
where fullMsg = mkLocMessage srcspan msg
134+
where fullMsg = ErrUtils.mkLocMessage srcspan msg
135+
#endif

src/Info.hs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE RankNTypes #-}
23
module Info
34
( getIdentifierInfo
@@ -12,6 +13,7 @@ import Data.Typeable (Typeable)
1213
import MonadUtils (liftIO)
1314
import qualified CoreUtils
1415
import qualified Desugar
16+
import qualified DynFlags
1517
import qualified GHC
1618
import qualified HscTypes
1719
import qualified NameSet
@@ -24,7 +26,11 @@ import qualified TcRnTypes
2426
getIdentifierInfo :: FilePath -> String -> GHC.Ghc (Either String String)
2527
getIdentifierInfo file identifier =
2628
withModSummary file $ \m -> do
29+
#if __GLASGOW_HASKELL__ >= 706
30+
GHC.setContext [GHC.IIModule (GHC.moduleName (GHC.ms_mod m))]
31+
#else
2732
GHC.setContext [GHC.IIModule (GHC.ms_mod m)]
33+
#endif
2834
GHC.handleSourceError (return . Left . show) $
2935
liftM Right (infoThing identifier)
3036

@@ -84,15 +90,26 @@ processTypeCheckedModule tcm (line, col) = do
8490
bts <- mapM (getTypeLHsBind tcm) bs
8591
ets <- mapM (getTypeLHsExpr tcm) es
8692
pts <- mapM (getTypeLPat tcm) ps
87-
return $ map toTup $ sortBy cmp $ catMaybes $ concat [ets, bts, pts]
93+
#if __GLASGOW_HASKELL__ >= 706
94+
dflags <- DynFlags.getDynFlags
95+
return $ map (toTup dflags) $
96+
#else
97+
return $ map toTup $
98+
#endif
99+
sortBy cmp $ catMaybes $ concat [ets, bts, pts]
88100
where
89101
cmp (a, _) (b, _)
90102
| a `GHC.isSubspanOf` b = LT
91103
| b `GHC.isSubspanOf` a = GT
92104
| otherwise = EQ
93105

106+
#if __GLASGOW_HASKELL__ >= 706
107+
toTup :: GHC.DynFlags -> (GHC.SrcSpan, GHC.Type) -> ((Int, Int, Int, Int), String)
108+
toTup dflags (spn, typ) = (fourInts spn, pretty dflags typ)
109+
#else
94110
toTup :: (GHC.SrcSpan, GHC.Type) -> ((Int, Int, Int, Int), String)
95111
toTup (spn, typ) = (fourInts spn, pretty typ)
112+
#endif
96113

97114
fourInts :: GHC.SrcSpan -> (Int, Int, Int, Int)
98115
fourInts = fromMaybe (0, 0, 0, 0) . getSrcSpan
@@ -133,10 +150,20 @@ listifySpans tcs lc = listifyStaged TypeChecker p tcs
133150
listifyStaged :: Typeable r => Stage -> (r -> Bool) -> GenericQ [r]
134151
listifyStaged s p = everythingStaged s (++) [] ([] `mkQ` (\x -> [x | p x]))
135152

153+
#if __GLASGOW_HASKELL__ >= 706
154+
pretty :: GHC.DynFlags -> GHC.Type -> String
155+
pretty dflags =
156+
#else
136157
pretty :: GHC.Type -> String
137158
pretty =
159+
#endif
138160
Pretty.showDocWith Pretty.OneLineMode
139-
. Outputable.withPprStyleDoc (Outputable.mkUserStyle Outputable.neverQualify Outputable.AllTheWay)
161+
#if __GLASGOW_HASKELL__ >= 706
162+
. Outputable.withPprStyleDoc dflags
163+
#else
164+
. Outputable.withPprStyleDoc
165+
#endif
166+
(Outputable.mkUserStyle Outputable.neverQualify Outputable.AllTheWay)
140167
. PprTyThing.pprTypeForUser False
141168

142169
------------------------------------------------------------------------------
@@ -170,7 +197,12 @@ infoThing str = do
170197
mb_stuffs <- mapM GHC.getInfo names
171198
let filtered = filterOutChildren (\(t,_f,_i) -> t) (catMaybes mb_stuffs)
172199
unqual <- GHC.getPrintUnqual
200+
#if __GLASGOW_HASKELL__ >= 706
201+
dflags <- DynFlags.getDynFlags
202+
return $ Outputable.showSDocForUser dflags unqual $
203+
#else
173204
return $ Outputable.showSDocForUser unqual $
205+
#endif
174206
Outputable.vcat (intersperse (Outputable.text "") $ map (pprInfo False) filtered)
175207

176208
-- Filter out names whose parent is also there Good
@@ -185,7 +217,11 @@ filterOutChildren get_thing xs
185217
Just p -> GHC.getName p `NameSet.elemNameSet` all_names
186218
Nothing -> False
187219

220+
#if __GLASGOW_HASKELL__ >= 706
221+
pprInfo :: PprTyThing.PrintExplicitForalls -> (HscTypes.TyThing, GHC.Fixity, [GHC.ClsInst]) -> Outputable.SDoc
222+
#else
188223
pprInfo :: PprTyThing.PrintExplicitForalls -> (HscTypes.TyThing, GHC.Fixity, [GHC.Instance]) -> Outputable.SDoc
224+
#endif
189225
pprInfo pefas (thing, fixity, insts) =
190226
PprTyThing.pprTyThingInContextLoc pefas thing
191227
Outputable.$$ show_fixity fixity

0 commit comments

Comments
 (0)