@@ -826,43 +826,49 @@ suggestAddTypeAnnotationToSatisfyConstraints sourceOpt Diagnostic{_range=_range,
826
826
-- In the expression: seq "test" seq "test" (traceShow "test")
827
827
-- In an equation for ‘f’:
828
828
-- f = seq "test" seq "test" (traceShow "test")
829
+ --
829
830
| Just [ty, lit] <- matchRegexUnifySpaces _message (pat False False True False )
830
- <|> matchRegexUnifySpaces _message (pat False False False True )
831
- <|> matchRegexUnifySpaces _message (pat False False False False )
832
- = codeEdit ty lit (makeAnnotatedLit ty lit)
831
+ <|> matchRegexUnifySpaces _message (pat False False False True )
832
+ <|> matchRegexUnifySpaces _message (pat False False False False )
833
+
834
+ = codeEdit _range ty lit (makeAnnotatedLit ty lit)
833
835
| Just source <- sourceOpt
834
- , Just [ty, lit] <- matchRegexUnifySpaces _message (pat True True False False )
835
- = let lit' = makeAnnotatedLit ty lit;
836
- tir = textInRange _range source
837
- in codeEdit ty lit (T. replace lit lit' tir)
836
+ , Just [ty, lit, srcspan] <- matchRegexUnifySpaces _message (pat True True False False )
837
+ , range <- case [ x | (x," " ) <- readSrcSpan (T. unpack srcspan)] of
838
+ [s] -> let x = realSrcSpanToRange s
839
+ in x{_end = (_end x){_character = succ (_character (_end x))}}
840
+ _ -> error " bug in srcspan parser"
841
+ = let lit' = makeAnnotatedLit ty lit;
842
+ tir = textInRange range source
843
+ in codeEdit range ty lit (T. replace lit lit' tir)
838
844
| otherwise = []
839
845
where
840
846
makeAnnotatedLit ty lit = " (" <> lit <> " :: " <> ty <> " )"
841
847
#if MIN_VERSION_ghc(9,4,0)
842
848
pat multiple at inArg inExpr = T. concat [ " .*Defaulting the type variable "
843
849
, " .*to type ‘([^ ]+)’ "
844
850
, " in the following constraint"
845
- , if multiple then " s" else " "
851
+ , if multiple then " s" else " "
846
852
, " .*arising from the literal ‘(.+)’"
847
853
, if inArg then " .+In the.+argument" else " "
848
- , if at then " .+at" else " "
854
+ , if at then " .+at ([^ ]*) " else " "
849
855
, if inExpr then " .+In the expression" else " "
850
856
, " .+In the expression"
851
857
]
852
858
#else
853
859
pat multiple at inArg inExpr = T. concat [ " .*Defaulting the following constraint"
854
- , if multiple then " s" else " "
860
+ , if multiple then " s" else " "
855
861
, " to type ‘([^ ]+)’ "
856
862
, " .*arising from the literal ‘(.+)’"
857
863
, if inArg then " .+In the.+argument" else " "
858
- , if at then " .+at" else " "
864
+ , if at then " .+at ([^ ]*) " else " "
859
865
, if inExpr then " .+In the expression" else " "
860
866
, " .+In the expression"
861
867
]
862
868
#endif
863
- codeEdit ty lit replacement =
869
+ codeEdit range ty lit replacement =
864
870
let title = " Add type annotation ‘" <> ty <> " ’ to ‘" <> lit <> " ’"
865
- edits = [TextEdit _range replacement]
871
+ edits = [TextEdit range replacement]
866
872
in [( title, edits )]
867
873
868
874
-- | GHC strips out backticks in case of infix functions as well as single quote
@@ -967,7 +973,7 @@ suggestExtendImport :: ExportsMap -> ParsedSource -> Diagnostic -> [(T.Text, Cod
967
973
suggestExtendImport exportsMap (L _ HsModule {hsmodImports}) Diagnostic {_range= _range,.. }
968
974
| Just [binding, mod , srcspan] <-
969
975
matchRegexUnifySpaces _message
970
- " Perhaps you want to add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\ ((.*)\\ ).$ "
976
+ " Perhaps you want to add ‘([^’]*)’ to the import list in the import of ‘([^’]*)’ *\\ ((.*)\\ )."
971
977
= suggestions hsmodImports binding mod srcspan
972
978
| Just (binding, mod_srcspan) <-
973
979
matchRegExMultipleImports _message
@@ -1217,8 +1223,8 @@ suggestConstraint df (makeDeltaAst -> parsedModule) diag@Diagnostic {..}
1217
1223
where
1218
1224
findMissingConstraint :: T. Text -> Maybe T. Text
1219
1225
findMissingConstraint t =
1220
- let regex = " (No instance for|Could not deduce) \\ ((.+) \\ ) arising from" -- a use of / a do statement
1221
- regexImplicitParams = " Could not deduce: (\\ ?.+) arising from a use of"
1226
+ let regex = " (No instance for|Could not deduce) \\ (?‘?([^’)]+)’? \\ )? arising from" -- a use of / a do statement
1227
+ regexImplicitParams = " Could not deduce:? ‘? (\\ ?[^’]+)’? arising from a use of"
1222
1228
match = matchRegexUnifySpaces t regex
1223
1229
matchImplicitParams = matchRegexUnifySpaces t regexImplicitParams
1224
1230
in match <|> matchImplicitParams <&> last
0 commit comments