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