1
+ {-# LANGUAGE CPP #-}
1
2
{-# LANGUAGE ConstraintKinds #-}
2
3
{-# LANGUAGE DataKinds #-}
3
4
{-# LANGUAGE FlexibleContexts #-}
@@ -41,6 +42,9 @@ module Ide.Plugin.Properties
41
42
where
42
43
43
44
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
44
48
import qualified Data.Aeson.Types as A
45
49
import Data.Either (fromRight )
46
50
import Data.Function ((&) )
@@ -162,6 +166,15 @@ type HasProperty s k t r = (k ~ 'PropertyKey s t, Elem s r, FindByKeyName s r ~
162
166
-- "Description of exampleNumber"
163
167
-- 233
164
168
-- @
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
+
165
178
emptyProperties :: Properties '[]
166
179
emptyProperties = Properties Map. empty
167
180
@@ -247,7 +260,7 @@ parseProperty kn k x = case k of
247
260
)
248
261
x
249
262
where
250
- keyName = T. pack $ symbolVal kn
263
+ keyName = toKey $ symbolVal kn
251
264
parseEither :: forall a . A. FromJSON a => Either String a
252
265
parseEither = A. parseEither (A. .: keyName) x
253
266
@@ -352,7 +365,7 @@ toDefaultJSON :: Properties r -> [A.Pair]
352
365
toDefaultJSON (Properties p) = [toEntry s v | (s, v) <- Map. toList p]
353
366
where
354
367
toEntry :: String -> SomePropertyKeyWithMetaData -> A. Pair
355
- toEntry (T. pack -> s) = \ case
368
+ toEntry (toKey -> s) = \ case
356
369
(SomePropertyKeyWithMetaData SNumber MetaData {.. }) ->
357
370
s A. .= defaultValue
358
371
(SomePropertyKeyWithMetaData SInteger MetaData {.. }) ->
@@ -371,7 +384,7 @@ toDefaultJSON (Properties p) = [toEntry s v | (s, v) <- Map.toList p]
371
384
-- | Converts a properties definition into kv pairs as vscode schema
372
385
toVSCodeExtensionSchema :: T. Text -> Properties r -> [A. Pair ]
373
386
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]
375
388
where
376
389
toEntry :: SomePropertyKeyWithMetaData -> A. Value
377
390
toEntry = \ case
0 commit comments