@@ -22,7 +22,10 @@ module Ide.Types
2222, IdeNotification (.. )
2323, IdePlugins (IdePlugins , ipMap)
2424, DynFlagsModifications (.. )
25- , Config (.. ), PluginConfig (.. ), CheckParents (.. ), SessionLoadingPreferenceConfig (.. )
25+ , Config (.. ), PluginConfig (.. ), CheckParents (.. )
26+ , SessionLoadingPreferenceConfig (.. )
27+ , LegacySessionLoadingPreferenceConfig (.. )
28+ , getLegacySessionLoadingPreferenceConfig
2629, OptLinkTo (.. )
2730, ConfigDescriptor (.. ), defaultConfigDescriptor, configForPlugin
2831, CustomConfig (.. ), mkCustomConfig
@@ -78,7 +81,6 @@ import Data.Hashable (Hashable)
7881import Data.HashMap.Strict (HashMap )
7982import qualified Data.HashMap.Strict as HashMap
8083import Data.Kind (Type )
81- import qualified Data.List as List
8284import Data.List.Extra (find , sortOn )
8385import Data.List.NonEmpty (NonEmpty (.. ), toList )
8486import qualified Data.Map as Map
@@ -251,13 +253,29 @@ instance Pretty SessionLoadingPreferenceConfig where
251253 pretty PreferMultiWholeProjectLoading = " Prefer Whole Project Loading"
252254
253255-- | Labels for @SessionLoadingPreferenceConfig@ json format.
256+ --
257+ -- 'singleComponent' and 'multipleComponents' are outdated but are maintained here
258+ -- for backwards compatibility.
259+ -- We prefer 'single', 'multiNeededOnly' and 'multiWholeProject'
254260singleComponent , multipleComponents , single , multiNeededOnly , multiWholeProject :: T. Text
255261singleComponent = " singleComponent"
256262multipleComponents = " multipleComponents"
257263single = " single"
258264multiNeededOnly = " multi: needed-only"
259265multiWholeProject = " multi: whole-project"
260266
267+ -- | Historical artefact!
268+ -- Before HLS 2.15.0.0, the 'SessionLoadingPreferenceConfig' option was called `sessionLoading` with the values
269+ -- `multipleComponents` and `singleComponent`.
270+ --
271+ -- With HLS 2.15.0.0, we renamed these options and also added some new ones!
272+ -- For backwards compatibility, we support the old naming as well using
273+ -- this backwards compatibility newtype.
274+ newtype LegacySessionLoadingPreferenceConfig = LegacySessionLoadingPreferenceConfig SessionLoadingPreferenceConfig
275+
276+ getLegacySessionLoadingPreferenceConfig :: LegacySessionLoadingPreferenceConfig -> SessionLoadingPreferenceConfig
277+ getLegacySessionLoadingPreferenceConfig (LegacySessionLoadingPreferenceConfig conf) = conf
278+
261279instance ToJSON SessionLoadingPreferenceConfig where
262280 toJSON PreferSingleComponentLoading =
263281 String single
@@ -268,19 +286,24 @@ instance ToJSON SessionLoadingPreferenceConfig where
268286
269287instance FromJSON SessionLoadingPreferenceConfig where
270288 parseJSON (String val)
271- | val `elem` [singleComponent, single] = pure PreferSingleComponentLoading
272- | val `elem` [multipleComponents, multiNeededOnly] = pure PreferMultiComponentLoading
289+ | single == val = pure PreferSingleComponentLoading
290+ | multiNeededOnly == val = pure PreferMultiComponentLoading
273291 | val == multiWholeProject = pure PreferMultiWholeProjectLoading
274292 | otherwise = A. prependFailure " parsing SessionLoadingPreferenceConfig failed, "
275- (A. parseFail $ unwords [" Expected one of" , expected, " but got" , T. unpack val] )
276- where
277- expected = concat [" [" , List. intercalate " , " fields, " ]" ]
278- fields = map show
279- [single, multiNeededOnly, multiWholeProject]
280- ++
281- [ show old_value ++ " (deprecated)"
282- | old_value <- [singleComponent,multipleComponents]
283- ]
293+ (A. parseFail $ unwords [" Expected one of " ++ expected ++ " but got" , T. unpack val] )
294+ where
295+ expected = T. unpack $ T. intercalate " , " $ map (\ t -> " \' " <> t <> " \' " ) [single, multiNeededOnly, multiWholeProject]
296+ parseJSON o = A. prependFailure " parsing SessionLoadingPreferenceConfig failed, "
297+ (A. typeMismatch " String" o)
298+
299+ instance FromJSON LegacySessionLoadingPreferenceConfig where
300+ parseJSON (String val)
301+ | singleComponent == val = pure $ LegacySessionLoadingPreferenceConfig PreferSingleComponentLoading
302+ | multipleComponents == val = pure $ LegacySessionLoadingPreferenceConfig PreferMultiComponentLoading
303+ | otherwise = A. prependFailure " parsing SessionLoadingPreferenceConfig failed, "
304+ (A. parseFail $ " Expected one of " ++ expected ++ " but got " <> T. unpack val )
305+ where
306+ expected = T. unpack $ T. intercalate " , " $ map (\ t -> " \' " <> t <> " \' " ) [singleComponent, multipleComponents]
284307 parseJSON o = A. prependFailure " parsing SessionLoadingPreferenceConfig failed, "
285308 (A. typeMismatch " String" o)
286309
0 commit comments