Skip to content

Commit 6a45743

Browse files
committed
Adapt to Aeson.Key
1 parent 3671bc5 commit 6a45743

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# LANGUAGE ConstraintKinds #-}
23
{-# LANGUAGE DataKinds #-}
34
{-# LANGUAGE FlexibleContexts #-}
@@ -41,6 +42,9 @@ module Ide.Plugin.Properties
4142
where
4243

4344
import qualified Data.Aeson as A
45+
#if MIN_VERSION_aeson(2,0,0)
46+
import qualified Data.Aeson.Key as A.Key
47+
#endif
4448
import qualified Data.Aeson.Types as A
4549
import Data.Either (fromRight)
4650
import Data.Function ((&))
@@ -162,6 +166,15 @@ type HasProperty s k t r = (k ~ 'PropertyKey s t, Elem s r, FindByKeyName s r ~
162166
-- "Description of exampleNumber"
163167
-- 233
164168
-- @
169+
170+
#if MIN_VERSION_aeson(2,0,0)
171+
toKey :: String -> A.Key
172+
toKey = A.Key.fromString
173+
#else
174+
toKey :: String -> T.Text
175+
toKey = pack
176+
#endif
177+
165178
emptyProperties :: Properties '[]
166179
emptyProperties = Properties Map.empty
167180

@@ -247,7 +260,7 @@ parseProperty kn k x = case k of
247260
)
248261
x
249262
where
250-
keyName = T.pack $ symbolVal kn
263+
keyName = toKey $ symbolVal kn
251264
parseEither :: forall a. A.FromJSON a => Either String a
252265
parseEither = A.parseEither (A..: keyName) x
253266

@@ -352,7 +365,7 @@ toDefaultJSON :: Properties r -> [A.Pair]
352365
toDefaultJSON (Properties p) = [toEntry s v | (s, v) <- Map.toList p]
353366
where
354367
toEntry :: String -> SomePropertyKeyWithMetaData -> A.Pair
355-
toEntry (T.pack -> s) = \case
368+
toEntry (toKey -> s) = \case
356369
(SomePropertyKeyWithMetaData SNumber MetaData {..}) ->
357370
s A..= defaultValue
358371
(SomePropertyKeyWithMetaData SInteger MetaData {..}) ->
@@ -371,7 +384,7 @@ toDefaultJSON (Properties p) = [toEntry s v | (s, v) <- Map.toList p]
371384
-- | Converts a properties definition into kv pairs as vscode schema
372385
toVSCodeExtensionSchema :: T.Text -> Properties r -> [A.Pair]
373386
toVSCodeExtensionSchema prefix (Properties p) =
374-
[(prefix <> T.pack k) A..= toEntry v | (k, v) <- Map.toList p]
387+
[(toKey $ T.unpack prefix <> k) A..= toEntry v | (k, v) <- Map.toList p]
375388
where
376389
toEntry :: SomePropertyKeyWithMetaData -> A.Value
377390
toEntry = \case

0 commit comments

Comments
 (0)