Skip to content

Commit baa12ac

Browse files
committed
Pass ghc-options to Ormolu
1 parent ba76fab commit baa12ac

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/Haskell/Ide/Engine/Plugin/Ormolu.hs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import Haskell.Ide.Engine.MonadTypes
1010
import Control.Exception
1111
import Control.Monad.IO.Class ( liftIO , MonadIO(..) )
1212
import Data.Aeson ( Value ( Null ) )
13-
import Data.Text
13+
import Data.List
14+
import qualified Data.Text as T
1415
import Ormolu
15-
import Ormolu.Config (defaultConfig)
16-
import Ormolu.Exception (OrmoluException)
1716
import Haskell.Ide.Engine.PluginUtils
17+
import Haskell.Ide.Engine.Cradle
18+
import HIE.Bios.Flags
19+
import HIE.Bios.Types
1820
#endif
1921

2022
ormoluDescriptor :: PluginId -> PluginDescriptor
@@ -34,13 +36,24 @@ ormoluDescriptor plId = PluginDescriptor
3436
provider :: FormattingProvider
3537
provider _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+
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))
4149
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)
4351
Right new -> return $ IdeResultOk [TextEdit (fullRange _contents) new]
4452
#else
4553
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

Comments
 (0)