Skip to content

Commit 7248425

Browse files
Fix loadConfigFile
1 parent 2cf5480 commit 7248425

File tree

1 file changed

+42
-18
lines changed

1 file changed

+42
-18
lines changed

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

+42-18
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 fp'
10084
let config =
10185
refineConfig ModuleSource Nothing Nothing Nothing $
10286
defaultConfig
@@ -157,6 +141,46 @@ 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 :: FilePath -> ExceptT PluginError IO FourmoluConfig
145+
#if MIN_VERSION_fourmolu(0,16,0)
146+
loadConfig fp = do
147+
liftIO (findConfigFile fp) >>= \case
148+
Left (ConfigNotFound searchDirs) -> do
149+
logWith recorder Info $ NoConfigPath searchDirs
150+
pure emptyConfig
151+
Right file -> do
152+
logWith recorder Info $ ConfigPath file
153+
Yaml.decodeFileEither file >>= \case
154+
Left e -> do
155+
let errorMessage = "Failed to load " <> T.pack file <> ": " <> T.pack (show err)
156+
lift $ pluginSendNotification SMethod_WindowShowMessage $
157+
ShowMessageParams
158+
{ _type_ = MessageType_Error
159+
, _message = errorMessage
160+
}
161+
throwError $ PluginInternalError errorMessage
162+
Right cfg -> do
163+
pure cfg
164+
#else
165+
loadConfig fp = do
166+
liftIO (loadConfigFile fp) >>= \case
167+
ConfigLoaded file opts -> do
168+
logWith recorder Info $ ConfigPath file
169+
pure opts
170+
ConfigNotFound searchDirs -> do
171+
logWith recorder Info $ NoConfigPath searchDirs
172+
pure emptyConfig
173+
ConfigParseError f err -> do
174+
lift $ pluginSendNotification SMethod_WindowShowMessage $
175+
ShowMessageParams
176+
{ _type_ = MessageType_Error
177+
, _message = errorMessage
178+
}
179+
throwError $ PluginInternalError errorMessage
180+
where
181+
errorMessage = "Failed to load " <> T.pack f <> ": " <> T.pack (show err)
182+
#endif
183+
160184
data LogEvent
161185
= NoVersion Text
162186
| ConfigPath FilePath

0 commit comments

Comments
 (0)