Skip to content

Commit bb9558d

Browse files
committed
Remove more CPP pragmas
1 parent cdabd1e commit bb9558d

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

ghcide/src/Development/IDE/Core/Preprocessor.hs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
22
-- SPDX-License-Identifier: Apache-2.0
3-
{-# LANGUAGE CPP #-}
43

54
module Development.IDE.Core.Preprocessor
65
( preprocessor
@@ -59,7 +58,7 @@ preprocessor env filename mbContents = do
5958
else do
6059
cppLogs <- liftIO $ newIORef []
6160
contents <- ExceptT
62-
$ (Right <$> (runCpp dflags {log_action = logAction cppLogs} filename
61+
$ (Right <$> (runCpp dflags {log_action = logActionCompat $ logAction cppLogs} filename
6362
$ if isOnDisk then Nothing else Just contents))
6463
`catch`
6564
( \(e :: GhcException) -> do
@@ -79,12 +78,8 @@ preprocessor env filename mbContents = do
7978
(opts, dflags) <- ExceptT $ parsePragmasIntoDynFlags env filename contents
8079
return (contents, opts, dflags)
8180
where
82-
logAction :: IORef [CPPLog] -> LogAction
83-
#if __GLASGOW_HASKELL__ >= 900
84-
logAction cppLogs dflags _reason severity srcSpan msg = do
85-
#else
81+
logAction :: IORef [CPPLog] -> LogActionCompat
8682
logAction cppLogs dflags _reason severity srcSpan _style msg = do
87-
#endif
8883
let log = CPPLog severity srcSpan $ T.pack $ showSDoc dflags msg
8984
modifyIORef cppLogs (log :)
9085

ghcide/src/Development/IDE/GHC/Compat.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ module Development.IDE.GHC.Compat(
114114
stringToUnit,
115115
rtsUnit,
116116

117+
LogActionCompat,
118+
logActionCompat,
119+
117120
module GHC,
118121
module DynFlags,
119122
initializePlugins,
@@ -404,7 +407,19 @@ oldFormatErrDoc dflags = Err.formatErrDoc dummySDocContext
404407
-- oldFormatErrDoc = Err.formatErrDoc . undefined
405408
writeIfaceFile = writeIface
406409

410+
type LogActionCompat = DynFlags -> WarnReason -> Severity -> SrcSpan -> PrintUnqualified -> Out.SDoc -> IO ()
411+
412+
-- alwaysQualify seems to still do the right thing here, according to the "unqualified warnings" test.
413+
logActionCompat :: LogActionCompat -> LogAction
414+
logActionCompat logAction dynFlags wr severity loc = logAction dynFlags wr severity loc alwaysQualify
415+
407416
#else
417+
418+
type LogActionCompat = DynFlags -> WarnReason -> Severity -> SrcSpan -> PrintUnqualified -> Out.SDoc -> IO ()
419+
420+
logActionCompat :: LogActionCompat -> LogAction
421+
logActionCompat logAction dynFlags wr severity loc style = logAction dynFlags wr severity loc (Out.queryQual style)
422+
408423
type Unit = Module.UnitId
409424
-- type PackageConfig = Packages.PackageConfig
410425
definiteUnitId :: Module.DefUnitId -> UnitId

ghcide/src/Development/IDE/GHC/Warnings.hs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
22
-- SPDX-License-Identifier: Apache-2.0
3-
{-# LANGUAGE CPP #-}
43
{-# LANGUAGE ExplicitNamespaces #-}
54

65
module Development.IDE.GHC.Warnings(withWarnings) where
@@ -12,6 +11,8 @@ import GhcPlugins as GHC hiding (Var, (<>))
1211
import Control.Concurrent.Strict
1312
import qualified Data.Text as T
1413

14+
import Development.IDE.GHC.Compat (LogActionCompat,
15+
logActionCompat)
1516
import Development.IDE.GHC.Error
1617
import Development.IDE.Types.Diagnostics
1718
import Language.LSP.Types (type (|?) (..))
@@ -29,18 +30,11 @@ import Language.LSP.Types (type (|?) (..))
2930
withWarnings :: T.Text -> ((ModSummary -> ModSummary) -> IO a) -> IO ([(WarnReason, FileDiagnostic)], a)
3031
withWarnings diagSource action = do
3132
warnings <- newVar []
32-
#if __GLASGOW_HASKELL__ >= 900
33-
let newAction :: DynFlags -> WarnReason -> Severity -> SrcSpan -> MsgDoc -> IO ()
34-
newAction dynFlags wr _ loc msg = do
35-
let prUnqual = alwaysQualify :: PrintUnqualified -- TODO: Do something proper here
36-
#else
37-
let newAction :: DynFlags -> WarnReason -> Severity -> SrcSpan -> PprStyle -> SDoc -> IO ()
38-
newAction dynFlags wr _ loc style msg = do
39-
let prUnqual = queryQual style
40-
#endif
33+
let newAction :: LogActionCompat
34+
newAction dynFlags wr _ loc prUnqual msg = do
4135
let wr_d = map ((wr,) . third3 (attachReason wr)) $ diagFromErrMsg diagSource dynFlags $ mkWarnMsg dynFlags loc prUnqual msg
4236
modifyVar_ warnings $ return . (wr_d:)
43-
res <- action $ \x -> x{ms_hspp_opts = (ms_hspp_opts x){log_action = newAction}}
37+
res <- action $ \x -> x{ms_hspp_opts = (ms_hspp_opts x){log_action = logActionCompat newAction}}
4438
warns <- readVar warnings
4539
return (reverse $ concat warns, res)
4640

0 commit comments

Comments
 (0)