@@ -17,16 +17,24 @@ module Development.IDE.GHC.Compat.Error (
1717 DriverMessage (.. ),
1818 -- * General Diagnostics
1919 Diagnostic (.. ),
20- -- * Prisms for error selection
20+ -- * Prisms and lenses for error selection
2121 _TcRnMessage ,
2222 _TcRnMessageWithCtx ,
2323 _GhcPsMessage ,
2424 _GhcDsMessage ,
2525 _GhcDriverMessage ,
2626 _TcRnMissingSignature ,
27+ _TcRnSolverReport ,
28+ _TcRnMessageWithInfo ,
29+ reportContextL ,
30+ reportContentL ,
31+ _MismatchMessage ,
32+ _TypeEqMismatchActual ,
33+ _TypeEqMismatchExpected ,
2734 ) where
2835
2936import Control.Lens
37+ import Development.IDE.GHC.Compat (Type )
3038import GHC.Driver.Errors.Types
3139import GHC.HsToCore.Errors.Types
3240import GHC.Tc.Errors.Types
@@ -82,3 +90,36 @@ msgEnvelopeErrorL :: Lens' (MsgEnvelope e) e
8290msgEnvelopeErrorL = lens errMsgDiagnostic (\ envelope e -> envelope { errMsgDiagnostic = e } )
8391
8492makePrisms ''TcRnMessage
93+
94+ makeLensesWith
95+ (lensRules & lensField .~ mappingNamer (pure . (++ " L" )))
96+ ''SolverReportWithCtxt
97+
98+ -- | Focus 'MismatchMsg' from 'TcSolverReportMsg'. Currently, 'MismatchMsg' can be
99+ -- extracted from 'CannotUnifyVariable' and 'Mismatch' constructors.
100+ _MismatchMessage :: Traversal' TcSolverReportMsg MismatchMsg
101+ _MismatchMessage focus (Mismatch msg t a c) = (\ msg' -> Mismatch msg' t a c) <$> focus msg
102+ _MismatchMessage focus (CannotUnifyVariable msg a) = flip CannotUnifyVariable a <$> focus msg
103+ _MismatchMessage _ report = pure report
104+
105+ -- | Focus 'teq_mismatch_expected' from 'TypeEqMismatch'.
106+ _TypeEqMismatchExpected :: Traversal' MismatchMsg Type
107+ #if MIN_VERSION_ghc(9,10,2)
108+ _TypeEqMismatchExpected focus mismatch@ (TypeEqMismatch _ _ _ expected _ _ _) =
109+ (\ expected' -> mismatch { teq_mismatch_expected = expected' }) <$> focus expected
110+ #else
111+ _TypeEqMismatchExpected focus mismatch@ (TypeEqMismatch _ _ _ _ expected _ _ _) =
112+ (\ expected' -> mismatch { teq_mismatch_expected = expected' }) <$> focus expected
113+ #endif
114+ _TypeEqMismatchExpected _ mismatch = pure mismatch
115+
116+ -- | Focus 'teq_mismatch_actual' from 'TypeEqMismatch'.
117+ _TypeEqMismatchActual :: Traversal' MismatchMsg Type
118+ #if MIN_VERSION_ghc(9,10,2)
119+ _TypeEqMismatchActual focus mismatch@ (TypeEqMismatch _ _ _ _ actual _ _) =
120+ (\ actual' -> mismatch { teq_mismatch_actual = actual' }) <$> focus actual
121+ #else
122+ _TypeEqMismatchActual focus mismatch@ (TypeEqMismatch _ _ _ _ _ actual _ _) =
123+ (\ actual' -> mismatch { teq_mismatch_expected = actual' }) <$> focus actual
124+ #endif
125+ _TypeEqMismatchActual _ mismatch = pure mismatch
0 commit comments