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