Safe Haskell | None |
---|---|
Language | Haskell2010 |
Basic utilities and types for defining refactorings.
- type UnnamedModule dom = Ann UModule dom SrcTemplateStage
- type ModuleDom dom = (SourceFileKey, UnnamedModule dom)
- data SourceFileKey = SourceFileKey {}
- type LocalRefactoring dom = UnnamedModule dom -> LocalRefactor dom (UnnamedModule dom)
- type Refactoring dom = ModuleDom dom -> [ModuleDom dom] -> Refactor [RefactorChange dom]
- data RefactorChange dom
- = ContentChanged {
- fromContentChanged :: ModuleDom dom
- | ModuleRemoved { }
- | ModuleCreated { }
- = ContentChanged {
- data RefactorException
- moduleSourceFile :: String -> FilePath
- sourceFileModule :: FilePath -> String
- data ModuleCollection = ModuleCollection {}
- data ModuleRecord
- = ModuleNotLoaded { }
- | ModuleParsed { }
- | ModuleRenamed { }
- | ModuleTypeChecked { }
- | ModuleCodeGenerated { }
- data ModuleCollectionId
- class IsRefactSessionState st where
- runRefactor :: ModuleDom dom -> [ModuleDom dom] -> Refactoring dom -> Ghc (Either String [RefactorChange dom])
- localRefactoring :: HasModuleInfo dom => LocalRefactoring dom -> Refactoring dom
- localRefactoringRes :: HasModuleInfo dom => ((UnnamedModule dom -> UnnamedModule dom) -> a -> a) -> UnnamedModule dom -> LocalRefactor dom a -> Refactor a
- insertText :: SourceInfoTraversal p => [(SrcSpan, String, String)] -> p dom SrcTemplateStage -> p dom SrcTemplateStage
- addGeneratedImports :: [Name] -> Ann UModule dom SrcTemplateStage -> Ann UModule dom SrcTemplateStage
- newtype LocalRefactorT dom m a = LocalRefactorT {
- fromRefactorT :: WriterT [Either Name (SrcSpan, String, String)] (ReaderT (RefactorCtx dom) m) a
- data RefactorCtx dom = RefactorCtx {
- refModuleName :: Module
- refCtxRoot :: Ann UModule dom SrcTemplateStage
- refCtxImports :: [Ann UImportDecl dom SrcTemplateStage]
- class Monad m => RefactorMonad m where
- type LocalRefactor dom = LocalRefactorT dom Refactor
- type Refactor = ExceptT String Ghc
- registeredNamesFromPrelude :: [Name]
- otherNamesFromPrelude :: [String]
- qualifiedName :: Name -> String
- referenceName :: (HasImportInfo dom, HasModuleInfo dom) => Name -> LocalRefactor dom (Ann UName dom SrcTemplateStage)
- referenceOperator :: (HasImportInfo dom, HasModuleInfo dom) => Name -> LocalRefactor dom (Ann UOperator dom SrcTemplateStage)
- referenceName' :: (HasImportInfo dom, HasModuleInfo dom) => ([String] -> Name -> Ann nt dom SrcTemplateStage) -> Name -> LocalRefactor dom (Ann nt dom SrcTemplateStage)
- referenceBy :: ([String] -> Name -> Ann nt dom SrcTemplateStage) -> Name -> [Ann UImportDecl dom SrcTemplateStage] -> Ann nt dom SrcTemplateStage
- data NameClass
- classifyName :: RefactorMonad m => Name -> m NameClass
- validModuleName :: String -> Maybe String
- nameValid :: NameClass -> String -> Maybe String
- isIdStartChar :: Char -> Bool
- isOperatorChar :: Char -> Bool
- sfkModuleName :: Lens SourceFileKey SourceFileKey String String
- sfkFileName :: Lens SourceFileKey SourceFileKey FilePath FilePath
- mcSourceDirs :: Lens ModuleCollection ModuleCollection [FilePath] [FilePath]
- mcRoot :: Lens ModuleCollection ModuleCollection FilePath FilePath
- mcModules :: Lens ModuleCollection ModuleCollection (Map SourceFileKey ModuleRecord) (Map SourceFileKey ModuleRecord)
- mcLoadFlagSetup :: Lens ModuleCollection ModuleCollection (DynFlags -> IO DynFlags) (DynFlags -> IO DynFlags)
- mcId :: Lens ModuleCollection ModuleCollection ModuleCollectionId ModuleCollectionId
- mcFlagSetup :: Lens ModuleCollection ModuleCollection (DynFlags -> IO DynFlags) (DynFlags -> IO DynFlags)
- mcDependencies :: Lens ModuleCollection ModuleCollection [ModuleCollectionId] [ModuleCollectionId]
- typedRecModule :: Partial ModuleRecord ModuleRecord (UnnamedModule IdDom) (UnnamedModule IdDom)
- renamedRecModule :: Partial ModuleRecord ModuleRecord (UnnamedModule (Dom Name)) (UnnamedModule (Dom Name))
- recModuleWillNeedCode :: Partial ModuleRecord ModuleRecord Bool Bool
- recModuleExposed :: Partial ModuleRecord ModuleRecord Bool Bool
- parsedRecModule :: Partial ModuleRecord ModuleRecord (UnnamedModule (Dom RdrName)) (UnnamedModule (Dom RdrName))
- modRecMS :: Partial ModuleRecord ModuleRecord ModSummary ModSummary
- findModule :: (IsRefactSessionState st, Monad m) => String -> StateT st m [FilePath]
Documentation
type UnnamedModule dom = Ann UModule dom SrcTemplateStage Source #
A type for the input and result of refactoring a module
type ModuleDom dom = (SourceFileKey, UnnamedModule dom) Source #
The name of the module and the AST
data SourceFileKey Source #
Module name and marker to separate .hs-boot module definitions. Specifies a source file in a working directory.
type LocalRefactoring dom = UnnamedModule dom -> LocalRefactor dom (UnnamedModule dom) Source #
A refactoring that only affects one module
type Refactoring dom = ModuleDom dom -> [ModuleDom dom] -> Refactor [RefactorChange dom] Source #
The type of a refactoring
data RefactorChange dom Source #
Change in the project, modification or removal of a module.
Show (RefactorChange dom) Source # | |
data RefactorException Source #
Exceptions that can occur while loading modules or during internal operations (not during performing the refactor).
moduleSourceFile :: String -> FilePath Source #
sourceFileModule :: FilePath -> String Source #
data ModuleCollection Source #
The modules of a library, executable, test or benchmark. A package contains one or more module collection.
ModuleCollection | |
|
data ModuleRecord Source #
The state of a module.
data ModuleCollectionId Source #
This data structure identifies a module collection.
class IsRefactSessionState st where Source #
A common class for the state of refactoring tools
refSessMCs :: Simple Lens st [ModuleCollection] Source #
initSession :: st Source #
runRefactor :: ModuleDom dom -> [ModuleDom dom] -> Refactoring dom -> Ghc (Either String [RefactorChange dom]) Source #
Performs the given refactoring, transforming it into a Ghc action
localRefactoring :: HasModuleInfo dom => LocalRefactoring dom -> Refactoring dom Source #
Wraps a refactoring that only affects one module. Performs the per-module finishing touches.
localRefactoringRes :: HasModuleInfo dom => ((UnnamedModule dom -> UnnamedModule dom) -> a -> a) -> UnnamedModule dom -> LocalRefactor dom a -> Refactor a Source #
Transform the result of the local refactoring
insertText :: SourceInfoTraversal p => [(SrcSpan, String, String)] -> p dom SrcTemplateStage -> p dom SrcTemplateStage Source #
Re-inserts the elements removed from the AST that should be kept (for example preprocessor directives)
addGeneratedImports :: [Name] -> Ann UModule dom SrcTemplateStage -> Ann UModule dom SrcTemplateStage Source #
Adds the imports that bring names into scope that are needed by the refactoring
newtype LocalRefactorT dom m a Source #
Input and output information for the refactoring
LocalRefactorT | |
|
MonadTrans (LocalRefactorT dom) Source # | |
RefactorMonad (LocalRefactor dom) Source # | |
Monad m => MonadReader (RefactorCtx dom) (LocalRefactorT dom m) Source # | |
Monad m => MonadWriter [Either Name (SrcSpan, String, String)] (LocalRefactorT dom m) Source # | |
Monad m => Monad (LocalRefactorT dom m) Source # | |
Functor m => Functor (LocalRefactorT dom m) Source # | |
Applicative m => Applicative (LocalRefactorT dom m) Source # | |
MonadIO m => MonadIO (LocalRefactorT dom m) Source # | |
GhcMonad m => GhcMonad (LocalRefactorT dom m) Source # | |
(HasDynFlags m, Monad m) => HasDynFlags (LocalRefactorT dom m) Source # | |
ExceptionMonad m => ExceptionMonad (LocalRefactorT dom m) Source # | |
data RefactorCtx dom Source #
The information a refactoring can use
RefactorCtx | |
|
Monad m => MonadReader (RefactorCtx dom) (LocalRefactorT dom m) Source # | |
class Monad m => RefactorMonad m where Source #
A monad that can be used to refactor
RefactorMonad Refactor Source # | |
RefactorMonad (LocalRefactor dom) Source # | |
RefactorMonad m => RefactorMonad (StateT s m) Source # | |
RefactorMonad m => RefactorMonad (StateT s m) Source # | |
type LocalRefactor dom = LocalRefactorT dom Refactor Source #
The refactoring monad for a given module
qualifiedName :: Name -> String Source #
referenceName :: (HasImportInfo dom, HasModuleInfo dom) => Name -> LocalRefactor dom (Ann UName dom SrcTemplateStage) Source #
referenceOperator :: (HasImportInfo dom, HasModuleInfo dom) => Name -> LocalRefactor dom (Ann UOperator dom SrcTemplateStage) Source #
referenceName' :: (HasImportInfo dom, HasModuleInfo dom) => ([String] -> Name -> Ann nt dom SrcTemplateStage) -> Name -> LocalRefactor dom (Ann nt dom SrcTemplateStage) Source #
Create a name that references the definition. Generates an import if the definition is not yet imported.
referenceBy :: ([String] -> Name -> Ann nt dom SrcTemplateStage) -> Name -> [Ann UImportDecl dom SrcTemplateStage] -> Ann nt dom SrcTemplateStage Source #
Reference the name by the shortest suitable import
Different classes of definitions that have different kind of names.
Variable | Normal value definitions: functions, variables |
Ctor | Data constructors |
ValueOperator | Functions with operator-like names |
DataCtorOperator | Constructors with operator-like names |
SynonymOperator | UType definitions with operator-like names |
classifyName :: RefactorMonad m => Name -> m NameClass Source #
Get which category does a given name belong to
nameValid :: NameClass -> String -> Maybe String Source #
Check if a given name is valid for a given kind of definition
isIdStartChar :: Char -> Bool Source #
isOperatorChar :: Char -> Bool Source #
mcModules :: Lens ModuleCollection ModuleCollection (Map SourceFileKey ModuleRecord) (Map SourceFileKey ModuleRecord) Source #
mcLoadFlagSetup :: Lens ModuleCollection ModuleCollection (DynFlags -> IO DynFlags) (DynFlags -> IO DynFlags) Source #
mcFlagSetup :: Lens ModuleCollection ModuleCollection (DynFlags -> IO DynFlags) (DynFlags -> IO DynFlags) Source #
mcDependencies :: Lens ModuleCollection ModuleCollection [ModuleCollectionId] [ModuleCollectionId] Source #
typedRecModule :: Partial ModuleRecord ModuleRecord (UnnamedModule IdDom) (UnnamedModule IdDom) Source #
renamedRecModule :: Partial ModuleRecord ModuleRecord (UnnamedModule (Dom Name)) (UnnamedModule (Dom Name)) Source #
parsedRecModule :: Partial ModuleRecord ModuleRecord (UnnamedModule (Dom RdrName)) (UnnamedModule (Dom RdrName)) Source #
findModule :: (IsRefactSessionState st, Monad m) => String -> StateT st m [FilePath] Source #
Orphan instances
Show ErrorMessages Source # | |
(GhcMonad m, Monoid s) => GhcMonad (WriterT s m) Source # | |
GhcMonad m => GhcMonad (StateT s m) Source # | |
GhcMonad m => GhcMonad (ExceptT s m) Source # | |
GhcMonad m => GhcMonad (StateT s m) Source # | |
(Monad m, HasDynFlags m) => HasDynFlags (StateT s m) Source # | |
(Monad m, HasDynFlags m) => HasDynFlags (StateT s m) Source # | |
(ExceptionMonad m, Monoid s) => ExceptionMonad (WriterT s m) Source # | |
ExceptionMonad m => ExceptionMonad (StateT s m) Source # | |
ExceptionMonad m => ExceptionMonad (ExceptT s m) Source # | |
ExceptionMonad m => ExceptionMonad (StateT s m) Source # | |
GhcMonad m => GhcMonad (ReaderT * s m) Source # | |
ExceptionMonad m => ExceptionMonad (ReaderT * s m) Source # | |