@@ -10,11 +10,13 @@ import Haskell.Ide.Engine.MonadTypes
10
10
import Control.Exception
11
11
import Control.Monad.IO.Class ( liftIO , MonadIO (.. ) )
12
12
import Data.Aeson ( Value ( Null ) )
13
- import Data.Text
13
+ import Data.List
14
+ import qualified Data.Text as T
14
15
import Ormolu
15
- import Ormolu.Config (defaultConfig )
16
- import Ormolu.Exception (OrmoluException )
17
16
import Haskell.Ide.Engine.PluginUtils
17
+ import Haskell.Ide.Engine.Cradle
18
+ import HIE.Bios.Flags
19
+ import HIE.Bios.Types
18
20
#endif
19
21
20
22
ormoluDescriptor :: PluginId -> PluginDescriptor
@@ -34,13 +36,24 @@ 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
+ cradle <- liftIO $ findLocalCradle file
43
+ res <- liftIO $ getCompilerOptions file cradle
44
+ let opts = case res of
45
+ CradleSuccess o -> fmap DynOption $ filter exop $ componentOptions o
46
+ _ -> []
47
+ let config = Config opts False False True False
48
+ result <- liftIO $ try @ OrmoluException (ormolu config file (T. unpack _contents))
41
49
case result of
42
- Left err -> return $ IdeResultFail (IdeError PluginError (pack $ " ormoluCmd: " ++ show err) Null )
50
+ Left err -> return $ IdeResultFail (IdeError PluginError (T. pack $ " ormoluCmd: " ++ show err) Null )
43
51
Right new -> return $ IdeResultOk [TextEdit (fullRange _contents) new]
44
52
#else
45
53
return $ IdeResultOk [] -- NOP formatter
46
- #endif
54
+ #endif
55
+ where
56
+ exop s =
57
+ " -X" `isPrefixOf` s
58
+ || " -fplugin=" `isPrefixOf` s
59
+ || " -pgmF=" `isPrefixOf` s
0 commit comments