1- {-# LANGUAGE CPP #-}
21{-# LANGUAGE DataKinds #-}
32{-# LANGUAGE DisambiguateRecordFields #-}
43{-# LANGUAGE LambdaCase #-}
@@ -16,7 +15,7 @@ import Control.Exception (IOException, try)
1615import Control.Lens ((^.) )
1716import Control.Monad
1817import Control.Monad.IO.Class
19- import Data.Bifunctor (first )
18+ import Data.Bifunctor (bimap , first )
2019import Data.Maybe
2120import Data.Text (Text )
2221import qualified Data.Text as T
@@ -25,6 +24,7 @@ import Development.IDE.GHC.Compat as Compat hiding (Cpp, Warning,
2524 hang , vcat )
2625import qualified Development.IDE.GHC.Compat.Util as S
2726import GHC.LanguageExtensions.Type (Extension (Cpp ))
27+ import Ide.Plugin.Fourmolu.Shim
2828import Ide.Plugin.Properties
2929import Ide.PluginUtils (makeDiffTextEdit ,
3030 usePropertyLsp )
@@ -33,7 +33,6 @@ import Language.LSP.Server hiding (defaultConfig)
3333import Language.LSP.Types hiding (line )
3434import Language.LSP.Types.Lens (HasTabSize (tabSize ))
3535import Ormolu
36- import Ormolu.Config
3736import System.Exit
3837import System.FilePath
3938import System.Process.Run (cwd , proc )
@@ -100,17 +99,12 @@ provider recorder plId ideState typ contents fp fo = withIndefiniteProgress titl
10099 pure . Left . responseError $ " Fourmolu failed with exit code " <> T. pack (show n)
101100 else do
102101 let format fourmoluConfig =
103- first (mkError . show )
104- <$> try @ OrmoluException (makeDiffTextEdit contents <$> ormolu config fp' (T. unpack contents))
102+ bimap (mkError . show ) (makeDiffTextEdit contents )
103+ <$> try @ OrmoluException (ormolu config fp' (T. unpack contents))
105104 where
106- printerOpts =
107- #if MIN_VERSION_fourmolu(0,7,0)
108- cfgFilePrinterOpts fourmoluConfig
109- #else
110- fourmoluConfig
111-
112- #endif
105+ printerOpts = cfgFilePrinterOpts fourmoluConfig
113106 config =
107+ addFixityOverrides (cfgFileFixities fourmoluConfig) $
114108 defaultConfig
115109 { cfgDynOptions = map DynOption fileOpts
116110 , cfgRegion = region
@@ -119,29 +113,14 @@ provider recorder plId ideState typ contents fp fo = withIndefiniteProgress titl
119113 fillMissingPrinterOpts
120114 (printerOpts <> lspPrinterOpts)
121115 defaultPrinterOpts
122- #if MIN_VERSION_fourmolu(0,7,0)
123- , cfgFixityOverrides =
124- cfgFileFixities fourmoluConfig
125- #endif
126116 }
127117 in liftIO (loadConfigFile fp') >>= \ case
128118 ConfigLoaded file opts -> liftIO $ do
129119 logWith recorder Info $ ConfigPath file
130120 format opts
131121 ConfigNotFound searchDirs -> liftIO $ do
132122 logWith recorder Info $ NoConfigPath searchDirs
133- format emptyOptions
134- where
135- emptyOptions =
136- #if MIN_VERSION_fourmolu(0,7,0)
137- FourmoluConfig
138- { cfgFilePrinterOpts = mempty
139- , cfgFileFixities = mempty
140- }
141- #else
142- mempty
143- #endif
144-
123+ format emptyConfig
145124 ConfigParseError f err -> do
146125 sendNotification SWindowShowMessage $
147126 ShowMessageParams
@@ -150,13 +129,7 @@ provider recorder plId ideState typ contents fp fo = withIndefiniteProgress titl
150129 }
151130 return . Left $ responseError errorMessage
152131 where
153- errorMessage = " Failed to load " <> T. pack f <> " : " <> T. pack (convertErr err)
154- convertErr =
155- #if MIN_VERSION_fourmolu(0,7,0)
156- show
157- #else
158- snd
159- #endif
132+ errorMessage = " Failed to load " <> T. pack f <> " : " <> T. pack (showParseError err)
160133 where
161134 fp' = fromNormalizedFilePath fp
162135 title = " Formatting " <> T. pack (takeFileName fp')
0 commit comments