forked from haskell/haskell-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOutputable.hs
172 lines (153 loc) · 4.95 KB
/
Outputable.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
{-# LANGUAGE CPP #-}
module Development.IDE.GHC.Compat.Outputable (
SDoc,
Outputable,
showSDoc,
showSDocUnsafe,
showSDocForUser,
ppr, pprPanic, text, vcat, (<+>), ($$), empty, hang, nest,
printSDocQualifiedUnsafe,
printNameWithoutUniques,
printSDocAllTheWay,
mkPrintUnqualified,
mkPrintUnqualifiedDefault,
PrintUnqualified(..),
-- * Parser errors
PsWarning,
PsError,
pprWarning,
pprError,
-- * Error infrastructure
DecoratedSDoc,
MsgEnvelope,
errMsgSpan,
errMsgSeverity,
formatErrorWithQual,
mkWarnMsg,
mkSrcErr,
srcErrorMessages,
) where
#if MIN_VERSION_ghc(9,2,0)
import GHC.Driver.Ppr
import GHC.Driver.Session
import GHC.Parser.Errors
import qualified GHC.Parser.Errors.Ppr as Ppr
import qualified GHC.Types.Error as Error
import GHC.Types.Name.Ppr
import GHC.Types.Name.Reader
import GHC.Types.SourceError
import GHC.Types.SrcLoc
import GHC.Unit.State
import GHC.Utils.Error hiding (mkWarnMsg)
import GHC.Utils.Logger
import GHC.Utils.Outputable
import GHC.Utils.Panic
#elif MIN_VERSION_ghc(9,0,0)
import GHC.Driver.Session
import GHC.Driver.Types as HscTypes
import GHC.Types.Name.Reader (GlobalRdrEnv)
import GHC.Types.SrcLoc
import GHC.Utils.Error as Err hiding (mkWarnMsg)
import qualified GHC.Utils.Error as Err
import GHC.Utils.Outputable as Out
#else
import Development.IDE.GHC.Compat.Core (GlobalRdrEnv)
import DynFlags
import ErrUtils hiding (mkWarnMsg)
import qualified ErrUtils as Err
import HscTypes
import Outputable as Out
import SrcLoc
#endif
printNameWithoutUniques :: Outputable a => a -> String
printNameWithoutUniques =
#if MIN_VERSION_ghc(9,2,0)
renderWithContext (defaultSDocContext { sdocSuppressUniques = True }) . ppr
#else
printSDocAllTheWay dyn . ppr
where
dyn = unsafeGlobalDynFlags `gopt_set` Opt_SuppressUniques
#endif
printSDocQualifiedUnsafe :: PrintUnqualified -> SDoc -> String
#if MIN_VERSION_ghc(9,2,0)
printSDocQualifiedUnsafe unqual doc =
-- Taken from 'showSDocForUser'
renderWithContext (defaultSDocContext { sdocStyle = sty }) doc'
where
sty = mkUserStyle unqual AllTheWay
doc' = pprWithUnitState emptyUnitState doc
#else
printSDocQualifiedUnsafe unqual doc =
showSDocForUser unsafeGlobalDynFlags unqual doc
#endif
printSDocAllTheWay :: DynFlags -> SDoc -> String
#if MIN_VERSION_ghc(9,2,0)
printSDocAllTheWay dflags sdoc = renderWithContext ctxt sdoc
where
ctxt = initSDocContext dflags (mkUserStyle neverQualify AllTheWay)
#else
printSDocAllTheWay dflags sdoc = oldRenderWithStyle dflags sdoc (oldMkUserStyle dflags Out.neverQualify Out.AllTheWay)
#if MIN_VERSION_ghc(9,0,0)
oldRenderWithStyle dflags sdoc sty = Out.renderWithStyle (initSDocContext dflags sty) sdoc
oldMkUserStyle _ = Out.mkUserStyle
oldMkErrStyle _ = Out.mkErrStyle
oldFormatErrDoc :: DynFlags -> Err.ErrDoc -> Out.SDoc
oldFormatErrDoc dflags = Err.formatErrDoc dummySDocContext
where dummySDocContext = initSDocContext dflags Out.defaultUserStyle
#else
oldRenderWithStyle :: DynFlags -> Out.SDoc -> Out.PprStyle -> String
oldRenderWithStyle = Out.renderWithStyle
oldMkUserStyle :: DynFlags -> Out.PrintUnqualified -> Out.Depth -> Out.PprStyle
oldMkUserStyle = Out.mkUserStyle
oldMkErrStyle :: DynFlags -> Out.PrintUnqualified -> Out.PprStyle
oldMkErrStyle = Out.mkErrStyle
oldFormatErrDoc :: DynFlags -> Err.ErrDoc -> Out.SDoc
oldFormatErrDoc = Err.formatErrDoc
#endif
#endif
pprWarning :: PsWarning -> MsgEnvelope DecoratedSDoc
pprWarning =
#if MIN_VERSION_ghc(9,2,0)
Ppr.pprWarning
#else
id
#endif
pprError :: PsError -> MsgEnvelope DecoratedSDoc
pprError =
#if MIN_VERSION_ghc(9,2,0)
Ppr.pprError
#else
id
#endif
formatErrorWithQual :: DynFlags -> MsgEnvelope DecoratedSDoc -> String
formatErrorWithQual dflags e =
#if MIN_VERSION_ghc(9,2,0)
showSDoc dflags (pprLocMsgEnvelope e)
#else
Out.showSDoc dflags
$ Out.withPprStyle (oldMkErrStyle dflags $ errMsgContext e)
$ oldFormatErrDoc dflags
$ Err.errMsgDoc e
#endif
#if !MIN_VERSION_ghc(9,2,0)
type DecoratedSDoc = ()
type MsgEnvelope e = ErrMsg
type PsWarning = ErrMsg
type PsError = ErrMsg
#endif
mkPrintUnqualifiedDefault :: GlobalRdrEnv -> PrintUnqualified
mkPrintUnqualifiedDefault =
#if MIN_VERSION_ghc(9,2,0)
-- GHC 9.2.1 version
-- mkPrintUnqualified :: UnitEnv -> GlobalRdrEnv -> PrintUnqualified
mkPrintUnqualified unsafeGlobalDynFlags
#else
HscTypes.mkPrintUnqualified unsafeGlobalDynFlags
#endif
mkWarnMsg :: DynFlags -> SrcSpan -> PrintUnqualified -> SDoc -> MsgEnvelope DecoratedSDoc
mkWarnMsg =
#if MIN_VERSION_ghc(9,2,0)
const Error.mkWarnMsg
#else
Err.mkWarnMsg
#endif