From b501e5c92dac8b89ff0c1f962a4be4ecbc261e97 Mon Sep 17 00:00:00 2001 From: Łukasz Gołębiewski Date: Sun, 26 Jan 2020 11:36:49 +0000 Subject: Expose "format" function in Sylish.hs (#259) * Expose "format" function in Sylish.hs It's going to be needed for the haskell-ide integration * Update tests/Language/Haskell/StylishSpec.hs Co-Authored-By: Jasper Van der Jeugt * Remove empty line Co-authored-by: Jasper Van der Jeugt --- lib/Language/Haskell/Stylish.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib') diff --git a/lib/Language/Haskell/Stylish.hs b/lib/Language/Haskell/Stylish.hs index a40a7d2..4f6aa1f 100644 --- a/lib/Language/Haskell/Stylish.hs +++ b/lib/Language/Haskell/Stylish.hs @@ -16,6 +16,8 @@ module Language.Haskell.Stylish -- * Misc , module Language.Haskell.Stylish.Verbose , version + , format + , ConfigPath(..) , Lines , Step ) where @@ -91,3 +93,13 @@ runStep exts mfp ls step = runSteps :: Extensions -> Maybe FilePath -> [Step] -> Lines -> Either String Lines runSteps exts mfp steps ls = foldM (runStep exts mfp) ls steps + +newtype ConfigPath = ConfigPath { unConfigPath :: FilePath } + +-- |Formats given contents optionally using the config provided as first param. +-- The second file path is the location from which the contents were read. +-- If provided, it's going to be printed out in the error message. +format :: Maybe ConfigPath -> Maybe FilePath -> String -> IO (Either String Lines) +format maybeConfigPath maybeFilePath contents = do + conf <- loadConfig (makeVerbose True) (fmap unConfigPath maybeConfigPath) + pure $ runSteps (configLanguageExtensions conf) maybeFilePath (configSteps conf) $ lines contents -- cgit v1.2.3