@@ -19,9 +19,11 @@ module Development.IDE.GHC.Compat.Error (
19
19
Diagnostic (.. ),
20
20
-- * Prisms for error selection
21
21
_TcRnMessage ,
22
+ _TcRnMessageWithCtx ,
22
23
_GhcPsMessage ,
23
24
_GhcDsMessage ,
24
25
_GhcDriverMessage ,
26
+ _TcRnMissingSignature ,
25
27
) where
26
28
27
29
import Control.Lens
@@ -30,8 +32,20 @@ import GHC.HsToCore.Errors.Types
30
32
import GHC.Tc.Errors.Types
31
33
import GHC.Types.Error
32
34
33
- _TcRnMessage :: Prism' GhcMessage TcRnMessage
34
- _TcRnMessage = prism' GhcTcRnMessage (\ case
35
+ -- | Some 'TcRnMessage's are nested in other constructors for additional context.
36
+ -- For example, 'TcRnWithHsDocContext' and 'TcRnMessageWithInfo'.
37
+ -- However, in most occasions you don't need the additional context and you just want
38
+ -- the error message. @'_TcRnMessage'@ recursively unwraps these constructors,
39
+ -- until there are no more constructors with additional context.
40
+ --
41
+ -- Use @'_TcRnMessageWithCtx'@ if you need the additional context. You can always
42
+ -- strip it later using @'stripTcRnMessageContext'@.
43
+ --
44
+ _TcRnMessage :: Fold GhcMessage TcRnMessage
45
+ _TcRnMessage = _TcRnMessageWithCtx . to stripTcRnMessageContext
46
+
47
+ _TcRnMessageWithCtx :: Prism' GhcMessage TcRnMessage
48
+ _TcRnMessageWithCtx = prism' GhcTcRnMessage (\ case
35
49
GhcTcRnMessage tcRnMsg -> Just tcRnMsg
36
50
_ -> Nothing )
37
51
@@ -66,3 +80,5 @@ stripTcRnMessageContext = \case
66
80
67
81
msgEnvelopeErrorL :: Lens' (MsgEnvelope e ) e
68
82
msgEnvelopeErrorL = lens errMsgDiagnostic (\ envelope e -> envelope { errMsgDiagnostic = e } )
83
+
84
+ makePrisms ''TcRnMessage
0 commit comments