|
| 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 recorder fp' |
100 | 84 | let config = |
101 | 85 | refineConfig ModuleSource Nothing Nothing Nothing $ |
102 | 86 | defaultConfig |
@@ -157,6 +141,49 @@ 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 :: |
| 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 | + |
160 | 187 | data LogEvent |
161 | 188 | = NoVersion Text |
162 | 189 | | ConfigPath FilePath |
|
0 commit comments