@@ -17,7 +17,12 @@ import Data.String (IsString (fromString))
17
17
import qualified Data.Text as T
18
18
import GHC.TypeLits (symbolVal )
19
19
import Ide.Plugin.Config
20
- import Ide.Plugin.Properties (MetaData (.. ), Properties (.. ),
20
+ import Ide.Plugin.Properties (KeyNameProxy , MetaData (.. ),
21
+ PluginCustomConfig (.. ),
22
+ PluginCustomConfigParam (.. ),
23
+ Properties (.. ),
24
+ SPropertyKey (.. ),
25
+ SomePropertyKeyWithMetaData (.. ),
21
26
toDefaultJSON ,
22
27
toVSCodeExtensionSchema )
23
28
import Ide.Types
@@ -142,41 +147,91 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
142
147
withIdPrefix x = " haskell.plugin." <> pId <> " ." <> x
143
148
toKey' = fromString . T. unpack . withIdPrefix
144
149
145
- data PluginCustomConfig = PluginCustomConfig {
146
- pccHeader :: T. Text ,
147
- pccParams :: [PluginCustomConfigParam ]
148
- }
149
- data PluginCustomConfigParam = PluginCustomConfigParam {
150
- pccpName :: T. Text ,
151
- pccpDescription :: T. Text ,
152
- pccpIsDefault :: Bool
153
- }
154
150
155
151
-- | Generates markdown tables for custom config
156
152
pluginsCustomConfigToMarkdownTables :: IdePlugins a -> T. Text
157
153
pluginsCustomConfigToMarkdownTables IdePlugins {.. } = T. unlines
158
154
$ map renderCfg
159
155
$ filter (\ (PluginCustomConfig _ params) -> not $ null params)
160
- $ map pluginCfg ipMap
156
+ $ map toPluginCustomConfig ipMap
161
157
where
158
+ toPluginCustomConfig :: PluginDescriptor ideState -> PluginCustomConfig
159
+ toPluginCustomConfig PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {configCustomConfig = c}, pluginId = PluginId pId} =
160
+ PluginCustomConfig { pcc'Name = pId, pcc'Params = toPluginCustomConfigParams c}
161
+ toPluginCustomConfigParams :: CustomConfig -> [PluginCustomConfigParam ]
162
+ toPluginCustomConfigParams (CustomConfig p) = toPluginCustomConfigParams' p
163
+ toPluginCustomConfigParams' :: Properties r -> [PluginCustomConfigParam ]
164
+ toPluginCustomConfigParams' EmptyProperties = []
165
+ toPluginCustomConfigParams' (ConsProperties (keyNameProxy :: KeyNameProxy s ) (k :: SPropertyKey k ) (m :: MetaData t ) xs) =
166
+ toEntry (SomePropertyKeyWithMetaData k m) : toPluginCustomConfigParams' xs
167
+ where
168
+ toEntry :: SomePropertyKeyWithMetaData -> PluginCustomConfigParam
169
+ toEntry (SomePropertyKeyWithMetaData SNumber MetaData {.. }) =
170
+ PluginCustomConfigParam {
171
+ pccp'Name = T. pack $ symbolVal keyNameProxy,
172
+ pccp'Description = description,
173
+ pccp'Default = T. pack $ show defaultValue,
174
+ pccp'EnumValues = []
175
+ }
176
+ toEntry (SomePropertyKeyWithMetaData SInteger MetaData {.. }) =
177
+ PluginCustomConfigParam {
178
+ pccp'Name = T. pack $ symbolVal keyNameProxy,
179
+ pccp'Description = description,
180
+ pccp'Default = T. pack $ show defaultValue,
181
+ pccp'EnumValues = []
182
+ }
183
+ toEntry (SomePropertyKeyWithMetaData SString MetaData {.. }) =
184
+ PluginCustomConfigParam {
185
+ pccp'Name = T. pack $ symbolVal keyNameProxy,
186
+ pccp'Description = description,
187
+ pccp'Default = T. pack $ show defaultValue,
188
+ pccp'EnumValues = []
189
+ }
190
+ toEntry (SomePropertyKeyWithMetaData SBoolean MetaData {.. }) =
191
+ PluginCustomConfigParam {
192
+ pccp'Name = T. pack $ symbolVal keyNameProxy,
193
+ pccp'Description = description,
194
+ pccp'Default = T. pack $ show defaultValue,
195
+ pccp'EnumValues = []
196
+ }
197
+ toEntry (SomePropertyKeyWithMetaData (SObject _) MetaData {.. }) =
198
+ PluginCustomConfigParam {
199
+ pccp'Name = T. pack $ symbolVal keyNameProxy,
200
+ pccp'Description = description,
201
+ pccp'Default = " TODO: nested object" , -- T.pack $ show defaultValue,
202
+ pccp'EnumValues = []
203
+ }
204
+ toEntry (SomePropertyKeyWithMetaData (SArray _) MetaData {.. }) =
205
+ PluginCustomConfigParam {
206
+ pccp'Name = T. pack $ symbolVal keyNameProxy,
207
+ pccp'Description = description,
208
+ pccp'Default = " TODO: Array values" , -- T.pack $ show defaultValue,
209
+ pccp'EnumValues = []
210
+ }
211
+ toEntry (SomePropertyKeyWithMetaData (SEnum _) EnumMetaData {.. }) =
212
+ PluginCustomConfigParam {
213
+ pccp'Name = T. pack $ symbolVal keyNameProxy,
214
+ pccp'Description = description,
215
+ pccp'Default = T. pack $ show defaultValue,
216
+ pccp'EnumValues = map (T. pack . show ) enumValues
217
+ }
218
+ toEntry (SomePropertyKeyWithMetaData SProperties PropertiesMetaData {.. }) =
219
+ PluginCustomConfigParam {
220
+ pccp'Name = T. pack $ symbolVal keyNameProxy,
221
+ pccp'Description = description,
222
+ pccp'Default = T. pack $ show defaultValue,
223
+ pccp'EnumValues = []
224
+ }
162
225
renderCfg :: PluginCustomConfig -> T. Text
163
226
renderCfg (PluginCustomConfig pId pccParams) =
164
227
T. unlines (pluginHeader : tableHeader : rows pccParams)
165
228
where
166
229
pluginHeader = " ## " <> pId
167
- tableHeader = " | Property | Description | Default |" <> " \n " <> " | --- | --- | --- |"
230
+ tableHeader =
231
+ " | Property | Description | Default | Allowed values |" <> " \n " <>
232
+ " | --- | --- | --- | --- |"
168
233
rows = map renderRow
169
- renderRow (PluginCustomConfigParam name desc isDefault) =
170
- " | `" <> name <> " ` | " <> desc <> " | " <> if isDefault then " Yes" else " No" <> " |"
171
- pluginCfg :: PluginDescriptor r -> PluginCustomConfig
172
- pluginCfg PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {configCustomConfig = c}, pluginId = PluginId pId} =
173
- PluginCustomConfig pId (pccProcess c)
174
- where
175
- pccProcess :: CustomConfig -> [PluginCustomConfigParam ]
176
- pccProcess (CustomConfig EmptyProperties ) = mempty
177
- pccProcess (CustomConfig (ConsProperties keyNameProxy _k m xs)) =
178
- let (desc, isDefault) = case m of
179
- PropertiesMetaData _ desc _ -> (desc, False )
180
- EnumMetaData _ desc _ _ -> (desc, True )
181
- MetaData _ desc -> (desc, False )
182
- in PluginCustomConfigParam (T. pack $ symbolVal keyNameProxy) desc isDefault : pccProcess (CustomConfig xs)
234
+ renderRow PluginCustomConfigParam {.. } =
235
+ " | `" <> pccp'Name <> " ` | " <> pccp'Description <> " | `" <> pccp'Default <> " ` | " <> renderEnum pccp'EnumValues <> " |"
236
+ renderEnum [] = " " -- Placeholder to prevent missing cells
237
+ renderEnum vs = " <ul> " <> (T. intercalate " " $ map (\ x -> " <li><code>" <> x <> " </code></li>" ) vs) <> " </ul>"
0 commit comments