{-# LANGUAGE CPP #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RecordWildCards #-}
module Ide.Plugin.Class.ExactPrint where
import Control.Monad.Trans.Maybe
import Data.Either.Extra (eitherToMaybe)
import Data.Functor.Identity (Identity)
import qualified Data.Text as T
import Development.IDE.GHC.Compat
import GHC.Parser.Annotation
import Ide.Plugin.Class.Types
import Ide.Plugin.Class.Utils
import Language.Haskell.GHC.ExactPrint
import Language.Haskell.GHC.ExactPrint.Parsers
import Language.LSP.Protocol.Types (Range)
#if MIN_VERSION_ghc(9,9,0)
import Control.Lens (_head, over)
#endif
makeEditText :: Monad m => ParsedModule -> DynFlags -> AddMinimalMethodsParams -> MaybeT m (T.Text, T.Text)
makeEditText :: forall (m :: * -> *).
Monad m =>
ParsedModule
-> DynFlags -> AddMinimalMethodsParams -> MaybeT m (Text, Text)
makeEditText ParsedModule
pm DynFlags
df AddMinimalMethodsParams{Bool
[(Text, Text)]
Range
VersionedTextDocumentIdentifier
verTxtDocId :: VersionedTextDocumentIdentifier
range :: Range
methodGroup :: [(Text, Text)]
withSig :: Bool
verTxtDocId :: AddMinimalMethodsParams -> VersionedTextDocumentIdentifier
range :: AddMinimalMethodsParams -> Range
methodGroup :: AddMinimalMethodsParams -> [(Text, Text)]
withSig :: AddMinimalMethodsParams -> Bool
..} = do
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
mDecls <- m (Maybe
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))])
-> MaybeT
m
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (m (Maybe
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))])
-> MaybeT
m
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))])
-> (Maybe
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
-> m (Maybe
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]))
-> Maybe
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
-> MaybeT
m
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
-> m (Maybe
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))])
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
-> MaybeT
m
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))])
-> Maybe
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
-> MaybeT
m
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
forall a b. (a -> b) -> a -> b
$ ((Text, Text)
-> Maybe
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)))
-> [(Text, Text)]
-> Maybe
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> [a] -> f [b]
traverse (DynFlags -> (Text, Text) -> Maybe (LHsDecl GhcPs, LHsDecl GhcPs)
makeMethodDecl DynFlags
df) [(Text, Text)]
methodGroup
let ps :: ParsedSource
ps =
#if !MIN_VERSION_ghc(9,9,0)
ParsedSource -> ParsedSource
forall ast. ExactPrint ast => ast -> ast
makeDeltaAst (ParsedSource -> ParsedSource) -> ParsedSource -> ParsedSource
forall a b. (a -> b) -> a -> b
$
#endif
ParsedModule -> ParsedSource
pm_parsed_source ParsedModule
pm
old :: Text
old = String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ ParsedSource -> String
forall ast. ExactPrint ast => ast -> String
exactPrint ParsedSource
ps
(ParsedSource
ps', Int
_, [String]
_) = Transform ParsedSource -> (ParsedSource, Int, [String])
forall a. Transform a -> (a, Int, [String])
runTransform (ParsedSource
-> [(LHsDecl GhcPs, LHsDecl GhcPs)]
-> Range
-> Bool
-> Transform ParsedSource
addMethodDecls ParsedSource
ps [(LHsDecl GhcPs, LHsDecl GhcPs)]
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
mDecls Range
range Bool
withSig)
new :: Text
new = String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ ParsedSource -> String
forall ast. ExactPrint ast => ast -> String
exactPrint ParsedSource
ps'
(Text, Text) -> MaybeT m (Text, Text)
forall a. a -> MaybeT m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text
old, Text
new)
makeMethodDecl :: DynFlags -> (T.Text, T.Text) -> Maybe (LHsDecl GhcPs, LHsDecl GhcPs)
makeMethodDecl :: DynFlags -> (Text, Text) -> Maybe (LHsDecl GhcPs, LHsDecl GhcPs)
makeMethodDecl DynFlags
df (Text
mName, Text
sig) = do
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
name <- Either
ErrorMessages
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> Maybe
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
forall a b. Either a b -> Maybe b
eitherToMaybe (Either
ErrorMessages
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> Maybe
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)))
-> Either
ErrorMessages
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> Maybe
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
forall a b. (a -> b) -> a -> b
$ Parser (LHsDecl GhcPs)
parseDecl DynFlags
df (Text -> String
T.unpack Text
mName) (String
-> Either
ErrorMessages
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)))
-> (Text -> String)
-> Text
-> Either
ErrorMessages
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> String
T.unpack (Text
-> Either
ErrorMessages
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)))
-> Text
-> Either
ErrorMessages
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
forall a b. (a -> b) -> a -> b
$ Text -> Text
toMethodName Text
mName Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" = _"
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
sig' <- Either
ErrorMessages
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> Maybe
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
forall a b. Either a b -> Maybe b
eitherToMaybe (Either
ErrorMessages
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> Maybe
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)))
-> Either
ErrorMessages
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> Maybe
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
forall a b. (a -> b) -> a -> b
$ Parser (LHsDecl GhcPs)
parseDecl DynFlags
df (Text -> String
T.unpack Text
sig) (String -> ParseResult (LHsDecl GhcPs))
-> String -> ParseResult (LHsDecl GhcPs)
forall a b. (a -> b) -> a -> b
$ Text -> String
T.unpack Text
sig
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> Maybe
(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
forall a. a -> Maybe a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
name, GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
sig')
#if MIN_VERSION_ghc(9,5,0)
addMethodDecls :: ParsedSource -> [(LHsDecl GhcPs, LHsDecl GhcPs)] -> Range -> Bool -> TransformT Identity (Located (HsModule GhcPs))
#else
addMethodDecls :: ParsedSource -> [(LHsDecl GhcPs, LHsDecl GhcPs)] -> Range -> Bool -> TransformT Identity (Located HsModule)
#endif
addMethodDecls :: ParsedSource
-> [(LHsDecl GhcPs, LHsDecl GhcPs)]
-> Range
-> Bool
-> Transform ParsedSource
addMethodDecls ParsedSource
ps [(LHsDecl GhcPs, LHsDecl GhcPs)]
mDecls Range
range Bool
withSig
| Bool
withSig = [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> Transform ParsedSource
go (((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)])
-> [(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (\(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
decl, GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
sig) -> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
sig, GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
decl]) [(LHsDecl GhcPs, LHsDecl GhcPs)]
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
mDecls)
| Bool
otherwise = [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> Transform ParsedSource
go (((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> [(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
forall a b. (a, b) -> a
fst [(LHsDecl GhcPs, LHsDecl GhcPs)]
[(GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs),
GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))]
mDecls)
where
go :: [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> Transform ParsedSource
go [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
inserting = do
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
allDecls <- ParsedSource -> TransformT Identity [LHsDecl GhcPs]
forall t (m :: * -> *).
(HasDecls t, Monad m) =>
t -> TransformT m [LHsDecl GhcPs]
forall (m :: * -> *).
Monad m =>
ParsedSource -> TransformT m [LHsDecl GhcPs]
hsDecls ParsedSource
ps
case (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> Bool)
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)],
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Range -> SrcSpan -> Bool
inRange Range
range (SrcSpan -> Bool)
-> (GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> SrcSpan)
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc) [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
allDecls of
([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
before, L SrcSpanAnn' (EpAnn AnnListItem)
l HsDecl GhcPs
inst : [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
after) ->
let
instSpan :: RealSrcSpan
instSpan = SrcSpan -> RealSrcSpan
realSrcSpan (SrcSpan -> RealSrcSpan) -> SrcSpan -> RealSrcSpan
forall a b. (a -> b) -> a -> b
$ SrcSpanAnn' (EpAnn AnnListItem) -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc SrcSpanAnn' (EpAnn AnnListItem)
l
instCol :: Int
instCol = RealSrcSpan -> Int
srcSpanStartCol RealSrcSpan
instSpan
#if MIN_VERSION_ghc(9,9,0)
instRow = srcSpanEndLine instSpan
methodEpAnn = noAnnSrcSpanDP $ deltaPos 1 (instCol + defaultIndent)
newLine (L _ e) = L methodEpAnn e
resetFollowing =
over _head (\followingDecl ->
let followingDeclRow = srcSpanStartLine $ realSrcSpan $ getLoc followingDecl
delta = DifferentLine (followingDeclRow - instRow) instCol
in setEntryDP followingDecl delta)
#else
newLine :: GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
newLine (L SrcSpanAnn' (EpAnn AnnListItem)
l HsDecl GhcPs
e) =
let dp :: DeltaPos
dp = Int -> Int -> DeltaPos
deltaPos Int
1 (Int
instCol Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
defaultIndent Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1)
in SrcSpanAnn' (EpAnn AnnListItem)
-> HsDecl GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
forall l e. l -> e -> GenLocated l e
L (SrcSpan -> DeltaPos -> SrcSpanAnn' (EpAnn AnnListItem)
forall ann.
Monoid ann =>
SrcSpan -> DeltaPos -> SrcSpanAnn' (EpAnn ann)
noAnnSrcSpanDP (SrcSpanAnn' (EpAnn AnnListItem) -> SrcSpan
forall a. HasSrcSpan a => a -> SrcSpan
getLoc SrcSpanAnn' (EpAnn AnnListItem)
l) DeltaPos
dp SrcSpanAnn' (EpAnn AnnListItem)
-> SrcSpanAnn' (EpAnn AnnListItem)
-> SrcSpanAnn' (EpAnn AnnListItem)
forall a. Semigroup a => a -> a -> a
<> SrcSpanAnn' (EpAnn AnnListItem)
l) HsDecl GhcPs
e
resetFollowing :: a -> a
resetFollowing = a -> a
forall a. a -> a
id
#endif
in ParsedSource -> [LHsDecl GhcPs] -> Transform ParsedSource
forall t (m :: * -> *).
(HasDecls t, Monad m) =>
t -> [LHsDecl GhcPs] -> TransformT m t
forall (m :: * -> *).
Monad m =>
ParsedSource -> [LHsDecl GhcPs] -> TransformT m ParsedSource
replaceDecls ParsedSource
ps ([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
before [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a. [a] -> [a] -> [a]
++ SrcSpanAnn' (EpAnn AnnListItem)
-> HsDecl GhcPs
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
forall l e. l -> e -> GenLocated l e
L SrcSpanAnn' (EpAnn AnnListItem)
l (HsDecl GhcPs -> HsDecl GhcPs
addWhere HsDecl GhcPs
inst)GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a. a -> [a] -> [a]
:((GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs))
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
-> GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)
newLine [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
inserting [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a. [a] -> [a] -> [a]
++ [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
-> [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
forall a. a -> a
resetFollowing [GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
after))
([GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
before, []) ->
ParsedSource -> [LHsDecl GhcPs] -> Transform ParsedSource
forall t (m :: * -> *).
(HasDecls t, Monad m) =>
t -> [LHsDecl GhcPs] -> TransformT m t
forall (m :: * -> *).
Monad m =>
ParsedSource -> [LHsDecl GhcPs] -> TransformT m ParsedSource
replaceDecls ParsedSource
ps [LHsDecl GhcPs]
[GenLocated (SrcSpanAnn' (EpAnn AnnListItem)) (HsDecl GhcPs)]
before
addWhere :: HsDecl GhcPs -> HsDecl GhcPs
addWhere :: HsDecl GhcPs -> HsDecl GhcPs
addWhere instd :: HsDecl GhcPs
instd@(InstD XInstD GhcPs
xInstD (ClsInstD XClsInstD GhcPs
ext decl :: ClsInstDecl GhcPs
decl@ClsInstDecl{[LSig GhcPs]
[LDataFamInstDecl GhcPs]
[LTyFamInstDecl GhcPs]
Maybe (XRec GhcPs OverlapMode)
XCClsInstDecl GhcPs
LHsSigType GhcPs
LHsBinds GhcPs
cid_ext :: XCClsInstDecl GhcPs
cid_poly_ty :: LHsSigType GhcPs
cid_binds :: LHsBinds GhcPs
cid_sigs :: [LSig GhcPs]
cid_tyfam_insts :: [LTyFamInstDecl GhcPs]
cid_datafam_insts :: [LDataFamInstDecl GhcPs]
cid_overlap_mode :: Maybe (XRec GhcPs OverlapMode)
cid_ext :: forall pass. ClsInstDecl pass -> XCClsInstDecl pass
cid_poly_ty :: forall pass. ClsInstDecl pass -> LHsSigType pass
cid_binds :: forall pass. ClsInstDecl pass -> LHsBinds pass
cid_sigs :: forall pass. ClsInstDecl pass -> [LSig pass]
cid_tyfam_insts :: forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_datafam_insts :: forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_overlap_mode :: forall pass. ClsInstDecl pass -> Maybe (XRec pass OverlapMode)
..})) =
case XCClsInstDecl GhcPs
cid_ext of
#if MIN_VERSION_ghc(9,9,0)
(warnings, anns, key)
| any (\(AddEpAnn kw _ )-> kw == AnnWhere) anns -> instd
| otherwise ->
InstD xInstD (ClsInstD ext decl {
cid_ext = ( warnings
, AddEpAnn AnnWhere d1 : anns
, key
)
})
#else
(EpAnn Anchor
entry [AddEpAnn]
anns EpAnnComments
comments, AnnSortKey
key) ->
XInstD GhcPs -> InstDecl GhcPs -> HsDecl GhcPs
forall p. XInstD p -> InstDecl p -> HsDecl p
InstD XInstD GhcPs
xInstD (XClsInstD GhcPs -> ClsInstDecl GhcPs -> InstDecl GhcPs
forall pass. XClsInstD pass -> ClsInstDecl pass -> InstDecl pass
ClsInstD XClsInstD GhcPs
ext ClsInstDecl GhcPs
decl {
cid_ext = (EpAnn
entry
(AddEpAnn AnnWhere d1 : anns)
comments
, key
)
})
XCClsInstDecl GhcPs
_ -> HsDecl GhcPs
instd
#endif
addWhere HsDecl GhcPs
decl = HsDecl GhcPs
decl