1
- {-# LANGUAGE CPP #-}
2
1
{-# LANGUAGE DataKinds #-}
3
2
{-# LANGUAGE DisambiguateRecordFields #-}
4
3
{-# LANGUAGE LambdaCase #-}
@@ -16,7 +15,7 @@ import Control.Exception (IOException, try)
16
15
import Control.Lens ((^.) )
17
16
import Control.Monad
18
17
import Control.Monad.IO.Class
19
- import Data.Bifunctor (first )
18
+ import Data.Bifunctor (bimap , first )
20
19
import Data.Maybe
21
20
import Data.Text (Text )
22
21
import qualified Data.Text as T
@@ -25,6 +24,7 @@ import Development.IDE.GHC.Compat as Compat hiding (Cpp, Warning,
25
24
hang , vcat )
26
25
import qualified Development.IDE.GHC.Compat.Util as S
27
26
import GHC.LanguageExtensions.Type (Extension (Cpp ))
27
+ import Ide.Plugin.Fourmolu.Shim
28
28
import Ide.Plugin.Properties
29
29
import Ide.PluginUtils (makeDiffTextEdit ,
30
30
usePropertyLsp )
@@ -33,7 +33,6 @@ import Language.LSP.Server hiding (defaultConfig)
33
33
import Language.LSP.Types hiding (line )
34
34
import Language.LSP.Types.Lens (HasTabSize (tabSize ))
35
35
import Ormolu
36
- import Ormolu.Config
37
36
import System.Exit
38
37
import System.FilePath
39
38
import System.Process.Run (cwd , proc )
@@ -100,17 +99,12 @@ provider recorder plId ideState typ contents fp fo = withIndefiniteProgress titl
100
99
pure . Left . responseError $ " Fourmolu failed with exit code " <> T. pack (show n)
101
100
else do
102
101
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))
105
104
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
113
106
config =
107
+ addFixityOverrides (cfgFileFixities fourmoluConfig) $
114
108
defaultConfig
115
109
{ cfgDynOptions = map DynOption fileOpts
116
110
, cfgRegion = region
@@ -119,29 +113,14 @@ provider recorder plId ideState typ contents fp fo = withIndefiniteProgress titl
119
113
fillMissingPrinterOpts
120
114
(printerOpts <> lspPrinterOpts)
121
115
defaultPrinterOpts
122
- #if MIN_VERSION_fourmolu(0,7,0)
123
- , cfgFixityOverrides =
124
- cfgFileFixities fourmoluConfig
125
- #endif
126
116
}
127
117
in liftIO (loadConfigFile fp') >>= \ case
128
118
ConfigLoaded file opts -> liftIO $ do
129
119
logWith recorder Info $ ConfigPath file
130
120
format opts
131
121
ConfigNotFound searchDirs -> liftIO $ do
132
122
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
145
124
ConfigParseError f err -> do
146
125
sendNotification SWindowShowMessage $
147
126
ShowMessageParams
@@ -150,13 +129,7 @@ provider recorder plId ideState typ contents fp fo = withIndefiniteProgress titl
150
129
}
151
130
return . Left $ responseError errorMessage
152
131
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)
160
133
where
161
134
fp' = fromNormalizedFilePath fp
162
135
title = " Formatting " <> T. pack (takeFileName fp')
0 commit comments