@@ -45,11 +45,13 @@ import GHC.Types.SrcLoc (generatedSrcSpan)
45
45
#endif
46
46
47
47
#if MIN_VERSION_ghc(9,9,0)
48
- import GHC (EpUniToken (.. ),
48
+ import GHC (DeltaPos (.. ),
49
+ EpUniToken (.. ),
49
50
IsUnicodeSyntax (NormalSyntax ))
50
- import Language.Haskell.GHC.ExactPrint (d1 )
51
+ import Language.Haskell.GHC.ExactPrint (d1 , setEntryDP )
51
52
#endif
52
53
54
+
53
55
-- When GHC tells us that a variable is not bound, it will tell us either:
54
56
-- - there is an unbound variable with a given type
55
57
-- - there is an unbound variable (GHC provides no type suggestion)
@@ -74,15 +76,20 @@ plugin parsedModule Diagnostic {_message, _range}
74
76
-- returning how many patterns there were in this match prior to the transformation:
75
77
-- addArgToMatch "foo" `bar arg1 arg2 = ...`
76
78
-- => (`bar arg1 arg2 foo = ...`, 2)
77
- addArgToMatch :: T. Text -> GenLocated l (Match GhcPs body ) -> (GenLocated l (Match GhcPs body ), Int )
79
+ addArgToMatch :: T. Text -> GenLocated l (Match GhcPs ( LocatedA ( HsExpr GhcPs ))) -> (GenLocated l (Match GhcPs ( LocatedA ( HsExpr GhcPs )) ), Int )
78
80
addArgToMatch name (L locMatch (Match xMatch ctxMatch pats rhs)) =
79
81
let unqualName = mkRdrUnqual $ mkVarOcc $ T. unpack name
80
82
#if MIN_VERSION_ghc(9,9,0)
81
- newPat = L noAnnSrcSpanDP1 $ VarPat NoExtField (noLocA unqualName)
83
+ newPat = L noAnnSrcSpanDP1 $ VarPat NoExtField $ L noAnn unqualName
84
+ -- The intention is to move `= ...` (right-hand side with equals) to the right so there's 1 space between
85
+ -- the newly added pattern and the rest
86
+ indentRhs :: GRHSs GhcPs (LocatedA (HsExpr GhcPs )) -> GRHSs GhcPs (LocatedA (HsExpr GhcPs ))
87
+ indentRhs rhs@ GRHSs {grhssGRHSs} = rhs {grhssGRHSs = fmap (`setEntryDP` (SameLine 1 )) grhssGRHSs }
82
88
#else
83
89
newPat = L (noAnnSrcSpanDP1 generatedSrcSpan) $ VarPat NoExtField (noLocA unqualName)
90
+ indentRhs = id
84
91
#endif
85
- in (L locMatch (Match xMatch ctxMatch (pats <> [newPat]) rhs), Prelude. length pats)
92
+ in (L locMatch (Match xMatch ctxMatch (pats <> [newPat]) (indentRhs rhs) ), Prelude. length pats)
86
93
87
94
-- Attempt to insert a binding pattern into each match for the given LHsDecl; succeeds only if the function is a FunBind.
88
95
-- Also return:
0 commit comments