Skip to content

Commit 08c5d94

Browse files
committed
Adapt to aeson-2 (incomplete)
1 parent ab79e36 commit 08c5d94

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,28 @@ import Data.Default (def)
1212
import qualified Data.Dependent.Map as DMap
1313
import qualified Data.Dependent.Sum as DSum
1414
#if MIN_VERSION_aeson(2,0,0)
15+
import qualified Data.Aeson.Key as A.Key
1516
import qualified Data.Aeson.KeyMap as Map
1617
#else
17-
import qualified Data.HasMap.Lazy as Map
18+
import qualified Data.HashMap.Lazy as Map
1819
#endif
20+
import Data.Functor.Identity
1921
import Data.List (nub)
22+
import Data.Maybe (fromJust)
23+
import Data.Text (Text)
2024
import Ide.Plugin.Config
2125
import Ide.Plugin.Properties (toDefaultJSON, toVSCodeExtensionSchema)
2226
import Ide.Types
2327
import Language.LSP.Types
2428

29+
#if MIN_VERSION_aeson(2,0,0)
30+
toKey :: Text -> A.Key
31+
toKey = A.Key.fromText
32+
#else
33+
toKey :: Text -> Text
34+
toKey = id
35+
#endif
36+
2537
-- Attention:
2638
-- 'diagnosticsOn' will never be added into the default config or the schema,
2739
-- since diagnostics emit in arbitrary shake rules -- we don't know
@@ -30,10 +42,10 @@ import Language.LSP.Types
3042
-- | Generates a default 'Config', but remains only effective items
3143
pluginsToDefaultConfig :: IdePlugins a -> A.Value
3244
pluginsToDefaultConfig IdePlugins {..} =
33-
A.Object $
34-
Map.alter
35-
( \(unsafeValueToObject -> o) ->
36-
Just $ A.Object $ Map.insert "plugin" elems o -- inplace the "plugin" section with our 'elems', leaving others unchanged
45+
A.Object $ runIdentity $
46+
Map.alterF
47+
( \(unsafeValueToObject . fromJust -> o) ->
48+
Identity $ Just $ A.Object $ Map.insert "plugin" elems o -- inplace the "plugin" section with our 'elems', leaving others unchanged
3749
)
3850
"haskell"
3951
(unsafeValueToObject (A.toJSON defaultConfig))
@@ -57,7 +69,7 @@ pluginsToDefaultConfig IdePlugins {..} =
5769
-- }
5870
singlePlugin PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {..}, ..} =
5971
let x = genericDefaultConfig <> dedicatedDefaultConfig
60-
in [pId A..= A.object x | not $ null x]
72+
in [(toKey pId) A..= A.object x | not $ null x]
6173
where
6274
(PluginHandlers (DMap.toList -> handlers)) = pluginHandlers
6375
customConfigToDedicatedDefaultConfig (CustomConfig p) = toDefaultJSON p
@@ -136,4 +148,4 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
136148
"default" A..= True,
137149
"description" A..= A.String ("Enables " <> pId <> " " <> desc)
138150
]
139-
withIdPrefix x = "haskell.plugin." <> pId <> "." <> x
151+
withIdPrefix x = toKey $ "haskell.plugin." <> pId <> "." <> x

0 commit comments

Comments
 (0)