{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wno-redundant-constraints #-}
module Ide.Plugin.Properties
( PropertyType (..),
ToHsType,
MetaData (..),
PropertyKey (..),
SPropertyKey (..),
KeyNameProxy (..),
Properties,
HasProperty,
emptyProperties,
defineNumberProperty,
defineIntegerProperty,
defineStringProperty,
defineBooleanProperty,
defineObjectProperty,
defineArrayProperty,
defineEnumProperty,
toDefaultJSON,
toVSCodeExtensionSchema,
usePropertyEither,
useProperty,
(&),
)
where
import qualified Data.Aeson as A
import qualified Data.Aeson.Types as A
import Data.Either (fromRight)
import Data.Function ((&))
import Data.Kind (Constraint, Type)
import qualified Data.Map.Strict as Map
import Data.Proxy (Proxy (..))
import Data.String (IsString (fromString))
import qualified Data.Text as T
import GHC.OverloadedLabels (IsLabel (..))
import GHC.TypeLits
import Unsafe.Coerce (unsafeCoerce)
data PropertyType
= TNumber
| TInteger
| TString
| TBoolean
| TObject Type
| TArray Type
| TEnum Type
type family ToHsType (t :: PropertyType) where
ToHsType 'TNumber = Double
ToHsType 'TInteger = Int
ToHsType 'TString = T.Text
ToHsType 'TBoolean = Bool
ToHsType ('TObject a) = a
ToHsType ('TArray a) = [a]
ToHsType ('TEnum a) = a
data MetaData (t :: PropertyType) where
MetaData ::
(IsTEnum t ~ 'False) =>
{ forall (t :: PropertyType). MetaData t -> ToHsType t
defaultValue :: ToHsType t,
forall (t :: PropertyType). MetaData t -> Text
description :: T.Text
} ->
MetaData t
EnumMetaData ::
(IsTEnum t ~ 'True) =>
{ defaultValue :: ToHsType t,
description :: T.Text,
forall (t :: PropertyType). MetaData t -> [ToHsType t]
enumValues :: [ToHsType t],
forall (t :: PropertyType). MetaData t -> [Text]
enumDescriptions :: [T.Text]
} ->
MetaData t
data PropertyKey = PropertyKey Symbol PropertyType
data SPropertyKey (k :: PropertyKey) where
SNumber :: SPropertyKey ('PropertyKey s 'TNumber)
SInteger :: SPropertyKey ('PropertyKey s 'TInteger)
SString :: SPropertyKey ('PropertyKey s 'TString)
SBoolean :: SPropertyKey ('PropertyKey s 'TBoolean)
SObject :: (A.ToJSON a, A.FromJSON a) => Proxy a -> SPropertyKey ('PropertyKey s ('TObject a))
SArray :: (A.ToJSON a, A.FromJSON a) => Proxy a -> SPropertyKey ('PropertyKey s ('TArray a))
SEnum :: (A.ToJSON a, A.FromJSON a, Eq a, Show a) => Proxy a -> SPropertyKey ('PropertyKey s ('TEnum a))
data SomePropertyKeyWithMetaData
= forall k s t.
(k ~ 'PropertyKey s t) =>
SomePropertyKeyWithMetaData (SPropertyKey k) (MetaData t)
newtype Properties (r :: [PropertyKey]) = Properties (Map.Map String SomePropertyKeyWithMetaData)
data KeyNameProxy (s :: Symbol) = KnownSymbol s => KeyNameProxy
instance (KnownSymbol s', s ~ s') => IsLabel s (KeyNameProxy s') where
fromLabel :: KeyNameProxy s'
fromLabel = forall (s :: Symbol). KnownSymbol s => KeyNameProxy s
KeyNameProxy
type family IsTEnum (t :: PropertyType) :: Bool where
IsTEnum ('TEnum _) = 'True
IsTEnum _ = 'False
type family FindByKeyName (s :: Symbol) (r :: [PropertyKey]) :: PropertyType where
FindByKeyName s ('PropertyKey s t ': _) = t
FindByKeyName s (_ ': xs) = FindByKeyName s xs
type family Elem (s :: Symbol) (r :: [PropertyKey]) :: Constraint where
Elem s ('PropertyKey s _ ': _) = ()
Elem s (_ ': xs) = Elem s xs
Elem s '[] = TypeError ('Text "The key ‘" ':<>: 'Text s ':<>: 'Text "’ is missing")
type family NotElem (s :: Symbol) (r :: [PropertyKey]) :: Constraint where
NotElem s ('PropertyKey s _ ': _) = TypeError ('Text "The key ‘" ':<>: 'Text s ':<>: 'Text "’ is already defined")
NotElem s (_ ': xs) = NotElem s xs
NotElem s '[] = ()
type HasProperty s k t r = (k ~ 'PropertyKey s t, Elem s r, FindByKeyName s r ~ t, KnownSymbol s)
emptyProperties :: Properties '[]
emptyProperties :: Properties '[]
emptyProperties = forall (r :: [PropertyKey]).
Map String SomePropertyKeyWithMetaData -> Properties r
Properties forall k a. Map k a
Map.empty
insert ::
(k ~ 'PropertyKey s t, NotElem s r, KnownSymbol s) =>
KeyNameProxy s ->
SPropertyKey k ->
MetaData t ->
Properties r ->
Properties (k ': r)
insert :: forall (k :: PropertyKey) (s :: Symbol) (t :: PropertyType)
(r :: [PropertyKey]).
(k ~ 'PropertyKey s t, NotElem s r, KnownSymbol s) =>
KeyNameProxy s
-> SPropertyKey k
-> MetaData t
-> Properties r
-> Properties (k : r)
insert KeyNameProxy s
kn SPropertyKey k
key MetaData t
metadata (Properties Map String SomePropertyKeyWithMetaData
old) =
forall (r :: [PropertyKey]).
Map String SomePropertyKeyWithMetaData -> Properties r
Properties
( forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert
(forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal KeyNameProxy s
kn)
(forall (k :: PropertyKey) (s :: Symbol) (t :: PropertyType).
(k ~ 'PropertyKey s t) =>
SPropertyKey k -> MetaData t -> SomePropertyKeyWithMetaData
SomePropertyKeyWithMetaData SPropertyKey k
key MetaData t
metadata)
Map String SomePropertyKeyWithMetaData
old
)
find ::
(HasProperty s k t r) =>
KeyNameProxy s ->
Properties r ->
(SPropertyKey k, MetaData t)
find :: forall (s :: Symbol) (k :: PropertyKey) (t :: PropertyType)
(r :: [PropertyKey]).
HasProperty s k t r =>
KeyNameProxy s -> Properties r -> (SPropertyKey k, MetaData t)
find KeyNameProxy s
kn (Properties Map String SomePropertyKeyWithMetaData
p) = case Map String SomePropertyKeyWithMetaData
p forall k a. Ord k => Map k a -> k -> a
Map.! forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal KeyNameProxy s
kn of
(SomePropertyKeyWithMetaData SPropertyKey k
sing MetaData t
metadata) ->
forall a b. a -> b
unsafeCoerce (SPropertyKey k
sing, MetaData t
metadata)
usePropertyEither ::
(HasProperty s k t r) =>
KeyNameProxy s ->
Properties r ->
A.Object ->
Either String (ToHsType t)
usePropertyEither :: forall (s :: Symbol) (k :: PropertyKey) (t :: PropertyType)
(r :: [PropertyKey]).
HasProperty s k t r =>
KeyNameProxy s
-> Properties r -> Object -> Either String (ToHsType t)
usePropertyEither KeyNameProxy s
kn Properties r
p = forall (k :: PropertyKey) (s :: Symbol) (t :: PropertyType).
(k ~ 'PropertyKey s t, KnownSymbol s) =>
KeyNameProxy s
-> (SPropertyKey k, MetaData t)
-> Object
-> Either String (ToHsType t)
parseProperty KeyNameProxy s
kn (forall (s :: Symbol) (k :: PropertyKey) (t :: PropertyType)
(r :: [PropertyKey]).
HasProperty s k t r =>
KeyNameProxy s -> Properties r -> (SPropertyKey k, MetaData t)
find KeyNameProxy s
kn Properties r
p)
useProperty ::
(HasProperty s k t r) =>
KeyNameProxy s ->
Properties r ->
A.Object ->
ToHsType t
useProperty :: forall (s :: Symbol) (k :: PropertyKey) (t :: PropertyType)
(r :: [PropertyKey]).
HasProperty s k t r =>
KeyNameProxy s -> Properties r -> Object -> ToHsType t
useProperty KeyNameProxy s
kn Properties r
p = forall b a. b -> Either a b -> b
fromRight (forall (t :: PropertyType). MetaData t -> ToHsType t
defaultValue MetaData t
metadata) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (s :: Symbol) (k :: PropertyKey) (t :: PropertyType)
(r :: [PropertyKey]).
HasProperty s k t r =>
KeyNameProxy s
-> Properties r -> Object -> Either String (ToHsType t)
usePropertyEither KeyNameProxy s
kn Properties r
p
where
(SPropertyKey ('PropertyKey s t)
_, MetaData t
metadata) = forall (s :: Symbol) (k :: PropertyKey) (t :: PropertyType)
(r :: [PropertyKey]).
HasProperty s k t r =>
KeyNameProxy s -> Properties r -> (SPropertyKey k, MetaData t)
find KeyNameProxy s
kn Properties r
p
parseProperty ::
(k ~ 'PropertyKey s t, KnownSymbol s) =>
KeyNameProxy s ->
(SPropertyKey k, MetaData t) ->
A.Object ->
Either String (ToHsType t)
parseProperty :: forall (k :: PropertyKey) (s :: Symbol) (t :: PropertyType).
(k ~ 'PropertyKey s t, KnownSymbol s) =>
KeyNameProxy s
-> (SPropertyKey k, MetaData t)
-> Object
-> Either String (ToHsType t)
parseProperty KeyNameProxy s
kn (SPropertyKey k, MetaData t)
k Object
x = case (SPropertyKey k, MetaData t)
k of
(SPropertyKey k
SNumber, MetaData t
_) -> forall a. FromJSON a => Either String a
parseEither
(SPropertyKey k
SInteger, MetaData t
_) -> forall a. FromJSON a => Either String a
parseEither
(SPropertyKey k
SString, MetaData t
_) -> forall a. FromJSON a => Either String a
parseEither
(SPropertyKey k
SBoolean, MetaData t
_) -> forall a. FromJSON a => Either String a
parseEither
(SObject Proxy a
_, MetaData t
_) -> forall a. FromJSON a => Either String a
parseEither
(SArray Proxy a
_, MetaData t
_) -> forall a. FromJSON a => Either String a
parseEither
(SEnum Proxy a
_, EnumMetaData {[Text]
[ToHsType t]
Text
ToHsType t
enumDescriptions :: [Text]
enumValues :: [ToHsType t]
description :: Text
defaultValue :: ToHsType t
enumDescriptions :: forall (t :: PropertyType). MetaData t -> [Text]
enumValues :: forall (t :: PropertyType). MetaData t -> [ToHsType t]
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
forall a b. (a -> Parser b) -> a -> Either String b
A.parseEither
( \Object
o -> do
a
txt <- Object
o forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
key
if a
txt forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [ToHsType t]
enumValues
then forall (f :: * -> *) a. Applicative f => a -> f a
pure a
txt
else
forall (m :: * -> *) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$
String
"invalid enum member: "
forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show a
txt
forall a. Semigroup a => a -> a -> a
<> String
". Expected one of "
forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show [ToHsType t]
enumValues
)
Object
x
where
key :: Key
key = forall a. IsString a => String -> a
fromString forall a b. (a -> b) -> a -> b
$ forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal KeyNameProxy s
kn
parseEither :: forall a. A.FromJSON a => Either String a
parseEither :: forall a. FromJSON a => Either String a
parseEither = forall a b. (a -> Parser b) -> a -> Either String b
A.parseEither (forall a. FromJSON a => Object -> Key -> Parser a
A..: Key
key) Object
x
defineNumberProperty ::
(KnownSymbol s, NotElem s r) =>
KeyNameProxy s ->
T.Text ->
Double ->
Properties r ->
Properties ('PropertyKey s 'TNumber : r)
defineNumberProperty :: forall (s :: Symbol) (r :: [PropertyKey]).
(KnownSymbol s, NotElem s r) =>
KeyNameProxy s
-> Text
-> Double
-> Properties r
-> Properties ('PropertyKey s 'TNumber : r)
defineNumberProperty KeyNameProxy s
kn Text
description Double
defaultValue =
forall (k :: PropertyKey) (s :: Symbol) (t :: PropertyType)
(r :: [PropertyKey]).
(k ~ 'PropertyKey s t, NotElem s r, KnownSymbol s) =>
KeyNameProxy s
-> SPropertyKey k
-> MetaData t
-> Properties r
-> Properties (k : r)
insert KeyNameProxy s
kn forall (a :: Symbol). SPropertyKey ('PropertyKey a 'TNumber)
SNumber MetaData {Double
Text
defaultValue :: Double
description :: Text
description :: Text
defaultValue :: ToHsType 'TNumber
..}
defineIntegerProperty ::
(KnownSymbol s, NotElem s r) =>
KeyNameProxy s ->
T.Text ->
Int ->
Properties r ->
Properties ('PropertyKey s 'TInteger : r)
defineIntegerProperty :: forall (s :: Symbol) (r :: [PropertyKey]).
(KnownSymbol s, NotElem s r) =>
KeyNameProxy s
-> Text
-> Int
-> Properties r
-> Properties ('PropertyKey s 'TInteger : r)
defineIntegerProperty KeyNameProxy s
kn Text
description Int
defaultValue =
forall (k :: PropertyKey) (s :: Symbol) (t :: PropertyType)
(r :: [PropertyKey]).
(k ~ 'PropertyKey s t, NotElem s r, KnownSymbol s) =>
KeyNameProxy s
-> SPropertyKey k
-> MetaData t
-> Properties r
-> Properties (k : r)
insert KeyNameProxy s
kn forall (a :: Symbol). SPropertyKey ('PropertyKey a 'TInteger)
SInteger MetaData {Int
Text
defaultValue :: Int
description :: Text
description :: Text
defaultValue :: ToHsType 'TInteger
..}
defineStringProperty ::
(KnownSymbol s, NotElem s r) =>
KeyNameProxy s ->
T.Text ->
T.Text ->
Properties r ->
Properties ('PropertyKey s 'TString : r)
defineStringProperty :: forall (s :: Symbol) (r :: [PropertyKey]).
(KnownSymbol s, NotElem s r) =>
KeyNameProxy s
-> Text
-> Text
-> Properties r
-> Properties ('PropertyKey s 'TString : r)
defineStringProperty KeyNameProxy s
kn Text
description Text
defaultValue =
forall (k :: PropertyKey) (s :: Symbol) (t :: PropertyType)
(r :: [PropertyKey]).
(k ~ 'PropertyKey s t, NotElem s r, KnownSymbol s) =>
KeyNameProxy s
-> SPropertyKey k
-> MetaData t
-> Properties r
-> Properties (k : r)
insert KeyNameProxy s
kn forall (a :: Symbol). SPropertyKey ('PropertyKey a 'TString)
SString MetaData {Text
defaultValue :: Text
description :: Text
description :: Text
defaultValue :: ToHsType 'TString
..}
defineBooleanProperty ::
(KnownSymbol s, NotElem s r) =>
KeyNameProxy s ->
T.Text ->
Bool ->
Properties r ->
Properties ('PropertyKey s 'TBoolean : r)
defineBooleanProperty :: forall (s :: Symbol) (r :: [PropertyKey]).
(KnownSymbol s, NotElem s r) =>
KeyNameProxy s
-> Text
-> Bool
-> Properties r
-> Properties ('PropertyKey s 'TBoolean : r)
defineBooleanProperty KeyNameProxy s
kn Text
description Bool
defaultValue =
forall (k :: PropertyKey) (s :: Symbol) (t :: PropertyType)
(r :: [PropertyKey]).
(k ~ 'PropertyKey s t, NotElem s r, KnownSymbol s) =>
KeyNameProxy s
-> SPropertyKey k
-> MetaData t
-> Properties r
-> Properties (k : r)
insert KeyNameProxy s
kn forall (a :: Symbol). SPropertyKey ('PropertyKey a 'TBoolean)
SBoolean MetaData {Bool
Text
defaultValue :: Bool
description :: Text
description :: Text
defaultValue :: ToHsType 'TBoolean
..}
defineObjectProperty ::
(KnownSymbol s, NotElem s r, A.ToJSON a, A.FromJSON a) =>
KeyNameProxy s ->
T.Text ->
a ->
Properties r ->
Properties ('PropertyKey s ('TObject a) : r)
defineObjectProperty :: forall (s :: Symbol) (r :: [PropertyKey]) a.
(KnownSymbol s, NotElem s r, ToJSON a, FromJSON a) =>
KeyNameProxy s
-> Text
-> a
-> Properties r
-> Properties ('PropertyKey s ('TObject a) : r)
defineObjectProperty KeyNameProxy s
kn Text
description a
defaultValue =
forall (k :: PropertyKey) (s :: Symbol) (t :: PropertyType)
(r :: [PropertyKey]).
(k ~ 'PropertyKey s t, NotElem s r, KnownSymbol s) =>
KeyNameProxy s
-> SPropertyKey k
-> MetaData t
-> Properties r
-> Properties (k : r)
insert KeyNameProxy s
kn (forall a (s :: Symbol).
(ToJSON a, FromJSON a) =>
Proxy a -> SPropertyKey ('PropertyKey s ('TObject a))
SObject forall {k} (t :: k). Proxy t
Proxy) MetaData {a
Text
defaultValue :: a
description :: Text
description :: Text
defaultValue :: ToHsType ('TObject a)
..}
defineArrayProperty ::
(KnownSymbol s, NotElem s r, A.ToJSON a, A.FromJSON a) =>
KeyNameProxy s ->
T.Text ->
[a] ->
Properties r ->
Properties ('PropertyKey s ('TArray a) : r)
defineArrayProperty :: forall (s :: Symbol) (r :: [PropertyKey]) a.
(KnownSymbol s, NotElem s r, ToJSON a, FromJSON a) =>
KeyNameProxy s
-> Text
-> [a]
-> Properties r
-> Properties ('PropertyKey s ('TArray a) : r)
defineArrayProperty KeyNameProxy s
kn Text
description [a]
defaultValue =
forall (k :: PropertyKey) (s :: Symbol) (t :: PropertyType)
(r :: [PropertyKey]).
(k ~ 'PropertyKey s t, NotElem s r, KnownSymbol s) =>
KeyNameProxy s
-> SPropertyKey k
-> MetaData t
-> Properties r
-> Properties (k : r)
insert KeyNameProxy s
kn (forall a (s :: Symbol).
(ToJSON a, FromJSON a) =>
Proxy a -> SPropertyKey ('PropertyKey s ('TArray a))
SArray forall {k} (t :: k). Proxy t
Proxy) MetaData {[a]
Text
defaultValue :: [a]
description :: Text
description :: Text
defaultValue :: ToHsType ('TArray a)
..}
defineEnumProperty ::
(KnownSymbol s, NotElem s r, A.ToJSON a, A.FromJSON a, Eq a, Show a) =>
KeyNameProxy s ->
T.Text ->
[(a, T.Text)] ->
a ->
Properties r ->
Properties ('PropertyKey s ('TEnum a) : r)
defineEnumProperty :: forall (s :: Symbol) (r :: [PropertyKey]) a.
(KnownSymbol s, NotElem s r, ToJSON a, FromJSON a, Eq a, Show a) =>
KeyNameProxy s
-> Text
-> [(a, Text)]
-> a
-> Properties r
-> Properties ('PropertyKey s ('TEnum a) : r)
defineEnumProperty KeyNameProxy s
kn Text
description [(a, Text)]
enums a
defaultValue =
forall (k :: PropertyKey) (s :: Symbol) (t :: PropertyType)
(r :: [PropertyKey]).
(k ~ 'PropertyKey s t, NotElem s r, KnownSymbol s) =>
KeyNameProxy s
-> SPropertyKey k
-> MetaData t
-> Properties r
-> Properties (k : r)
insert KeyNameProxy s
kn (forall a (s :: Symbol).
(ToJSON a, FromJSON a, Eq a, Show a) =>
Proxy a -> SPropertyKey ('PropertyKey s ('TEnum a))
SEnum forall {k} (t :: k). Proxy t
Proxy) forall a b. (a -> b) -> a -> b
$ forall (t :: PropertyType).
(IsTEnum t ~ 'True) =>
ToHsType t -> Text -> [ToHsType t] -> [Text] -> MetaData t
EnumMetaData a
defaultValue Text
description (forall a b. (a, b) -> a
fst forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(a, Text)]
enums) (forall a b. (a, b) -> b
snd forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [(a, Text)]
enums)
toDefaultJSON :: Properties r -> [A.Pair]
toDefaultJSON :: forall (r :: [PropertyKey]). Properties r -> [Pair]
toDefaultJSON (Properties Map String SomePropertyKeyWithMetaData
p) = [String -> SomePropertyKeyWithMetaData -> Pair
toEntry String
s SomePropertyKeyWithMetaData
v | (String
s, SomePropertyKeyWithMetaData
v) <- forall k a. Map k a -> [(k, a)]
Map.toList Map String SomePropertyKeyWithMetaData
p]
where
toEntry :: String -> SomePropertyKeyWithMetaData -> A.Pair
toEntry :: String -> SomePropertyKeyWithMetaData -> Pair
toEntry String
s = \case
(SomePropertyKeyWithMetaData SPropertyKey k
SNumber MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
forall a. IsString a => String -> a
fromString String
s forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue
(SomePropertyKeyWithMetaData SPropertyKey k
SInteger MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
forall a. IsString a => String -> a
fromString String
s forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue
(SomePropertyKeyWithMetaData SPropertyKey k
SString MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
forall a. IsString a => String -> a
fromString String
s forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue
(SomePropertyKeyWithMetaData SPropertyKey k
SBoolean MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
forall a. IsString a => String -> a
fromString String
s forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue
(SomePropertyKeyWithMetaData (SObject Proxy a
_) MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
forall a. IsString a => String -> a
fromString String
s forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue
(SomePropertyKeyWithMetaData (SArray Proxy a
_) MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
forall a. IsString a => String -> a
fromString String
s forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue
(SomePropertyKeyWithMetaData (SEnum Proxy a
_) EnumMetaData {[Text]
[ToHsType t]
Text
ToHsType t
enumDescriptions :: [Text]
enumValues :: [ToHsType t]
description :: Text
defaultValue :: ToHsType t
enumDescriptions :: forall (t :: PropertyType). MetaData t -> [Text]
enumValues :: forall (t :: PropertyType). MetaData t -> [ToHsType t]
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
forall a. IsString a => String -> a
fromString String
s forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue
toVSCodeExtensionSchema :: T.Text -> Properties r -> [A.Pair]
toVSCodeExtensionSchema :: forall (r :: [PropertyKey]). Text -> Properties r -> [Pair]
toVSCodeExtensionSchema Text
prefix (Properties Map String SomePropertyKeyWithMetaData
p) =
[forall a. IsString a => String -> a
fromString (Text -> String
T.unpack Text
prefix forall a. Semigroup a => a -> a -> a
<> String
k) forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= SomePropertyKeyWithMetaData -> Value
toEntry SomePropertyKeyWithMetaData
v | (String
k, SomePropertyKeyWithMetaData
v) <- forall k a. Map k a -> [(k, a)]
Map.toList Map String SomePropertyKeyWithMetaData
p]
where
toEntry :: SomePropertyKeyWithMetaData -> A.Value
toEntry :: SomePropertyKeyWithMetaData -> Value
toEntry = \case
(SomePropertyKeyWithMetaData SPropertyKey k
SNumber MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
[Pair] -> Value
A.object
[ Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"number",
Key
"markdownDescription" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text
description,
Key
"default" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue,
Key
"scope" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"resource"
]
(SomePropertyKeyWithMetaData SPropertyKey k
SInteger MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
[Pair] -> Value
A.object
[ Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"integer",
Key
"markdownDescription" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text
description,
Key
"default" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue,
Key
"scope" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"resource"
]
(SomePropertyKeyWithMetaData SPropertyKey k
SString MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
[Pair] -> Value
A.object
[ Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"string",
Key
"markdownDescription" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text
description,
Key
"default" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue,
Key
"scope" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"resource"
]
(SomePropertyKeyWithMetaData SPropertyKey k
SBoolean MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
[Pair] -> Value
A.object
[ Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"boolean",
Key
"markdownDescription" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text
description,
Key
"default" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue,
Key
"scope" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"resource"
]
(SomePropertyKeyWithMetaData (SObject Proxy a
_) MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
[Pair] -> Value
A.object
[ Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"object",
Key
"markdownDescription" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text
description,
Key
"default" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue,
Key
"scope" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"resource"
]
(SomePropertyKeyWithMetaData (SArray Proxy a
_) MetaData {Text
ToHsType t
description :: Text
defaultValue :: ToHsType t
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
[Pair] -> Value
A.object
[ Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"array",
Key
"markdownDescription" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text
description,
Key
"default" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue,
Key
"scope" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"resource"
]
(SomePropertyKeyWithMetaData (SEnum Proxy a
_) EnumMetaData {[Text]
[ToHsType t]
Text
ToHsType t
enumDescriptions :: [Text]
enumValues :: [ToHsType t]
description :: Text
defaultValue :: ToHsType t
enumDescriptions :: forall (t :: PropertyType). MetaData t -> [Text]
enumValues :: forall (t :: PropertyType). MetaData t -> [ToHsType t]
description :: forall (t :: PropertyType). MetaData t -> Text
defaultValue :: forall (t :: PropertyType). MetaData t -> ToHsType t
..}) ->
[Pair] -> Value
A.object
[ Key
"type" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"string",
Key
"description" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text
description,
Key
"enum" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= [ToHsType t]
enumValues,
Key
"enumDescriptions" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= [Text]
enumDescriptions,
Key
"default" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= ToHsType t
defaultValue,
Key
"scope" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
A..= Text -> Value
A.String Text
"resource"
]