module Refact.Apply
( applyRefactorings,
applyRefactorings',
runRefactoring,
parseExtensions,
)
where
import Control.Monad (unless)
import Data.List (intercalate)
import Refact.Compat (Module)
import Refact.Fixity (applyFixities)
import Refact.Internal
import Refact.Types (Refactoring, SrcSpan)
applyRefactorings ::
FilePath ->
Maybe (Int, Int) ->
[[Refactoring SrcSpan]] ->
FilePath ->
[String] ->
IO String
applyRefactorings :: String
-> Maybe (Int, Int)
-> [[Refactoring SrcSpan]]
-> String
-> [String]
-> IO String
applyRefactorings String
libdir Maybe (Int, Int)
optionsPos [[Refactoring SrcSpan]]
inp String
file [String]
exts = do
let ([Extension]
enabled, [Extension]
disabled, [String]
invalid) = [String] -> ([Extension], [Extension], [String])
parseExtensions [String]
exts
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless ([String] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [String]
invalid) (IO () -> IO ()) -> (String -> IO ()) -> String -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO ()
forall a. String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$ String
"Unsupported extensions: " String -> String -> String
forall a. [a] -> [a] -> [a]
++ String -> [String] -> String
forall a. [a] -> [[a]] -> [a]
intercalate String
", " [String]
invalid
Module
m <-
(Errors -> IO Module)
-> (Module -> IO Module) -> Either Errors Module -> IO Module
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Errors -> IO Module
forall a. String -> Errors -> a
onError String
"apply") Module -> IO Module
applyFixities
(Either Errors Module -> IO Module)
-> IO (Either Errors Module) -> IO Module
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< String
-> ([Extension], [Extension])
-> String
-> IO (Either Errors Module)
parseModuleWithArgs String
libdir ([Extension]
enabled, [Extension]
disabled) String
file
Maybe (Int, Int)
-> Bool
-> [(String, [Refactoring SrcSpan])]
-> Maybe String
-> Verbosity
-> Module
-> IO String
apply Maybe (Int, Int)
optionsPos Bool
False ((String
forall a. Monoid a => a
mempty,) ([Refactoring SrcSpan] -> (String, [Refactoring SrcSpan]))
-> [[Refactoring SrcSpan]] -> [(String, [Refactoring SrcSpan])]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[Refactoring SrcSpan]]
inp) (String -> Maybe String
forall a. a -> Maybe a
Just String
file) Verbosity
Silent Module
m
applyRefactorings' ::
Maybe (Int, Int) ->
[[Refactoring SrcSpan]] ->
Module ->
IO String
applyRefactorings' :: Maybe (Int, Int) -> [[Refactoring SrcSpan]] -> Module -> IO String
applyRefactorings' Maybe (Int, Int)
optionsPos [[Refactoring SrcSpan]]
inp = Maybe (Int, Int)
-> Bool
-> [(String, [Refactoring SrcSpan])]
-> Maybe String
-> Verbosity
-> Module
-> IO String
apply Maybe (Int, Int)
optionsPos Bool
False ((String
forall a. Monoid a => a
mempty,) ([Refactoring SrcSpan] -> (String, [Refactoring SrcSpan]))
-> [[Refactoring SrcSpan]] -> [(String, [Refactoring SrcSpan])]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [[Refactoring SrcSpan]]
inp) Maybe String
forall a. Maybe a
Nothing Verbosity
Silent