@@ -180,7 +180,7 @@ data Config =
180180 , formattingProvider :: ! T. Text
181181 , cabalFormattingProvider :: ! T. Text
182182 , maxCompletions :: ! Int
183- , sessionLoading :: ! SessionLoadingPreferenceConfig
183+ , componentsLoading :: ! SessionLoadingPreferenceConfig
184184 , linkSourceTo :: ! OptLinkTo
185185 , linkDocTo :: ! OptLinkTo
186186 , plugins :: ! (Map. Map PluginId PluginConfig )
@@ -193,7 +193,7 @@ instance ToJSON Config where
193193 , " formattingProvider" .= formattingProvider
194194 , " cabalFormattingProvider" .= cabalFormattingProvider
195195 , " maxCompletions" .= maxCompletions
196- , " componentsLoading" .= sessionLoading
196+ , " componentsLoading" .= componentsLoading
197197 , " linkSourceTo" .= linkSourceTo
198198 , " linkDocTo" .= linkDocTo
199199 , " plugin" .= Map. mapKeysMonotonic (\ (PluginId p) -> p) plugins
@@ -209,7 +209,7 @@ instance Default Config where
209209 -- , cabalFormattingProvider = "cabal-fmt"
210210 -- this string value needs to kept in sync with the value provided in HlsPlugins
211211 , maxCompletions = 40
212- , sessionLoading = PreferMultiComponentLoading
212+ , componentsLoading = PreferMultiComponentLoading
213213 , linkSourceTo = LinkToHackage
214214 , linkDocTo = LinkToHackage
215215 , plugins = mempty
@@ -250,30 +250,36 @@ instance Pretty SessionLoadingPreferenceConfig where
250250 pretty PreferMultiComponentLoading = " Prefer Multiple Components Loading"
251251 pretty PreferMultiWholeProjectLoading = " Prefer Whole Project Loading"
252252
253+ -- | Labels for @SessionLoadingPreferenceConfig@ json format.
254+ singleComponent , multipleComponents , single , multiNeededOnly , multiWholeProject :: T. Text
255+ singleComponent = " singleComponent"
256+ multipleComponents = " multipleComponents"
257+ single = " single"
258+ multiNeededOnly = " multi: needed-only"
259+ multiWholeProject = " multi: whole-project"
260+
253261instance ToJSON SessionLoadingPreferenceConfig where
254262 toJSON PreferSingleComponentLoading =
255- String " single"
263+ String single
256264 toJSON PreferMultiComponentLoading =
257- String " multi: needed-only "
265+ String multiNeededOnly
258266 toJSON PreferMultiWholeProjectLoading =
259- String " multi: whole-project "
267+ String multiWholeProject
260268
261269instance FromJSON SessionLoadingPreferenceConfig where
262- parseJSON (String val) = case val of
263- " singleComponent" -> pure PreferSingleComponentLoading
264- " single" -> pure PreferSingleComponentLoading
265- " multipleComponents" -> pure PreferMultiComponentLoading
266- " multi: needed-only" -> pure PreferMultiComponentLoading
267- " multi: whole-project" -> pure PreferMultiWholeProjectLoading
268- _ -> A. prependFailure " parsing SessionLoadingPreferenceConfig failed, "
270+ parseJSON (String val)
271+ | val `elem` [singleComponent, single] = pure PreferSingleComponentLoading
272+ | val `elem` [multipleComponents, multiNeededOnly] = pure PreferMultiComponentLoading
273+ | val == multiWholeProject = pure PreferMultiWholeProjectLoading
274+ | otherwise = A. prependFailure " parsing SessionLoadingPreferenceConfig failed, "
269275 (A. parseFail $ unwords [" Expected one of" , expected, " but got" , T. unpack val] )
270276 where
271277 expected = concat [" [" , List. intercalate " , " fields, " ]" ]
272- fields = map ( show @ String )
273- [" single" , " multi: only-needed " , " multi: whole-project " ]
278+ fields = map show
279+ [single, multiNeededOnly, multiWholeProject ]
274280 ++
275- [ show @ String old_value ++ " (deprecated)"
276- | old_value <- [" singleComponent" , " multiComponent " ]
281+ [ show old_value ++ " (deprecated)"
282+ | old_value <- [singleComponent,multipleComponents ]
277283 ]
278284 parseJSON o = A. prependFailure " parsing SessionLoadingPreferenceConfig failed, "
279285 (A. typeMismatch " String" o)
0 commit comments