@@ -19,9 +19,11 @@ module Development.IDE.GHC.Compat.Error (
1919 Diagnostic (.. ),
2020 -- * Prisms for error selection
2121 _TcRnMessage ,
22+ _TcRnMessageWithCtx ,
2223 _GhcPsMessage ,
2324 _GhcDsMessage ,
2425 _GhcDriverMessage ,
26+ _TcRnMissingSignature ,
2527 ) where
2628
2729import Control.Lens
@@ -30,8 +32,20 @@ import GHC.HsToCore.Errors.Types
3032import GHC.Tc.Errors.Types
3133import GHC.Types.Error
3234
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
3549 GhcTcRnMessage tcRnMsg -> Just tcRnMsg
3650 _ -> Nothing )
3751
@@ -66,3 +80,5 @@ stripTcRnMessageContext = \case
6680
6781msgEnvelopeErrorL :: Lens' (MsgEnvelope e ) e
6882msgEnvelopeErrorL = lens errMsgDiagnostic (\ envelope e -> envelope { errMsgDiagnostic = e } )
83+
84+ makePrisms ''TcRnMessage
0 commit comments