Skip to content

Commit 63eb537

Browse files
committed
CodeAction: fixed add default type to satisfy one constraint
1 parent 57dccc2 commit 63eb537

File tree

1 file changed

+30
-3
lines changed
  • plugins/hls-refactor-plugin/src/Development/IDE/Plugin

1 file changed

+30
-3
lines changed

plugins/hls-refactor-plugin/src/Development/IDE/Plugin/CodeAction.hs

+30-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Development.IDE.Plugin.CodeAction
1414
matchRegExMultipleImports
1515
) where
1616

17+
import Debug.Trace
1718
import Control.Applicative ((<|>))
1819
import Control.Applicative.Combinators.NonEmpty (sepBy1)
1920
import Control.Arrow (second,
@@ -791,12 +792,12 @@ suggestAddTypeAnnotationToSatisfyConstraints sourceOpt Diagnostic{_range=_range,
791792
-- In an equation for ‘f’:
792793
-- f = seq "test" seq "test" (traceShow "test")
793794
--
794-
| Just [ty, lit] <- matchRegexUnifySpaces _message (pat False False True False)
795+
| Just [ty, lit] <- matchRegexUnifySpaces (trace ("message:" <> show _message) _message) (pat False False True False)
795796
<|> matchRegexUnifySpaces _message (pat False False False True)
796797
<|> matchRegexUnifySpaces _message (pat False False False False)
797798

798-
= codeEdit _range ty lit (makeAnnotatedLit ty lit)
799-
| Just source <- sourceOpt
799+
= codeEdit _range (trace ("ty " <> show ty <> "lit " <> show lit) ty) lit (makeAnnotatedLit ty lit)
800+
| Just source <- trace ("sourceOpt: " <> show sourceOpt) sourceOpt
800801
, Just [ty, lit, srcspan] <- matchRegexUnifySpaces _message (pat True True False False)
801802
, range <- case [ x | (x,"") <- readSrcSpan (T.unpack srcspan)] of
802803
[s] -> let x = realSrcSpanToRange s
@@ -808,6 +809,14 @@ suggestAddTypeAnnotationToSatisfyConstraints sourceOpt Diagnostic{_range=_range,
808809
| otherwise = []
809810
where
810811
makeAnnotatedLit ty lit = "(" <> lit <> " :: " <> ty <> ")"
812+
#if MIN_VERSION_ghc(9,8,0)
813+
pat multiple _ _ _ = T.concat [ ".*Defaulting the type variable "
814+
, ".*to type ‘([^ ]+)’ "
815+
, "in the following constraint"
816+
, if multiple then "s" else " "
817+
, ".*arising from the literal ‘(.+)’"
818+
]
819+
#else
811820
#if MIN_VERSION_ghc(9,4,0)
812821
pat multiple at inArg inExpr = T.concat [ ".*Defaulting the type variable "
813822
, ".*to type ‘([^ ]+)’ "
@@ -829,6 +838,7 @@ suggestAddTypeAnnotationToSatisfyConstraints sourceOpt Diagnostic{_range=_range,
829838
, if inExpr then ".+In the expression" else ""
830839
, ".+In the expression"
831840
]
841+
#endif
832842
#endif
833843
codeEdit range ty lit replacement =
834844
let title = "Add type annotation ‘" <> ty <> "’ to ‘" <> lit <> ""
@@ -1992,3 +2002,20 @@ matchRegExMultipleImports message = do
19922002
_ -> Nothing
19932003
imps <- regExImports imports
19942004
return (binding, imps)
2005+
2006+
---- Debugging
2007+
-- pat multiple at inArg inExpr = T.concat [ ".*Defaulting the type variable "
2008+
-- , ".*to type ‘([^ ]+)’ "
2009+
-- , "in the following constraint"
2010+
-- , if multiple then "s" else " "
2011+
-- , ".*arising from the literal ‘(.+)’"
2012+
-- , if inArg then ".+In the.+argument" else ""
2013+
-- , if at then ".+at ([^ ]*)" else ""
2014+
-- , if inExpr then ".+In the expression" else ""
2015+
-- , ".+In the expression"
2016+
-- ]
2017+
2018+
2019+
-- Just [ty, lit] <- matchRegexUnifySpaces _message (pat False False True False)
2020+
-- <|> matchRegexUnifySpaces _message (pat False False False True)
2021+
-- <|> matchRegexUnifySpaces _message (pat False False False False)

0 commit comments

Comments
 (0)