Skip to content

Commit 0655fcc

Browse files
committed
Fix most add argument tests except for one
1 parent d955f9a commit 0655fcc

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

plugins/hls-refactor-plugin/src/Development/IDE/GHC/ExactPrint.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ modifySmallestDeclWithM validSpan f a = do
462462
modifyMatchingDecl (ldecl@(L src _) : rest) =
463463
TransformT (lift $ validSpan $ locA src) >>= \case
464464
True -> do
465-
(decs', r) <- f (makeDeltaAst ldecl)
465+
(decs', r) <- f ldecl
466466
pure (DL.fromList decs' <> DL.fromList rest, Just r)
467467
False -> first (DL.singleton ldecl <>) <$> modifyMatchingDecl rest
468468
modifyDeclsT' (fmap (first DL.toList) . modifyMatchingDecl) a
@@ -607,7 +607,7 @@ modifyMgMatchesT' ::
607607
modifyMgMatchesT' (MG xMg (L locMatches matches)) f def combineResults = do
608608
(unzip -> (matches', rs)) <- mapM f matches
609609
r' <- TransformT $ lift $ foldM combineResults def rs
610-
pure $ (MG xMg (L locMatches matches'), r')
610+
pure (MG xMg (L locMatches matches'), r')
611611
#else
612612
modifyMgMatchesT' (MG xMg (L locMatches matches) originMg) f def combineResults = do
613613
(unzip -> (matches', rs)) <- mapM f matches

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ import GHC.Types.SrcLoc (generatedSrcSpan)
4545
#endif
4646

4747
#if MIN_VERSION_ghc(9,9,0)
48-
import GHC (EpUniToken (..),
48+
import GHC (DeltaPos (..),
49+
EpUniToken (..),
4950
IsUnicodeSyntax (NormalSyntax))
50-
import Language.Haskell.GHC.ExactPrint (d1)
51+
import Language.Haskell.GHC.ExactPrint (d1, setEntryDP)
5152
#endif
5253

54+
5355
-- When GHC tells us that a variable is not bound, it will tell us either:
5456
-- - there is an unbound variable with a given type
5557
-- - there is an unbound variable (GHC provides no type suggestion)
@@ -74,15 +76,20 @@ plugin parsedModule Diagnostic {_message, _range}
7476
-- returning how many patterns there were in this match prior to the transformation:
7577
-- addArgToMatch "foo" `bar arg1 arg2 = ...`
7678
-- => (`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)
7880
addArgToMatch name (L locMatch (Match xMatch ctxMatch pats rhs)) =
7981
let unqualName = mkRdrUnqual $ mkVarOcc $ T.unpack name
8082
#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 }
8288
#else
8389
newPat = L (noAnnSrcSpanDP1 generatedSrcSpan) $ VarPat NoExtField (noLocA unqualName)
90+
indentRhs = id
8491
#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)
8693

8794
-- Attempt to insert a binding pattern into each match for the given LHsDecl; succeeds only if the function is a FunBind.
8895
-- Also return:

0 commit comments

Comments
 (0)