|
| 1 | +{-# LANGUAGE CPP #-} |
1 | 2 | {-# LANGUAGE DataKinds #-}
|
2 | 3 | {-# LANGUAGE LambdaCase #-}
|
3 | 4 | {-# LANGUAGE OverloadedLabels #-}
|
@@ -79,24 +80,7 @@ provider recorder plId ideState token typ contents fp fo = ExceptT $ pluginWithI
|
79 | 80 | runExceptT (cliHandler fourmoluExePath fileOpts)
|
80 | 81 | else do
|
81 | 82 | 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' |
100 | 84 | let config =
|
101 | 85 | refineConfig ModuleSource Nothing Nothing Nothing $
|
102 | 86 | defaultConfig
|
@@ -157,6 +141,46 @@ provider recorder plId ideState token typ contents fp fo = ExceptT $ pluginWithI
|
157 | 141 | logWith recorder Info $ StdErr err
|
158 | 142 | throwError $ PluginInternalError $ "Fourmolu failed with exit code " <> T.pack (show n)
|
159 | 143 |
|
| 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 | + |
160 | 184 | data LogEvent
|
161 | 185 | = NoVersion Text
|
162 | 186 | | ConfigPath FilePath
|
|
0 commit comments