@@ -8,13 +8,15 @@ import Haskell.Ide.Engine.MonadTypes
88
99#if __GLASGOW_HASKELL__ >= 806
1010import Control.Exception
11+ import Control.Monad
1112import Control.Monad.IO.Class ( liftIO , MonadIO (.. ) )
1213import Data.Aeson ( Value ( Null ) )
13- import Data.Text
14+ import Data.List
15+ import Data.Maybe
16+ import qualified Data.Text as T
1417import Ormolu
15- import Ormolu.Config (defaultConfig )
16- import Ormolu.Exception (OrmoluException )
1718import Haskell.Ide.Engine.PluginUtils
19+ import HIE.Bios.Types
1820#endif
1921
2022ormoluDescriptor :: PluginId -> PluginDescriptor
@@ -34,13 +36,22 @@ ormoluDescriptor plId = PluginDescriptor
3436provider :: FormattingProvider
3537provider _contents _uri _typ _opts =
3638#if __GLASGOW_HASKELL__ >= 806
37- case _typ of
38- FormatRange _ -> return $ IdeResultFail (IdeError PluginError (pack " Selection formatting for Ormolu is not currently supported." ) Null )
39+ case _typ of
40+ FormatRange _ -> return $ IdeResultFail (IdeError PluginError (T. pack " Selection formatting for Ormolu is not currently supported." ) Null )
3941 FormatText -> pluginGetFile _contents _uri $ \ file -> do
40- result <- liftIO $ try @ OrmoluException (ormolu defaultConfig file (unpack _contents))
42+ opts <- getComponentOptions file
43+ let opts' = map DynOption $ filter exop $ join $ maybeToList $ componentOptions <$> opts
44+ conf = Config opts' False False True False
45+ result <- liftIO $ try @ OrmoluException (ormolu conf file (T. unpack _contents))
46+
4147 case result of
42- Left err -> return $ IdeResultFail (IdeError PluginError (pack $ " ormoluCmd: " ++ show err) Null )
48+ Left err -> return $ IdeResultFail (IdeError PluginError (T. pack $ " ormoluCmd: " ++ show err) Null )
4349 Right new -> return $ IdeResultOk [TextEdit (fullRange _contents) new]
50+ where
51+ exop s =
52+ " -X" `isPrefixOf` s
53+ || " -fplugin=" `isPrefixOf` s
54+ || " -pgmF=" `isPrefixOf` s
4455#else
4556 return $ IdeResultOk [] -- NOP formatter
46- #endif
57+ #endif
0 commit comments