@@ -8,13 +8,15 @@ import Haskell.Ide.Engine.MonadTypes
8
8
9
9
#if __GLASGOW_HASKELL__ >= 806
10
10
import Control.Exception
11
+ import Control.Monad
11
12
import Control.Monad.IO.Class ( liftIO , MonadIO (.. ) )
12
13
import Data.Aeson ( Value ( Null ) )
13
- import Data.Text
14
+ import Data.List
15
+ import Data.Maybe
16
+ import qualified Data.Text as T
14
17
import Ormolu
15
- import Ormolu.Config (defaultConfig )
16
- import Ormolu.Exception (OrmoluException )
17
18
import Haskell.Ide.Engine.PluginUtils
19
+ import HIE.Bios.Types
18
20
#endif
19
21
20
22
ormoluDescriptor :: PluginId -> PluginDescriptor
@@ -34,13 +36,22 @@ ormoluDescriptor plId = PluginDescriptor
34
36
provider :: FormattingProvider
35
37
provider _contents _uri _typ _opts =
36
38
#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 )
39
41
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
+
41
47
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 )
43
49
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
44
55
#else
45
56
return $ IdeResultOk [] -- NOP formatter
46
- #endif
57
+ #endif
0 commit comments