| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
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, Outputable l) => 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, Typeable l, 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 -> Uri -> Graft (Either String) ParsedSource -> Annotated ParsedSource -> Either String WorkspaceEdit
- transformM :: Monad m => DynFlags -> ClientCapabilities -> Uri -> 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
- 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
- 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) => 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, Outputable l) => 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, Typeable l, 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 -> Uri -> Graft (Either String) ParsedSource -> Annotated ParsedSource -> Either String WorkspaceEdit Source #
Convert a Graft into a WorkspaceEdit.
transformM :: Monad m => DynFlags -> ClientCapabilities -> Uri -> 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
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.
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) => 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
| ASTElement NameAnn RdrName Source # | |
| p ~ GhcPs => ASTElement AnnListItem (ImportDecl p) Source # | |
Defined in Development.IDE.GHC.ExactPrint Methods parseAST :: Parser (LocatedAn AnnListItem (ImportDecl p)) Source # maybeParensAST :: LocatedAn AnnListItem (ImportDecl p) -> LocatedAn AnnListItem (ImportDecl p) Source # graft :: Data a => SrcSpan -> LocatedAn AnnListItem (ImportDecl p) -> Graft (Either String) a Source # | |
| p ~ GhcPs => ASTElement AnnListItem (HsDecl p) Source # | |
Defined in Development.IDE.GHC.ExactPrint | |
| p ~ GhcPs => ASTElement AnnListItem (HsExpr p) Source # | |
Defined in Development.IDE.GHC.ExactPrint | |
| p ~ GhcPs => ASTElement AnnListItem (Pat p) Source # | |
Defined in Development.IDE.GHC.ExactPrint | |
| p ~ GhcPs => ASTElement AnnListItem (HsType p) Source # | |
Defined in Development.IDE.GHC.ExactPrint | |
newtype ExceptStringT m a Source #
Constructors
| ExceptStringT | |
Fields
| |
Instances
data TransformT (m :: Type -> Type) a #
Monad transformer version of Transform monad
Instances
Orphan instances
| Show (Annotated ParsedSource) Source # | |
| NFData (Annotated ParsedSource) Source # | |
Methods rnf :: Annotated ParsedSource -> () # | |