| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
Development.IDE.GHC.ExactPrint
Contents
Description
This module hosts various abstractions and utility functions to work with ghc-exactprint.
Synopsis
- newtype Graft m a = Graft {
- runGraft :: DynFlags -> a -> TransformT m a
- graftDecls :: forall a. HasDecls a => SrcSpan -> [LHsDecl GhcPs] -> Graft (Either String) a
- graftDeclsWithM :: forall a m. (HasDecls a, MonadFail m) => SrcSpan -> (LHsDecl GhcPs -> TransformT m (Maybe [LHsDecl GhcPs])) -> Graft m a
- annotate :: ASTElement l ast => DynFlags -> Bool -> LocatedAn l ast -> TransformT (Either String) (LocatedAn l ast)
- annotateDecl :: DynFlags -> LHsDecl GhcPs -> TransformT (Either String) (LHsDecl GhcPs)
- hoistGraft :: (forall x. m x -> n x) -> Graft m a -> Graft n a
- graftWithM :: forall ast m a l. (MonadFail m, Data a, ASTElement l ast) => SrcSpan -> (LocatedAn l ast -> TransformT m (Maybe (LocatedAn l ast))) -> Graft m a
- graftExprWithM :: forall m a. (MonadFail m, Data a) => SrcSpan -> (LHsExpr GhcPs -> TransformT m (Maybe (LHsExpr GhcPs))) -> Graft m a
- genericGraftWithSmallestM :: forall m a ast. (Monad m, Data a, Typeable ast) => Proxy (Located ast) -> SrcSpan -> (DynFlags -> ast -> GenericM (TransformT m)) -> Graft m a
- genericGraftWithLargestM :: forall m a ast. (Monad m, Data a, Typeable ast) => Proxy (Located ast) -> SrcSpan -> (DynFlags -> ast -> GenericM (TransformT m)) -> Graft m a
- graftSmallestDeclsWithM :: forall a. HasDecls a => SrcSpan -> (LHsDecl GhcPs -> TransformT (Either String) (Maybe [LHsDecl GhcPs])) -> Graft (Either String) a
- transform :: DynFlags -> ClientCapabilities -> VersionedTextDocumentIdentifier -> Graft (Either String) ParsedSource -> Annotated ParsedSource -> Either String WorkspaceEdit
- transformM :: Monad m => DynFlags -> ClientCapabilities -> VersionedTextDocumentIdentifier -> Graft (ExceptStringT m) ParsedSource -> Annotated ParsedSource -> m (Either String WorkspaceEdit)
- class Typeable a => ExactPrint a where
- getAnnotationEntry :: a -> Entry
- setAnnotationAnchor :: a -> Anchor -> EpAnnComments -> a
- exact :: forall (m :: Type -> Type) w. (Monad m, Monoid w) => a -> EP w m a
- modifySmallestDeclWithM :: forall a m r. (HasDecls a, Monad m) => (SrcSpan -> m Bool) -> (LHsDecl GhcPs -> TransformT m ([LHsDecl GhcPs], r)) -> a -> TransformT m (a, Maybe r)
- modifyMgMatchesT :: Monad m => MatchGroup GhcPs (LHsExpr GhcPs) -> (LMatch GhcPs (LHsExpr GhcPs) -> TransformT m (LMatch GhcPs (LHsExpr GhcPs))) -> TransformT m (MatchGroup GhcPs (LHsExpr GhcPs))
- modifyMgMatchesT' :: Monad m => MatchGroup GhcPs (LHsExpr GhcPs) -> (LMatch GhcPs (LHsExpr GhcPs) -> TransformT m (LMatch GhcPs (LHsExpr GhcPs), r)) -> r -> (r -> r -> m r) -> TransformT m (MatchGroup GhcPs (LHsExpr GhcPs), r)
- modifySigWithM :: forall a m. (HasDecls a, Monad m) => IdP GhcPs -> (LHsSigType GhcPs -> LHsSigType GhcPs) -> a -> TransformT m a
- genAnchor1 :: Anchor
- setPrecedingLines :: Default t => LocatedAn t a -> Int -> Int -> LocatedAn t a
- addParens :: Bool -> NameAnn -> NameAnn
- addParensToCtxt :: Maybe EpaLocation -> AnnContext -> AnnContext
- modifyAnns :: LocatedAn a ast -> (a -> a) -> LocatedAn a ast
- removeComma :: SrcSpanAnnA -> SrcSpanAnnA
- eqSrcSpan :: SrcSpan -> SrcSpan -> Bool
- eqSrcSpanA :: SrcAnn a -> SrcAnn b -> Bool
- epl :: Int -> EpaLocation
- epAnn :: SrcSpan -> ann -> EpAnn ann
- removeTrailingComma :: GenLocated SrcSpanAnnA ast -> GenLocated SrcSpanAnnA ast
- annotateParsedSource :: ParsedModule -> Annotated ParsedSource
- getAnnotatedParsedSourceRule :: Recorder (WithPriority Log) -> Rules ()
- data GetAnnotatedParsedSource = GetAnnotatedParsedSource
- class (Data ast, Typeable l, Outputable l, Outputable ast, Default l) => ASTElement l ast | ast -> l where
- newtype ExceptStringT m a = ExceptStringT {
- runExceptString :: ExceptT String m a
- data TransformT (m :: Type -> Type) a
- data Log = LogShake Log
Documentation
A transformation for grafting source trees together. Use the semigroup
instance to combine Grafts, and run them via transform.
Constructors
| Graft | |
Fields
| |
graftDecls :: forall a. HasDecls a => SrcSpan -> [LHsDecl GhcPs] -> Graft (Either String) a Source #
graftDeclsWithM :: forall a m. (HasDecls a, MonadFail m) => SrcSpan -> (LHsDecl GhcPs -> TransformT m (Maybe [LHsDecl GhcPs])) -> Graft m a Source #
annotate :: ASTElement l ast => DynFlags -> Bool -> LocatedAn l ast -> TransformT (Either String) (LocatedAn l ast) Source #
Given an LHSExpr, compute its exactprint annotations.
Note that this function will throw away any existing annotations (and format)
annotateDecl :: DynFlags -> LHsDecl GhcPs -> TransformT (Either String) (LHsDecl GhcPs) Source #
Given an LHsDecl, compute its exactprint annotations.
hoistGraft :: (forall x. m x -> n x) -> Graft m a -> Graft n a Source #
graftWithM :: forall ast m a l. (MonadFail m, Data a, ASTElement l ast) => SrcSpan -> (LocatedAn l ast -> TransformT m (Maybe (LocatedAn l ast))) -> Graft m a Source #
graftExprWithM :: forall m a. (MonadFail m, Data a) => SrcSpan -> (LHsExpr GhcPs -> TransformT m (Maybe (LHsExpr GhcPs))) -> Graft m a Source #
genericGraftWithSmallestM Source #
Arguments
| :: forall m a ast. (Monad m, Data a, Typeable ast) | |
| => Proxy (Located ast) | The type of nodes we'd like to consider when finding the smallest. |
| -> SrcSpan | |
| -> (DynFlags -> ast -> GenericM (TransformT m)) | |
| -> Graft m a |
Run the given transformation only on the smallest node in the tree that
contains the SrcSpan.
genericGraftWithLargestM Source #
Arguments
| :: forall m a ast. (Monad m, Data a, Typeable ast) | |
| => Proxy (Located ast) | The type of nodes we'd like to consider when finding the largest. |
| -> SrcSpan | |
| -> (DynFlags -> ast -> GenericM (TransformT m)) | |
| -> Graft m a |
Run the given transformation only on the largest node in the tree that
contains the SrcSpan.
graftSmallestDeclsWithM :: forall a. HasDecls a => SrcSpan -> (LHsDecl GhcPs -> TransformT (Either String) (Maybe [LHsDecl GhcPs])) -> Graft (Either String) a Source #
transform :: DynFlags -> ClientCapabilities -> VersionedTextDocumentIdentifier -> Graft (Either String) ParsedSource -> Annotated ParsedSource -> Either String WorkspaceEdit Source #
Convert a Graft into a WorkspaceEdit.
transformM :: Monad m => DynFlags -> ClientCapabilities -> VersionedTextDocumentIdentifier -> Graft (ExceptStringT m) ParsedSource -> Annotated ParsedSource -> m (Either String WorkspaceEdit) Source #
Convert a Graft into a WorkspaceEdit.
class Typeable a => ExactPrint a where #
An AST fragment with an annotation must be able to return the
requirements for nesting another one, captured in an Entry, and
to be able to use the rest of the exactprint machinery to print the
element. In the analogy to Outputable, exact plays the role of
ppr.
Methods
getAnnotationEntry :: a -> Entry #
setAnnotationAnchor :: a -> Anchor -> EpAnnComments -> a #
exact :: forall (m :: Type -> Type) w. (Monad m, Monoid w) => a -> EP w m a #
Instances
modifySmallestDeclWithM :: forall a m r. (HasDecls a, Monad m) => (SrcSpan -> m Bool) -> (LHsDecl GhcPs -> TransformT m ([LHsDecl GhcPs], r)) -> a -> TransformT m (a, Maybe r) Source #
Replace the smallest declaration whose SrcSpan satisfies the given condition with a new list of declarations.
For example, if you would like to move a where-clause-defined variable to the same level as its parent HsDecl, you could use this function.
When matching declaration is found in the sub-declarations of a, `Just r` is also returned with the new a. If
not declaration matched, then Nothing is returned.
modifyMgMatchesT :: Monad m => MatchGroup GhcPs (LHsExpr GhcPs) -> (LMatch GhcPs (LHsExpr GhcPs) -> TransformT m (LMatch GhcPs (LHsExpr GhcPs))) -> TransformT m (MatchGroup GhcPs (LHsExpr GhcPs)) Source #
Modify each LMatch in a MatchGroup
modifyMgMatchesT' :: Monad m => MatchGroup GhcPs (LHsExpr GhcPs) -> (LMatch GhcPs (LHsExpr GhcPs) -> TransformT m (LMatch GhcPs (LHsExpr GhcPs), r)) -> r -> (r -> r -> m r) -> TransformT m (MatchGroup GhcPs (LHsExpr GhcPs), r) Source #
Modify the each LMatch in a MatchGroup
modifySigWithM :: forall a m. (HasDecls a, Monad m) => IdP GhcPs -> (LHsSigType GhcPs -> LHsSigType GhcPs) -> a -> TransformT m a Source #
Modify the type signature for the given IdP. This function handles splitting a multi-sig SigD into multiple SigD if the type signature is changed.
For example, update the type signature for foo from Int to Bool:
- foo :: Int + foo :: Bool
- foo, bar :: Int + bar :: Int + foo :: Bool
- foo, bar, baz :: Int + bar, baz :: Int + foo :: Bool
genAnchor1 :: Anchor Source #
addParensToCtxt :: Maybe EpaLocation -> AnnContext -> AnnContext Source #
modifyAnns :: LocatedAn a ast -> (a -> a) -> LocatedAn a ast Source #
removeComma :: SrcSpanAnnA -> SrcSpanAnnA Source #
Helper function
eqSrcSpan :: SrcSpan -> SrcSpan -> Bool Source #
Equality on SrcSpan's. Ignores the (Maybe BufSpan) field of SrcSpan's.
eqSrcSpanA :: SrcAnn a -> SrcAnn b -> Bool Source #
Equality on SrcSpan's. Ignores the (Maybe BufSpan) field of SrcSpan's.
epl :: Int -> EpaLocation Source #
removeTrailingComma :: GenLocated SrcSpanAnnA ast -> GenLocated SrcSpanAnnA ast Source #
getAnnotatedParsedSourceRule :: Recorder (WithPriority Log) -> Rules () Source #
Get the latest version of the annotated parse source with comments.
data GetAnnotatedParsedSource Source #
Constructors
| GetAnnotatedParsedSource |
Instances
class (Data ast, Typeable l, Outputable l, Outputable ast, Default l) => ASTElement l ast | ast -> l where Source #
Minimal complete definition
Methods
parseAST :: Parser (LocatedAn l ast) Source #
maybeParensAST :: LocatedAn l ast -> LocatedAn l ast Source #
graft :: forall a. Data a => SrcSpan -> LocatedAn l ast -> Graft (Either String) a Source #
Instances
newtype ExceptStringT m a Source #
Constructors
| ExceptStringT | |
Fields
| |
Instances
data TransformT (m :: Type -> Type) a #
Monad transformer version of Transform monad
Instances
Constructors
| LogShake Log |
Orphan instances
| Show (Annotated ParsedSource) Source # | |
| NFData (Annotated ParsedSource) Source # | |
Methods rnf :: Annotated ParsedSource -> () # | |