Skip to content

Commit 96d1c35

Browse files
Fix loadConfigFile
1 parent 2cf5480 commit 96d1c35

File tree

1 file changed

+45
-18
lines changed

1 file changed

+45
-18
lines changed

plugins/hls-fourmolu-plugin/src/Ide/Plugin/Fourmolu.hs

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE DataKinds #-}
23
{-# LANGUAGE LambdaCase #-}
34
{-# LANGUAGE OverloadedLabels #-}
@@ -79,24 +80,7 @@ provider recorder plId ideState token typ contents fp fo = ExceptT $ pluginWithI
7980
runExceptT (cliHandler fourmoluExePath fileOpts)
8081
else do
8182
logWith recorder Debug $ LogCompiledInVersion (showVersion Fourmolu.version)
82-
FourmoluConfig{..} <-
83-
liftIO (loadConfigFile fp') >>= \case
84-
ConfigLoaded file opts -> do
85-
logWith recorder Info $ ConfigPath file
86-
pure opts
87-
ConfigNotFound searchDirs -> do
88-
logWith recorder Info $ NoConfigPath searchDirs
89-
pure emptyConfig
90-
ConfigParseError f err -> do
91-
lift $ pluginSendNotification SMethod_WindowShowMessage $
92-
ShowMessageParams
93-
{ _type_ = MessageType_Error
94-
, _message = errorMessage
95-
}
96-
throwError $ PluginInternalError errorMessage
97-
where
98-
errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (show err)
99-
83+
FourmoluConfig{..} <- loadConfig recorder fp'
10084
let config =
10185
refineConfig ModuleSource Nothing Nothing Nothing $
10286
defaultConfig
@@ -157,6 +141,49 @@ provider recorder plId ideState token typ contents fp fo = ExceptT $ pluginWithI
157141
logWith recorder Info $ StdErr err
158142
throwError $ PluginInternalError $ "Fourmolu failed with exit code " <> T.pack (show n)
159143

144+
loadConfig ::
145+
Recorder (WithPriority LogEvent) ->
146+
FilePath ->
147+
ExceptT PluginError (HandlerM Ide.Types.Config) FourmoluConfig
148+
#if MIN_VERSION_fourmolu(0,16,0)
149+
loadConfig recorder fp = do
150+
liftIO (findConfigFile fp) >>= \case
151+
Left (ConfigNotFound searchDirs) -> do
152+
logWith recorder Info $ NoConfigPath searchDirs
153+
pure emptyConfig
154+
Right file -> do
155+
logWith recorder Info $ ConfigPath file
156+
Yaml.decodeFileEither file >>= \case
157+
Left e -> do
158+
let errorMessage = "Failed to load " <> T.pack file <> ": " <> T.pack (show err)
159+
lift $ pluginSendNotification SMethod_WindowShowMessage $
160+
ShowMessageParams
161+
{ _type_ = MessageType_Error
162+
, _message = errorMessage
163+
}
164+
throwError $ PluginInternalError errorMessage
165+
Right cfg -> do
166+
pure cfg
167+
#else
168+
loadConfig recorder fp = do
169+
liftIO (loadConfigFile fp) >>= \case
170+
ConfigLoaded file opts -> do
171+
logWith recorder Info $ ConfigPath file
172+
pure opts
173+
ConfigNotFound searchDirs -> do
174+
logWith recorder Info $ NoConfigPath searchDirs
175+
pure emptyConfig
176+
ConfigParseError f err -> do
177+
lift $ pluginSendNotification SMethod_WindowShowMessage $
178+
ShowMessageParams
179+
{ _type_ = MessageType_Error
180+
, _message = errorMessage
181+
}
182+
throwError $ PluginInternalError errorMessage
183+
where
184+
errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (show err)
185+
#endif
186+
160187
data LogEvent
161188
= NoVersion Text
162189
| ConfigPath FilePath

0 commit comments

Comments
 (0)