@@ -52,6 +52,7 @@ import Ide.Types (Config, HandlerM,
52
52
import Language.LSP.Protocol.Message
53
53
import Language.LSP.Protocol.Types
54
54
import Text.Regex.TDFA ((=~) )
55
+ import Control.Applicative (liftA )
55
56
56
57
data Log
57
58
= LogErrInfoCtxt ErrInfo
@@ -138,12 +139,13 @@ diagnosticToChangeSig recorder decls diagnostic = runMaybeT $ do
138
139
(expectedType, actualType, errInfo) <- hoistMaybe $ do
139
140
msg <- diagnostic ^. fdStructuredMessageL ^? _SomeStructuredMessage
140
141
tcRnMsg <- msg ^. msgEnvelopeErrorL ^? _TcRnMessage
141
- (solverReport, errInfo) <- findSolverReport tcRnMsg
142
- mismatch <- findMismatchMessage solverReport
143
- (expectedType', actualType') <- findTypeEqMismatch mismatch
144
- errInfo' <- errInfo
142
+ TcRnMessageDetailed errInfo tcRnMsg' <- tcRnMsg ^? _TcRnMessageDetailed
143
+ solverReport <- tcRnMsg' ^? _TcRnSolverReport . tcSolverReportMsgL
144
+ mismatch <- solverReport ^? _MismatchMessage
145
+ expectedType <- mismatch ^? _TypeEqMismatchExpected
146
+ actualType <- mismatch ^? _TypeEqMismatchActual
145
147
146
- pure (showType expectedType' , showType actualType' , errInfo' )
148
+ pure (showType expectedType, showType actualType, errInfo)
147
149
148
150
logWith recorder Debug (LogErrInfoCtxt errInfo)
149
151
@@ -163,35 +165,48 @@ diagnosticToChangeSig recorder decls diagnostic = runMaybeT $ do
163
165
showType :: Type -> Text
164
166
showType = T. pack . showSDocUnsafe . pprTidiedType
165
167
166
- -- TODO: Make this a prism?
167
- findSolverReport :: TcRnMessage -> Maybe ( TcSolverReportMsg , Maybe ErrInfo )
168
- findSolverReport ( TcRnMessageWithInfo _ ( TcRnMessageDetailed errInfo msg)) =
169
- case findSolverReport msg of
170
- Just (mismatch, _) -> Just (mismatch, Just errInfo)
171
- _ -> Nothing
168
+ _TcRnMessageDetailed :: Traversal' TcRnMessage TcRnMessageDetailed
169
+ _TcRnMessageDetailed focus ( TcRnMessageWithInfo errInfo detailed) =
170
+ ( \ detailed' -> TcRnMessageWithInfo errInfo detailed') <$> focus detailed
171
+ _TcRnMessageDetailed _ msg = pure msg
172
+
173
+ _TcRnSolverReport :: Traversal' TcRnMessage SolverReportWithCtxt
172
174
#if MIN_VERSION_ghc(9,10,0)
173
- findSolverReport (TcRnSolverReport ( SolverReportWithCtxt _ mismatch) _ ) =
174
- Just (mismatch, Nothing )
175
+ _TcRnSolverReport focus (TcRnSolverReport report reason ) =
176
+ ( \ report' -> TcRnSolverReport report' reason) <$> focus report
175
177
#else
176
- findSolverReport (TcRnSolverReport ( SolverReportWithCtxt _ mismatch) _ _ ) =
177
- Just (mismatch, Nothing )
178
+ _TcRnSolverReport focus (TcRnSolverReport report reason hints ) =
179
+ ( \ report' -> TcRnSolverReport report' reason hints) <$> focus report
178
180
#endif
179
- findSolverReport _ = Nothing
181
+ _TcRnSolverReport _ msg = pure msg
182
+
183
+ tcSolverReportMsgL :: Lens' SolverReportWithCtxt TcSolverReportMsg
184
+ tcSolverReportMsgL = lens reportContent (\ report content' -> report { reportContent = content' })
185
+
186
+ _MismatchMessage :: Traversal' TcSolverReportMsg MismatchMsg
187
+ _MismatchMessage focus (Mismatch msg t a c) = (\ msg' -> Mismatch msg' t a c) <$> focus msg
188
+ _MismatchMessage focus (CannotUnifyVariable msg a) = flip CannotUnifyVariable a <$> focus msg
189
+ _MismatchMessage _ report = pure report
180
190
181
- -- TODO: Make this a prism?
182
- findMismatchMessage :: TcSolverReportMsg -> Maybe MismatchMsg
183
- findMismatchMessage (Mismatch m _ _ _) = Just m
184
- findMismatchMessage (CannotUnifyVariable m _) = Just m
185
- findMismatchMessage _ = Nothing
191
+ _TypeEqMismatchExpected :: Traversal' MismatchMsg Type
192
+ #if MIN_VERSION_ghc(9,12,0)
193
+ _TypeEqMismatchExpected focus mismatch@ (TypeEqMismatch _ _ _ expected _ _ _) =
194
+ (\ expected' -> mismatch { teq_mismatch_expected = expected' }) <$> focus expected
195
+ #else
196
+ _TypeEqMismatchExpected focus mismatch@ (TypeEqMismatch _ _ _ expected _ _ _ _) =
197
+ (\ expected' -> mismatch { teq_mismatch_expected = expected' }) <$> focus expected
198
+ #endif
199
+ _TypeEqMismatchExpected _ mismatch = pure mismatch
186
200
187
- -- TODO: Make this a prism?
188
- findTypeEqMismatch :: MismatchMsg -> Maybe (Type , Type )
201
+ _TypeEqMismatchActual :: Traversal' MismatchMsg Type
189
202
#if MIN_VERSION_ghc(9,12,0)
190
- findTypeEqMismatch (TypeEqMismatch _ _ _ expected actual _ _) = Just (expected, actual)
203
+ _TypeEqMismatchActual focus mismatch@ (TypeEqMismatch _ _ _ _ actual _ _) =
204
+ (\ actual' -> mismatch { teq_mismatch_actual = actual' }) <$> focus actual
191
205
#else
192
- findTypeEqMismatch (TypeEqMismatch _ _ _ _ expected actual _ _) = Just (expected, actual)
206
+ _TypeEqMismatchActual focus mismatch@ (TypeEqMismatch _ _ _ _ actual _ _ _) =
207
+ (\ actual' -> mismatch { teq_mismatch_expected = actual' }) <$> focus actual
193
208
#endif
194
- findTypeEqMismatch _ = Nothing
209
+ _TypeEqMismatchActual _ mismatch = pure mismatch
195
210
196
211
-- | If a diagnostic has the proper message create a ChangeSignature from it
197
212
matchingDiagnostic :: ErrInfo -> Maybe DeclName
@@ -207,8 +222,7 @@ matchingDiagnostic ErrInfo{errInfoContext} =
207
222
-- | List of regexes that match various Error Messages
208
223
errorMessageRegexes :: [Text ]
209
224
errorMessageRegexes = [ -- be sure to add new Error Messages Regexes at the bottom to not fail any existing tests
210
- " In an equation for ‘(.+)’:" -- TODO: Check if this is useful only for tests
211
- , " In an equation for `(.+)':"
225
+ " In an equation for ‘(.+)’:"
212
226
]
213
227
214
228
-- | Given a String with the name of a declaration, GHC's "Expected Type", find the declaration that matches
0 commit comments