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