-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Refactoring Tool for Haskell
--
-- Contains a set of refactorings based on the Haskell-Tools framework to
-- easily transform a Haskell program. For the descriptions of the
-- implemented refactorings, see the homepage.
@package haskell-tools-refactor
@version 0.7.0.0
-- | Basic utilities and types for defining refactorings.
module Language.Haskell.Tools.Refactor.RefactorBase
-- | A type for the input and result of refactoring a module
type UnnamedModule dom = Ann UModule dom SrcTemplateStage
-- | The name of the module and the AST
type ModuleDom dom = (SourceFileKey, UnnamedModule dom)
-- | Module name and marker to separate .hs-boot module definitions.
-- Specifies a source file in a working directory.
data SourceFileKey
SourceFileKey :: IsBoot -> String -> SourceFileKey
[_sfkIsBoot] :: SourceFileKey -> IsBoot
[_sfkModuleName] :: SourceFileKey -> String
-- | Decides if a module is a .hs-boot file or a normal .hs file
data IsBoot
NormalHs :: IsBoot
IsHsBoot :: IsBoot
-- | A refactoring that only affects one module
type LocalRefactoring dom = UnnamedModule dom -> LocalRefactor dom (UnnamedModule dom)
-- | The type of a refactoring
type Refactoring dom = ModuleDom dom -> [ModuleDom dom] -> Refactor [RefactorChange dom]
-- | Change in the project, modification or removal of a module.
data RefactorChange dom
ContentChanged :: (ModuleDom dom) -> RefactorChange dom
[fromContentChanged] :: RefactorChange dom -> (ModuleDom dom)
ModuleRemoved :: String -> RefactorChange dom
[removedModuleName] :: RefactorChange dom -> String
ModuleCreated :: String -> UnnamedModule dom -> SourceFileKey -> RefactorChange dom
[createdModuleName] :: RefactorChange dom -> String
[createdModuleContent] :: RefactorChange dom -> UnnamedModule dom
[sameLocation] :: RefactorChange dom -> SourceFileKey
-- | Exceptions that can occur while loading modules or during internal
-- operations (not during performing the refactor).
data RefactorException
IllegalExtensions :: [String] -> RefactorException
SourceCodeProblem :: ErrorMessages -> RefactorException
ModuleNotInPackage :: String -> RefactorException
UnknownException :: String -> RefactorException
-- | Performs the given refactoring, transforming it into a Ghc action
runRefactor :: ModuleDom dom -> [ModuleDom dom] -> Refactoring dom -> Ghc (Either String [RefactorChange dom])
-- | Wraps a refactoring that only affects one module. Performs the
-- per-module finishing touches.
localRefactoring :: HasModuleInfo dom => LocalRefactoring dom -> Refactoring dom
-- | Transform the result of the local refactoring
localRefactoringRes :: HasModuleInfo dom => ((UnnamedModule dom -> UnnamedModule dom) -> a -> a) -> UnnamedModule dom -> LocalRefactor dom a -> Refactor a
-- | Re-inserts the elements removed from the AST that should be kept (for
-- example preprocessor directives)
insertText :: SourceInfoTraversal p => [(SrcSpan, String, String)] -> p dom SrcTemplateStage -> p dom SrcTemplateStage
-- | Adds the imports that bring names into scope that are needed by the
-- refactoring
addGeneratedImports :: [Name] -> Ann UModule dom SrcTemplateStage -> Ann UModule dom SrcTemplateStage
-- | Input and output information for the refactoring
newtype LocalRefactorT dom m a
LocalRefactorT :: WriterT [Either Name (SrcSpan, String, String)] (ReaderT (RefactorCtx dom) m) a -> LocalRefactorT dom m a
[fromRefactorT] :: LocalRefactorT dom m a -> WriterT [Either Name (SrcSpan, String, String)] (ReaderT (RefactorCtx dom) m) a
-- | The information a refactoring can use
data RefactorCtx dom
RefactorCtx :: Module -> Ann UModule dom SrcTemplateStage -> [Ann UImportDecl dom SrcTemplateStage] -> RefactorCtx dom
[refModuleName] :: RefactorCtx dom -> Module
[refCtxRoot] :: RefactorCtx dom -> Ann UModule dom SrcTemplateStage
[refCtxImports] :: RefactorCtx dom -> [Ann UImportDecl dom SrcTemplateStage]
-- | A monad that can be used to refactor
class Monad m => RefactorMonad m
refactError :: RefactorMonad m => String -> m a
liftGhc :: RefactorMonad m => Ghc a -> m a
-- | The refactoring monad for a given module
type LocalRefactor dom = LocalRefactorT dom Refactor
-- | The refactoring monad for the whole project
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)
-- | Create a name that references the definition. Generates an import if
-- the definition is not yet imported.
referenceName' :: (HasImportInfo dom, HasModuleInfo dom) => ([String] -> Name -> Ann nt dom SrcTemplateStage) -> Name -> LocalRefactor dom (Ann nt dom SrcTemplateStage)
-- | Reference the name by the shortest suitable import
referenceBy :: ([String] -> Name -> Ann nt dom SrcTemplateStage) -> Name -> [Ann UImportDecl dom SrcTemplateStage] -> Ann nt dom SrcTemplateStage
-- | Different classes of definitions that have different kind of names.
data NameClass
-- | Normal value definitions: functions, variables
Variable :: NameClass
-- | Data constructors
Ctor :: NameClass
-- | Functions with operator-like names
ValueOperator :: NameClass
-- | Constructors with operator-like names
DataCtorOperator :: NameClass
-- | UType definitions with operator-like names
SynonymOperator :: NameClass
-- | Get which category does a given name belong to
classifyName :: RefactorMonad m => Name -> m NameClass
-- | Checks if a given name is a valid module name
validModuleName :: String -> Maybe String
-- | Check if a given name is valid for a given kind of definition
nameValid :: NameClass -> String -> Maybe String
isIdStartChar :: Char -> Bool
isOperatorChar :: Char -> Bool
sfkModuleName :: Lens SourceFileKey SourceFileKey String String
sfkIsBoot :: Lens SourceFileKey SourceFileKey IsBoot IsBoot
instance GhcMonad.GhcMonad m => GhcMonad.GhcMonad (Language.Haskell.Tools.Refactor.RefactorBase.LocalRefactorT dom m)
instance Exception.ExceptionMonad m => Exception.ExceptionMonad (Language.Haskell.Tools.Refactor.RefactorBase.LocalRefactorT dom m)
instance (DynFlags.HasDynFlags m, GHC.Base.Monad m) => DynFlags.HasDynFlags (Language.Haskell.Tools.Refactor.RefactorBase.LocalRefactorT dom m)
instance Control.Monad.IO.Class.MonadIO m => Control.Monad.IO.Class.MonadIO (Language.Haskell.Tools.Refactor.RefactorBase.LocalRefactorT dom m)
instance GHC.Base.Monad m => Control.Monad.Writer.Class.MonadWriter [Data.Either.Either Name.Name (SrcLoc.SrcSpan, GHC.Base.String, GHC.Base.String)] (Language.Haskell.Tools.Refactor.RefactorBase.LocalRefactorT dom m)
instance GHC.Base.Monad m => Control.Monad.Reader.Class.MonadReader (Language.Haskell.Tools.Refactor.RefactorBase.RefactorCtx dom) (Language.Haskell.Tools.Refactor.RefactorBase.LocalRefactorT dom m)
instance GHC.Base.Monad m => GHC.Base.Monad (Language.Haskell.Tools.Refactor.RefactorBase.LocalRefactorT dom m)
instance GHC.Base.Applicative m => GHC.Base.Applicative (Language.Haskell.Tools.Refactor.RefactorBase.LocalRefactorT dom m)
instance GHC.Base.Functor m => GHC.Base.Functor (Language.Haskell.Tools.Refactor.RefactorBase.LocalRefactorT dom m)
instance GHC.Show.Show Language.Haskell.Tools.Refactor.RefactorBase.RefactorException
instance GHC.Show.Show Language.Haskell.Tools.Refactor.RefactorBase.SourceFileKey
instance GHC.Classes.Ord Language.Haskell.Tools.Refactor.RefactorBase.SourceFileKey
instance GHC.Classes.Eq Language.Haskell.Tools.Refactor.RefactorBase.SourceFileKey
instance GHC.Show.Show Language.Haskell.Tools.Refactor.RefactorBase.IsBoot
instance GHC.Classes.Ord Language.Haskell.Tools.Refactor.RefactorBase.IsBoot
instance GHC.Classes.Eq Language.Haskell.Tools.Refactor.RefactorBase.IsBoot
instance GHC.Show.Show ErrUtils.ErrorMessages
instance GHC.Exception.Exception Language.Haskell.Tools.Refactor.RefactorBase.RefactorException
instance GHC.Show.Show (Language.Haskell.Tools.Refactor.RefactorBase.RefactorChange dom)
instance (GhcMonad.GhcMonad m, GHC.Base.Monoid s) => GhcMonad.GhcMonad (Control.Monad.Trans.Writer.Lazy.WriterT s m)
instance (Exception.ExceptionMonad m, GHC.Base.Monoid s) => Exception.ExceptionMonad (Control.Monad.Trans.Writer.Lazy.WriterT s m)
instance (GHC.Base.Monad m, DynFlags.HasDynFlags m) => DynFlags.HasDynFlags (Control.Monad.Trans.State.Strict.StateT s m)
instance GhcMonad.GhcMonad m => GhcMonad.GhcMonad (Control.Monad.Trans.State.Strict.StateT s m)
instance Exception.ExceptionMonad m => Exception.ExceptionMonad (Control.Monad.Trans.State.Strict.StateT s m)
instance (GHC.Base.Monad m, DynFlags.HasDynFlags m) => DynFlags.HasDynFlags (Control.Monad.Trans.State.Lazy.StateT s m)
instance GhcMonad.GhcMonad m => GhcMonad.GhcMonad (Control.Monad.Trans.State.Lazy.StateT s m)
instance Exception.ExceptionMonad m => Exception.ExceptionMonad (Control.Monad.Trans.State.Lazy.StateT s m)
instance GhcMonad.GhcMonad m => GhcMonad.GhcMonad (Control.Monad.Trans.Reader.ReaderT s m)
instance Exception.ExceptionMonad m => Exception.ExceptionMonad (Control.Monad.Trans.Reader.ReaderT s m)
instance GhcMonad.GhcMonad m => GhcMonad.GhcMonad (Control.Monad.Trans.Except.ExceptT s m)
instance Exception.ExceptionMonad m => Exception.ExceptionMonad (Control.Monad.Trans.Except.ExceptT s m)
instance Control.Monad.Trans.Class.MonadTrans (Language.Haskell.Tools.Refactor.RefactorBase.LocalRefactorT dom)
instance Language.Haskell.Tools.Refactor.RefactorBase.RefactorMonad Language.Haskell.Tools.Refactor.RefactorBase.Refactor
instance Language.Haskell.Tools.Refactor.RefactorBase.RefactorMonad (Language.Haskell.Tools.Refactor.RefactorBase.LocalRefactor dom)
instance Language.Haskell.Tools.Refactor.RefactorBase.RefactorMonad m => Language.Haskell.Tools.Refactor.RefactorBase.RefactorMonad (Control.Monad.Trans.State.Strict.StateT s m)
instance Language.Haskell.Tools.Refactor.RefactorBase.RefactorMonad m => Language.Haskell.Tools.Refactor.RefactorBase.RefactorMonad (Control.Monad.Trans.State.Lazy.StateT s m)
-- | Defines utility methods that prepare Haskell modules for refactoring
module Language.Haskell.Tools.Refactor.Prepare
-- | A quick function to try the refactorings
tryRefactor :: (RealSrcSpan -> Refactoring IdDom) -> String -> String -> IO ()
-- | Adjust the source range to be applied to the refactored module
correctRefactorSpan :: UnnamedModule dom -> RealSrcSpan -> RealSrcSpan
-- | Set the given flags for the GHC session
useFlags :: [String] -> Ghc [String]
-- | Reloads the package database based on the session flags
reloadPkgDb :: Ghc ()
-- | Initialize GHC flags to default values that support refactoring
initGhcFlags :: Ghc ()
initGhcFlagsForTest :: Ghc ()
-- | Sets up basic flags and settings for GHC
initGhcFlags' :: Bool -> Ghc ()
-- | Use the given source directories when searching for imported modules
useDirs :: [FilePath] -> Ghc ()
-- | Don't use the given source directories when searching for imported
-- modules
deregisterDirs :: [FilePath] -> Ghc ()
-- | Translates module name and working directory into the name of the file
-- where the given module should be defined
toFileName :: FilePath -> String -> FilePath
-- | Translates module name and working directory into the name of the file
-- where the boot module should be defined
toBootFileName :: FilePath -> String -> FilePath
-- | Get the source directory where the module is located.
getSourceDir :: ModSummary -> IO FilePath
-- | Gets the path to the source file of the module.
getModSumOrig :: ModSummary -> FilePath
-- | Gets the module name
getModSumName :: ModSummary -> String
-- | Load the summary of a module given by the working directory and module
-- name.
loadModule :: String -> String -> Ghc ModSummary
-- | The final version of our AST, with type infromation added
type TypedModule = Ann UModule IdDom SrcTemplateStage
-- | Get the typed representation from a type-correct program.
parseTyped :: ModSummary -> Ghc TypedModule
-- | Modifies the dynamic flags for performing a ghc task
withAlteredDynFlags :: GhcMonad m => (DynFlags -> m DynFlags) -> m a -> m a
-- | Forces the code generation for a given module
forceCodeGen :: ModSummary -> ModSummary
-- | Forces ASM code generation for a given module
forceAsmGen :: ModSummary -> ModSummary
-- | Normalizes the flags for a module summary
modSumNormalizeFlags :: ModSummary -> ModSummary
-- | Removes all flags that are unintelligable for refactoring
normalizeFlags :: DynFlags -> DynFlags
-- | Read a source range from our textual format:
-- line:col-line:col or line:col
readSrcSpan :: String -> RealSrcSpan
-- | Read a source location from our format: line:col
readSrcLoc :: String -> RealSrcLoc
-- | Representation and operations for module collections (libraries,
-- executables, ...) in the framework.
module Language.Haskell.Tools.Refactor.GetModules
-- | The modules of a library, executable, test or benchmark. A package
-- contains one or more module collection.
data ModuleCollection
ModuleCollection :: ModuleCollectionId -> FilePath -> [FilePath] -> Map SourceFileKey ModuleRecord -> (DynFlags -> IO DynFlags) -> (DynFlags -> IO DynFlags) -> [ModuleCollectionId] -> ModuleCollection
[_mcId] :: ModuleCollection -> ModuleCollectionId
[_mcRoot] :: ModuleCollection -> FilePath
[_mcSourceDirs] :: ModuleCollection -> [FilePath]
[_mcModules] :: ModuleCollection -> Map SourceFileKey ModuleRecord
-- | Sets up the ghc environment for compiling the modules of this
-- collection
[_mcFlagSetup] :: ModuleCollection -> DynFlags -> IO DynFlags
-- | Sets up the ghc environment for dependency analysis
[_mcLoadFlagSetup] :: ModuleCollection -> DynFlags -> IO DynFlags
[_mcDependencies] :: ModuleCollection -> [ModuleCollectionId]
containingMC :: FilePath -> Simple Traversal [ModuleCollection] ModuleCollection
-- | The state of a module.
data ModuleRecord
ModuleNotLoaded :: Bool -> ModuleRecord
[_recModuleWillNeedCode] :: ModuleRecord -> Bool
ModuleParsed :: UnnamedModule (Dom RdrName) -> ModSummary -> ModuleRecord
[_parsedRecModule] :: ModuleRecord -> UnnamedModule (Dom RdrName)
[_modRecMS] :: ModuleRecord -> ModSummary
ModuleRenamed :: UnnamedModule (Dom Name) -> ModSummary -> ModuleRecord
[_renamedRecModule] :: ModuleRecord -> UnnamedModule (Dom Name)
[_modRecMS] :: ModuleRecord -> ModSummary
ModuleTypeChecked :: UnnamedModule IdDom -> ModSummary -> ModuleRecord
[_typedRecModule] :: ModuleRecord -> UnnamedModule IdDom
[_modRecMS] :: ModuleRecord -> ModSummary
ModuleCodeGenerated :: UnnamedModule IdDom -> ModSummary -> ModuleRecord
[_typedRecModule] :: ModuleRecord -> UnnamedModule IdDom
[_modRecMS] :: ModuleRecord -> ModSummary
-- | This data structure identifies a module collection.
data ModuleCollectionId
DirectoryMC :: FilePath -> ModuleCollectionId
LibraryMC :: String -> ModuleCollectionId
ExecutableMC :: String -> String -> ModuleCollectionId
TestSuiteMC :: String -> String -> ModuleCollectionId
BenchmarkMC :: String -> String -> ModuleCollectionId
moduleCollectionIdString :: ModuleCollectionId -> String
moduleCollectionPkgId :: ModuleCollectionId -> Maybe String
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
parsedRecModule :: Partial ModuleRecord ModuleRecord (UnnamedModule (Dom RdrName)) (UnnamedModule (Dom RdrName))
modRecMS :: Partial ModuleRecord ModuleRecord ModSummary ModSummary
-- | Find the module collection where the given module is.
lookupModuleColl :: String -> [ModuleCollection] -> Maybe (ModuleCollection)
lookupModInSCs :: SourceFileKey -> [ModuleCollection] -> Maybe (SourceFileKey, ModuleRecord)
removeModule :: String -> [ModuleCollection] -> [ModuleCollection]
hasGeneratedCode :: SourceFileKey -> [ModuleCollection] -> Bool
needsGeneratedCode :: SourceFileKey -> [ModuleCollection] -> Bool
codeGeneratedFor :: SourceFileKey -> [ModuleCollection] -> [ModuleCollection]
isAlreadyLoaded :: SourceFileKey -> [ModuleCollection] -> Bool
-- | Gets all ModuleCollections from a list of source directories. It also
-- orders the source directories that are package roots so that they can
-- be loaded in the order they are defined (no backward imports). This
-- matters in those cases because for them there can be special
-- compilation flags.
getAllModules :: [FilePath] -> IO [ModuleCollection]
-- | Sorts model collection in an order to remove all backward references.
-- Works because module collections defined by directories cannot be
-- recursive.
orderMCs :: [ModuleCollection] -> [ModuleCollection]
-- | Get modules of the project with the indicated root directory. If there
-- is a cabal file, it uses that, otherwise it just scans the directory
-- recursively for haskell sourcefiles. Only returns the non-boot haskell
-- modules, the boot modules will be found during loading.
getModules :: FilePath -> IO [ModuleCollection]
-- | Load the module giving a directory. All modules loaded from the folder
-- and subfolders.
modulesFromDirectory :: FilePath -> FilePath -> IO [String]
srcDirFromRoot :: FilePath -> String -> FilePath
-- | Load the module using a cabal file. The modules described in the cabal
-- file will be loaded. The flags and extensions set in the cabal file
-- will be used by default.
modulesFromCabalFile :: FilePath -> FilePath -> IO [ModuleCollection]
class ToModuleCollection t
mkModuleCollKey :: ToModuleCollection t => PackageName -> t -> ModuleCollectionId
getBuildInfo :: ToModuleCollection t => t -> BuildInfo
getModuleNames :: ToModuleCollection t => t -> [ModuleName]
isDirectoryMC :: ModuleCollection -> Bool
compileInContext :: ModuleCollection -> [ModuleCollection] -> DynFlags -> IO DynFlags
applyDependencies :: [ModuleCollection] -> [ModuleCollectionId] -> DynFlags -> DynFlags
onlyUseEnabled :: DynFlags -> DynFlags
dependencyToPkgFlag :: [ModuleCollection] -> ModuleCollectionId -> Maybe (PackageFlag)
setupLoadFlags :: [ModuleCollection] -> DynFlags -> IO DynFlags
breaks :: [a] -> [(a, [a])]
loadFlagsFromBuildInfo :: BuildInfo -> DynFlags -> IO DynFlags
flagsFromBuildInfo :: BuildInfo -> DynFlags -> IO DynFlags
setExtensionFlag' :: Extension -> DynFlags -> DynFlags
unSetExtensionFlag' :: Extension -> DynFlags -> DynFlags
turnOn :: Bool
turnOff :: Bool
impliedXFlags :: [(Extension, Bool, Extension)]
-- | Map the cabal extensions to the ones that GHC recognizes
translateExtension :: KnownExtension -> Maybe Extension
instance GHC.Show.Show Language.Haskell.Tools.Refactor.GetModules.ModuleRecord
instance Language.Haskell.Tools.Refactor.GetModules.ToModuleCollection Distribution.PackageDescription.Library
instance Language.Haskell.Tools.Refactor.GetModules.ToModuleCollection Distribution.PackageDescription.Executable
instance Language.Haskell.Tools.Refactor.GetModules.ToModuleCollection Distribution.PackageDescription.TestSuite
instance Language.Haskell.Tools.Refactor.GetModules.ToModuleCollection Distribution.PackageDescription.Benchmark
instance GHC.Show.Show Language.Haskell.Tools.Refactor.GetModules.ModuleCollectionId
instance GHC.Classes.Ord Language.Haskell.Tools.Refactor.GetModules.ModuleCollectionId
instance GHC.Classes.Eq Language.Haskell.Tools.Refactor.GetModules.ModuleCollectionId
instance GHC.Classes.Eq Language.Haskell.Tools.Refactor.GetModules.ModuleCollection
instance GHC.Show.Show Language.Haskell.Tools.Refactor.GetModules.ModuleCollection
-- | Common operations for managing refactoring sessions, for example
-- loading packages, re-loading modules.
module Language.Haskell.Tools.Refactor.Session
-- | The state common for refactoring tools, carrying the state of modules.
data RefactorSessionState
RefactorSessionState :: [ModuleCollection] -> RefactorSessionState
[__refSessMCs] :: RefactorSessionState -> [ModuleCollection]
_refSessMCs :: Lens RefactorSessionState RefactorSessionState [ModuleCollection] [ModuleCollection]
-- | A common class for the state of refactoring tools
class IsRefactSessionState st
refSessMCs :: IsRefactSessionState st => Simple Lens st [ModuleCollection]
initSession :: IsRefactSessionState st => st
-- | Load packages from the given directories. Loads modules, performs the
-- given callback action, warns for duplicate modules.
loadPackagesFrom :: IsRefactSessionState st => (ModSummary -> IO a) -> ([ModSummary] -> IO ()) -> (st -> FilePath -> IO [FilePath]) -> [FilePath] -> StateT st Ghc (Either RefactorException ([a], [String]))
-- | Handle GHC exceptions and RefactorException.
handleErrors :: ExceptionMonad m => m a -> m (Either RefactorException a)
keyFromMS :: ModSummary -> SourceFileKey
getMods :: (Monad m, IsRefactSessionState st) => Maybe SourceFileKey -> StateT st m (Maybe (SourceFileKey, UnnamedModule IdDom), [(SourceFileKey, UnnamedModule IdDom)])
getFileMods :: (GhcMonad m, IsRefactSessionState st) => FilePath -> StateT st m (Maybe (SourceFileKey, UnnamedModule IdDom), [(SourceFileKey, UnnamedModule IdDom)])
-- | Reload the modules that have been changed (given by predicate). Pefrom
-- the callback.
reloadChangedModules :: IsRefactSessionState st => (ModSummary -> IO a) -> ([ModSummary] -> IO ()) -> (ModSummary -> Bool) -> StateT st Ghc (Either RefactorException [a])
getReachableModules :: IsRefactSessionState st => ([ModSummary] -> IO ()) -> (ModSummary -> Bool) -> StateT st Ghc [ModSummary]
-- | Reload a given module. Perform a callback.
reloadModule :: IsRefactSessionState st => (ModSummary -> IO a) -> ModSummary -> StateT st Ghc a
checkEvaluatedMods :: IsRefactSessionState st => (ModSummary -> IO a) -> [ModSummary] -> StateT st Ghc [a]
-- | Re-load the module with code generation enabled. Must be used when the
-- module had already been loaded, but code generation were not enabled
-- by then.
codeGenForModule :: (ModSummary -> IO a) -> [ModuleCollection] -> ModSummary -> Ghc a
-- | Check which modules can be reached from the module, if it uses
-- template haskell.
getEvaluatedMods :: [ModSummary] -> Ghc [ModSummary]
modSumName :: ModSummary -> String
type NodeKey = (ModuleName, IsBoot)
type NodeMap a = Map NodeKey a
type SummaryNode = (ModSummary, Int, [Int])
getModFromNode :: SummaryNode -> ModSummary
moduleGraphNodes :: Bool -> [ModSummary] -> (Graph SummaryNode, HscSource -> ModuleName -> Maybe SummaryNode)
hscSourceToIsBoot :: HscSource -> IsBoot
summaryNodeKey :: SummaryNode -> Int
ms_home_imps :: ModSummary -> [Located ModuleName]
ms_home_srcimps :: ModSummary -> [Located ModuleName]
home_imps :: [(Maybe FastString, Located ModuleName)] -> [Located ModuleName]
instance Language.Haskell.Tools.Refactor.Session.IsRefactSessionState Language.Haskell.Tools.Refactor.Session.RefactorSessionState
-- | Operations for changing the AST
module Language.Haskell.Tools.Refactor.ChangeAST
-- | Remove an element from the AST while keeping the textual parts of it
-- that should not be removed (like preprocessor pragmas).
removeChild :: (SourceInfoTraversal e) => e dom SrcTemplateStage -> LocalRefactor dom ()
-- | Remove a separator from the AST while keeping the textual parts of it
-- that should not be removed (like preprocessor pragmas).
removeSeparator :: ([SourceTemplateTextElem], SrcSpan) -> LocalRefactor dom ()
-- | Defines operation on AST lists. AST lists carry source information so
-- simple list modification is not enough.
module Language.Haskell.Tools.Refactor.ListOperations
-- | Filters the elements of the list. By default it removes the separator
-- before the element. Of course, if the first element is removed, the
-- following separator is removed as well.
filterList :: SourceInfoTraversal e => (Ann e dom SrcTemplateStage -> Bool) -> AnnList e dom -> AnnList e dom
filterListIndexed :: SourceInfoTraversal e => (Int -> Ann e dom SrcTemplateStage -> Bool) -> AnnList e dom -> AnnList e dom
-- | A version of filterList that cares about keeping non-removable code
-- elements (like preprocessor pragmas)
filterListSt :: SourceInfoTraversal e => (Ann e dom SrcTemplateStage -> Bool) -> AnnList e dom -> LocalRefactor dom (AnnList e dom)
-- | A version of filterListIndexed that cares about keeping non-removable
-- code elements (like preprocessor pragmas)
filterListIndexedSt :: SourceInfoTraversal e => (Int -> Ann e dom SrcTemplateStage -> Bool) -> AnnList e dom -> LocalRefactor dom (AnnList e dom)
-- | Selects the given indices from a list
sublist :: [Int] -> [a] -> [a]
-- | Selects all but the given indices from a list
notSublist :: [Int] -> [a] -> [a]
-- | Inserts the element in the places where the two positioning functions
-- (one checks the element before, one the element after) allows the
-- placement.
insertWhere :: Bool -> Ann e dom SrcTemplateStage -> (Maybe (Ann e dom SrcTemplateStage) -> Bool) -> (Maybe (Ann e dom SrcTemplateStage) -> Bool) -> AnnList e dom -> AnnList e dom
-- | Checks where the element will be inserted given the two positioning
-- functions.
insertIndex :: (Maybe (Ann e dom SrcTemplateStage) -> Bool) -> (Maybe (Ann e dom SrcTemplateStage) -> Bool) -> [Ann e dom SrcTemplateStage] -> Maybe Int
-- | Gets the elements and separators from a list. The first separator is
-- zipped to the second element. To the first element, the "" string is
-- zipped.
zipWithSeparators :: AnnList e dom -> [(([SourceTemplateTextElem], SrcSpan), Ann e dom SrcTemplateStage)]
-- | Helper functions for defining refactorings.
module Language.Haskell.Tools.Refactor.Helpers
replaceWithJust :: Ann e dom SrcTemplateStage -> AnnMaybe e dom -> AnnMaybe e dom
replaceWithNothing :: AnnMaybe e dom -> AnnMaybe e dom
-- | Remove the container (where or let) when the last binding is removed.
removeEmptyBnds :: Simple Traversal (Module dom) (ValueBind dom) -> Simple Traversal (Module dom) (Expr dom) -> Module dom -> Module dom
-- | Puts the elements in the orginal order and remove duplicates (elements
-- with the same source range)
normalizeElements :: [Ann e dom SrcTemplateStage] -> [Ann e dom SrcTemplateStage]
-- | Utilities for transformations that work on both top-level and local
-- definitions
module Language.Haskell.Tools.Refactor.BindingElem
-- | A type class for handling definitions that can appear as both
-- top-level and local definitions
class NamedElement d => BindingElem d
-- | Accesses a type signature definition in a local or top-level
-- definition
sigBind :: BindingElem d => Simple Partial (Ann d dom SrcTemplateStage) (TypeSignature dom)
-- | Accesses a value or function definition in a local or top-level
-- definition
valBind :: BindingElem d => Simple Partial (Ann d dom SrcTemplateStage) (ValueBind dom)
-- | Accesses a type signature definition in a local or top-level
-- definition
fixitySig :: BindingElem d => Simple Partial (Ann d dom SrcTemplateStage) (FixitySignature dom)
-- | Creates a new definition from a type signature
createTypeSig :: BindingElem d => TypeSignature dom -> Ann d dom SrcTemplateStage
-- | Creates a new definition from a value or function definition
createBinding :: BindingElem d => ValueBind dom -> Ann d dom SrcTemplateStage
-- | Creates a new fixity signature
createFixitySig :: BindingElem d => FixitySignature dom -> Ann d dom SrcTemplateStage
-- | Checks if a given definition is a type signature
isTypeSig :: BindingElem d => Ann d dom SrcTemplateStage -> Bool
-- | Checks if a given definition is a function or value binding
isBinding :: BindingElem d => Ann d dom SrcTemplateStage -> Bool
-- | Checks if a given definition is a fixity signature
isFixitySig :: BindingElem d => Ann d dom SrcTemplateStage -> Bool
getValBindInList :: (BindingElem d) => RealSrcSpan -> AnnListG d dom SrcTemplateStage -> Maybe (ValueBind dom)
valBindsInList :: BindingElem d => Simple Traversal (AnnListG d dom SrcTemplateStage) (ValueBind dom)
instance Language.Haskell.Tools.Refactor.BindingElem.BindingElem Language.Haskell.Tools.AST.Representation.Decls.UDecl
instance Language.Haskell.Tools.Refactor.BindingElem.BindingElem Language.Haskell.Tools.AST.Representation.Binds.ULocalBind
-- | Defines the API for refactorings
module Language.Haskell.Tools.Refactor
-- | An element of the AST keeping extra information.
data Ann (elem :: * -> * -> *) dom stage :: (* -> * -> *) -> * -> * -> *
class HasSourceInfo e where type SourceInfoType e :: * where {
type family SourceInfoType e :: *;
}
srcInfo :: HasSourceInfo e => Simple Lens e (SourceInfoType e)
-- | Extracts or modifies the concrete range corresponding to a given
-- source info. In case of lists and optional elements, it may not
-- contain the elements inside.
class HasRange a
getRange :: HasRange a => a -> SrcSpan
setRange :: HasRange a => SrcSpan -> a -> a
annListElems :: RefMonads w r => Reference w r (MU *) (MU *) (AnnListG elem0 dom0 stage0) (AnnListG elem0 dom0 stage0) [Ann elem0 dom0 stage0] [Ann elem0 dom0 stage0]
annListAnnot :: RefMonads w r => Reference w r (MU *) (MU *) (AnnListG elem0 dom0 stage0) (AnnListG elem0 dom0 stage0) (NodeInfo (SemanticInfo dom0 (AnnListG elem0)) (ListInfo stage0)) (NodeInfo (SemanticInfo dom0 (AnnListG elem0)) (ListInfo stage0))
annList :: (RefMonads w r, MonadPlus r, Morph Maybe r, Morph [] r) => Reference w r (MU *) (MU *) (AnnListG e d s) (AnnListG e d s) (Ann e d s) (Ann e d s)
annJust :: (Functor w, Applicative w, Monad w, Functor r, Applicative r, MonadPlus r, Morph Maybe r) => Reference w r (MU *) (MU *) (AnnMaybeG e d s) (AnnMaybeG e d s) (Ann e d s) (Ann e d s)
annMaybe :: RefMonads w r => Reference w r (MU *) (MU *) (AnnMaybeG elem0 dom0 stage0) (AnnMaybeG elem0 dom0 stage0) (Maybe (Ann elem0 dom0 stage0)) (Maybe (Ann elem0 dom0 stage0))
isAnnNothing :: AnnMaybeG e d s -> Bool
-- | Class for domain configuration markers
class (Typeable * d, Data d, (~) * (SemanticInfo' d SameInfoDefaultCls) NoSemanticInfo, Data (SemanticInfo' d SameInfoNameCls), Data (SemanticInfo' d SameInfoExprCls), Data (SemanticInfo' d SameInfoImportCls), Data (SemanticInfo' d SameInfoModuleCls), Data (SemanticInfo' d SameInfoWildcardCls), Show (SemanticInfo' d SameInfoNameCls), Show (SemanticInfo' d SameInfoExprCls), Show (SemanticInfo' d SameInfoImportCls), Show (SemanticInfo' d SameInfoModuleCls), Show (SemanticInfo' d SameInfoWildcardCls)) => Domain d
-- | A short form of showing a range, without file name, for debugging
-- purposes.
shortShowSpan :: SrcSpan -> String
-- | A stage where the annotation controls how the original source code can
-- be retrieved from the AST. A source template is assigned to each node.
-- It has holes where the content of an other node should be printed and
-- ranges for the source code of the node.
data SrcTemplateStage :: *
-- | A class for traversing source information in an AST
class SourceInfoTraversal (a :: * -> * -> *)
sourceInfoTraverseUp :: (SourceInfoTraversal a, Monad f) => SourceInfoTrf f st1 st2 -> f () -> f () -> a dom st1 -> f (a dom st2)
sourceInfoTraverseDown :: (SourceInfoTraversal a, Monad f) => SourceInfoTrf f st1 st2 -> f () -> f () -> a dom st1 -> f (a dom st2)
sourceInfoTraverse :: (SourceInfoTraversal a, Monad f) => SourceInfoTrf f st1 st2 -> a dom st1 -> f (a dom st2)
sourceTemplateNodeRange :: Simple Lens (SpanInfo SrcTemplateStage) SrcSpan
sourceTemplateNodeElems :: Simple Lens (SpanInfo SrcTemplateStage) [SourceTemplateElem]
sourceTemplateListRange :: Simple Lens (ListInfo SrcTemplateStage) SrcSpan
srcTmpListBefore :: Simple Lens (ListInfo SrcTemplateStage) String
srcTmpListAfter :: Simple Lens (ListInfo SrcTemplateStage) String
srcTmpDefaultSeparator :: Simple Lens (ListInfo SrcTemplateStage) String
srcTmpIndented :: Simple Lens (ListInfo SrcTemplateStage) (Maybe [Bool])
srcTmpSeparators :: Simple Lens (ListInfo SrcTemplateStage) [([SourceTemplateTextElem], SrcSpan)]
sourceTemplateOptRange :: Simple Lens (OptionalInfo SrcTemplateStage) SrcSpan
srcTmpOptBefore :: Simple Lens (OptionalInfo SrcTemplateStage) String
srcTmpOptAfter :: Simple Lens (OptionalInfo SrcTemplateStage) String
data SourceTemplateTextElem :: *
NormalText :: String -> SourceTemplateTextElem
[_sourceTemplateText] :: SourceTemplateTextElem -> String
StayingText :: String -> String -> SourceTemplateTextElem
[_sourceTemplateText] :: SourceTemplateTextElem -> String
[_lineEndings] :: SourceTemplateTextElem -> String
sourceTemplateText :: Lens SourceTemplateTextElem SourceTemplateTextElem String String
module Language.Haskell.Tools.Refactor.Predefined.DataToNewtype
dataToNewtype :: LocalRefactoring dom
tryItOut :: String -> IO ()
module Language.Haskell.Tools.Refactor.Predefined.DollarApp
dollarApp :: DollarDomain dom => RealSrcSpan -> LocalRefactoring dom
type DollarDomain dom = (HasImportInfo dom, HasModuleInfo dom, HasFixityInfo dom, HasNameInfo dom)
tryItOut :: String -> String -> IO ()
module Language.Haskell.Tools.Refactor.Predefined.DollarApp1
tryItOut :: String -> String -> IO ()
dollarApp :: Domain dom => RealSrcSpan -> LocalRefactoring dom
replaceExpr :: Expr dom -> Expr dom
module Language.Haskell.Tools.Refactor.Predefined.DollarApp2
tryItOut :: String -> String -> IO ()
dollarApp :: (HasImportInfo dom, HasModuleInfo dom) => RealSrcSpan -> LocalRefactoring dom
replaceExpr :: (HasImportInfo dom, HasModuleInfo dom) => Expr dom -> LocalRefactor dom (Expr dom)
dollarName :: Name
module Language.Haskell.Tools.Refactor.Predefined.DollarApp3
tryItOut :: String -> String -> IO ()
type DollarMonad dom = StateT [SrcSpan] (LocalRefactor dom)
type DollarDomain dom = (HasImportInfo dom, HasModuleInfo dom, HasFixityInfo dom, HasNameInfo dom)
dollarApp :: DollarDomain dom => RealSrcSpan -> LocalRefactoring dom
replaceExpr :: DollarDomain dom => Expr dom -> [SrcSpan] -> DollarMonad dom (Expr dom)
parenExpr :: Expr dom -> DollarMonad dom (Expr dom)
parenDollar :: Bool -> Expr dom -> DollarMonad dom (Expr dom)
dollarName :: Name
module Language.Haskell.Tools.Refactor.Predefined.ExtractBinding
extractBinding' :: ExtractBindingDomain dom => RealSrcSpan -> String -> LocalRefactoring dom
-- | We need name information to identify bindings, and scope information
-- to check which entities must be directly passed as parameters.
type ExtractBindingDomain dom = (HasNameInfo dom, HasDefiningInfo dom, HasScopeInfo dom)
tryItOut :: String -> String -> String -> IO ()
module Language.Haskell.Tools.Refactor.Predefined.FloatOut
type FloatOutDefinition dom = (HasNameInfo dom, HasScopeInfo dom)
floatOut :: FloatOutDefinition dom => RealSrcSpan -> LocalRefactoring dom
data FloatState dom
NotEncountered :: FloatState dom
Extracted :: [LocalBind dom] -> FloatState dom
Inserted :: FloatState dom
extractAndInsert :: FloatOutDefinition dom => RealSrcSpan -> LocalBindList dom -> StateT (FloatState dom) (LocalRefactor dom) (LocalBindList dom)
checkConflict :: forall dom. FloatOutDefinition dom => LocalBind dom -> ([String], [String])
module Language.Haskell.Tools.Refactor.Predefined.GenerateExports
-- | Creates an export list that imports standalone top-level definitions
-- with all of their contained definitions
generateExports :: DomGenerateExports dom => LocalRefactoring dom
-- | We need name information to generate exports
type DomGenerateExports dom = (Domain dom, HasNameInfo dom)
module Language.Haskell.Tools.Refactor.Predefined.GenerateTypeSignature
-- | Perform the refactoring on either local or top-level definition
generateTypeSignature :: GenerateSignatureDomain dom => Simple Traversal (Module dom) (DeclList dom) -> Simple Traversal (Module dom) (LocalBindList dom) -> (forall d. (BindingElem d) => AnnList d dom -> Maybe (ValueBind dom)) -> LocalRefactoring dom
generateTypeSignature' :: GenerateSignatureDomain dom => RealSrcSpan -> LocalRefactoring dom
type GenerateSignatureDomain dom = (HasModuleInfo dom, HasIdInfo dom, HasImportInfo dom, HasScopeInfo dom)
tryItOut :: String -> String -> IO ()
module Language.Haskell.Tools.Refactor.Predefined.HelloRefactor
tryItOut :: String -> String -> IO ()
helloRefactor :: Domain dom => RealSrcSpan -> LocalRefactoring dom
helloExpr :: Expr dom -> Expr dom
module Language.Haskell.Tools.Refactor.Predefined.IfToGuards
ifToGuards :: Domain dom => RealSrcSpan -> LocalRefactoring dom
tryItOut :: String -> String -> IO ()
-- | Defines the inline binding refactoring that removes a value binding
-- and replaces all occurences with an expression equivalent to the body
-- of the binding.
module Language.Haskell.Tools.Refactor.Predefined.InlineBinding
inlineBinding :: forall dom. InlineBindingDomain dom => RealSrcSpan -> Refactoring dom
type InlineBindingDomain dom = (HasNameInfo dom, HasDefiningInfo dom, HasScopeInfo dom, HasModuleInfo dom)
tryItOut :: String -> String -> IO ()
module Language.Haskell.Tools.Refactor.Predefined.OrganizeImports
organizeImports :: forall dom. OrganizeImportsDomain dom => LocalRefactoring dom
type OrganizeImportsDomain dom = (HasNameInfo dom, HasImportInfo dom, HasModuleInfo dom)
projectOrganizeImports :: forall dom. OrganizeImportsDomain dom => Refactoring dom
module Language.Haskell.Tools.Refactor.Predefined.RenameDefinition
renameDefinition :: DomainRenameDefinition dom => Name -> [Name] -> String -> Refactoring dom
renameDefinition' :: forall dom. DomainRenameDefinition dom => RealSrcSpan -> String -> Refactoring dom
type DomainRenameDefinition dom = (HasNameInfo dom, HasScopeInfo dom, HasDefiningInfo dom, HasImplicitFieldsInfo dom, HasModuleInfo dom)
-- | Defines common utilities for using refactorings. Provides an interface
-- for both demo, command line and integrated tools.
module Language.Haskell.Tools.Refactor.Perform
-- | Executes a given command on the selected module and given other
-- modules
performCommand :: (HasModuleInfo dom, DomGenerateExports dom, OrganizeImportsDomain dom, DomainRenameDefinition dom, ExtractBindingDomain dom, GenerateSignatureDomain dom) => RefactorCommand -> ModuleDom dom -> [ModuleDom dom] -> Ghc (Either String [RefactorChange dom])
-- | A refactoring command
data RefactorCommand
NoRefactor :: RefactorCommand
OrganizeImports :: RefactorCommand
ProjectOrganizeImports :: RefactorCommand
GenerateExports :: RefactorCommand
GenerateSignature :: RealSrcSpan -> RefactorCommand
RenameDefinition :: RealSrcSpan -> String -> RefactorCommand
ExtractBinding :: RealSrcSpan -> String -> RefactorCommand
InlineBinding :: RealSrcSpan -> RefactorCommand
FloatOut :: RealSrcSpan -> RefactorCommand
-- | Recognize a command from its textual representation
readCommand :: String -> Either String RefactorCommand
-- | Check the parts and return the command
analyzeCommand :: String -> [String] -> Either String RefactorCommand
refactorCommands :: [String]
instance GHC.Show.Show Language.Haskell.Tools.Refactor.Perform.RefactorCommand