@@ -826,43 +826,49 @@ suggestAddTypeAnnotationToSatisfyConstraints sourceOpt Diagnostic{_range=_range,
826826-- In the expression: seq "test" seq "test" (traceShow "test")
827827-- In an equation for ‘f’:
828828-- f = seq "test" seq "test" (traceShow "test")
829+ --
829830 | 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)
833835 | 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)
838844 | otherwise = []
839845 where
840846 makeAnnotatedLit ty lit = " (" <> lit <> " :: " <> ty <> " )"
841847#if MIN_VERSION_ghc(9,4,0)
842848 pat multiple at inArg inExpr = T. concat [ " .*Defaulting the type variable "
843849 , " .*to type ‘([^ ]+)’ "
844850 , " in the following constraint"
845- , if multiple then " s" else " "
851+ , if multiple then " s" else " "
846852 , " .*arising from the literal ‘(.+)’"
847853 , if inArg then " .+In the.+argument" else " "
848- , if at then " .+at" else " "
854+ , if at then " .+at ([^ ]*) " else " "
849855 , if inExpr then " .+In the expression" else " "
850856 , " .+In the expression"
851857 ]
852858#else
853859 pat multiple at inArg inExpr = T. concat [ " .*Defaulting the following constraint"
854- , if multiple then " s" else " "
860+ , if multiple then " s" else " "
855861 , " to type ‘([^ ]+)’ "
856862 , " .*arising from the literal ‘(.+)’"
857863 , if inArg then " .+In the.+argument" else " "
858- , if at then " .+at" else " "
864+ , if at then " .+at ([^ ]*) " else " "
859865 , if inExpr then " .+In the expression" else " "
860866 , " .+In the expression"
861867 ]
862868#endif
863- codeEdit ty lit replacement =
869+ codeEdit range ty lit replacement =
864870 let title = " Add type annotation ‘" <> ty <> " ’ to ‘" <> lit <> " ’"
865- edits = [TextEdit _range replacement]
871+ edits = [TextEdit range replacement]
866872 in [( title, edits )]
867873
868874-- | 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
967973suggestExtendImport exportsMap (L _ HsModule {hsmodImports}) Diagnostic {_range= _range,.. }
968974 | Just [binding, mod , srcspan] <-
969975 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 ‘([^’]*)’ *\\ ((.*)\\ )."
971977 = suggestions hsmodImports binding mod srcspan
972978 | Just (binding, mod_srcspan) <-
973979 matchRegExMultipleImports _message
@@ -1217,8 +1223,8 @@ suggestConstraint df (makeDeltaAst -> parsedModule) diag@Diagnostic {..}
12171223 where
12181224 findMissingConstraint :: T. Text -> Maybe T. Text
12191225 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"
12221228 match = matchRegexUnifySpaces t regex
12231229 matchImplicitParams = matchRegexUnifySpaces t regexImplicitParams
12241230 in match <|> matchImplicitParams <&> last
0 commit comments