Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 385008b

Browse files
committed
Make Ormolu respect cradle GHC options & extensions
1 parent bad8402 commit 385008b

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

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

+19-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import Haskell.Ide.Engine.MonadTypes
88

99
#if __GLASGOW_HASKELL__ >= 806
1010
import Control.Exception
11+
import Control.Monad
1112
import Control.Monad.IO.Class ( liftIO , MonadIO(..) )
1213
import Data.Aeson ( Value ( Null ) )
13-
import Data.Text
14+
import Data.List
15+
import Data.Maybe
16+
import qualified Data.Text as T
1417
import Ormolu
15-
import Ormolu.Config (defaultConfig)
16-
import Ormolu.Exception (OrmoluException)
1718
import Haskell.Ide.Engine.PluginUtils
19+
import HIE.Bios.Types
1820
#endif
1921

2022
ormoluDescriptor :: PluginId -> PluginDescriptor
@@ -34,13 +36,22 @@ 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+
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

Comments
 (0)