@@ -15,12 +15,13 @@ import qualified Data.Dependent.Sum as DSum
1515import Data.List.Extra (nubOrd )
1616import Data.String (IsString (fromString ))
1717import qualified Data.Text as T
18+ import GHC.TypeLits (symbolVal )
1819import Ide.Plugin.Config
19- import Ide.Plugin.Properties (Properties (.. ), toDefaultJSON ,
20- toVSCodeExtensionSchema , SPropertyKey (SProperties ), MetaData (.. ), SomePropertyKeyWithMetaData (.. ))
20+ import Ide.Plugin.Properties (MetaData (.. ), Properties (.. ),
21+ toDefaultJSON ,
22+ toVSCodeExtensionSchema )
2123import Ide.Types
2224import Language.LSP.Protocol.Message
23- import GHC.TypeLits (symbolVal )
2425
2526-- Attention:
2627-- 'diagnosticsOn' will never be added into the default config or the schema,
@@ -139,24 +140,41 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
139140 withIdPrefix x = " haskell.plugin." <> pId <> " ." <> x
140141 toKey' = fromString . T. unpack . withIdPrefix
141142
143+ data PluginCustomConfig = PluginCustomConfig {
144+ pccHeader :: T. Text ,
145+ pccParams :: [PluginCustomConfigParam ]
146+ }
147+ data PluginCustomConfigParam = PluginCustomConfigParam {
148+ pccpName :: T. Text ,
149+ pccpDescription :: T. Text ,
150+ pccpIsDefault :: Bool
151+ }
152+
142153-- | Generates markdown tables for custom config
143154pluginsCustomConfigToMarkdownTables :: IdePlugins a -> T. Text
144- pluginsCustomConfigToMarkdownTables IdePlugins {.. } = T. unlines $ map singlePlugin ipMap
155+ pluginsCustomConfigToMarkdownTables IdePlugins {.. } = T. unlines
156+ $ map renderCfg
157+ $ filter (\ (PluginCustomConfig _ params) -> not $ null params)
158+ $ map pluginCfg ipMap
145159 where
146- singlePlugin PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {configCustomConfig = c}, pluginId = PluginId pId} =
147- T. unlines (pluginHeader : tableHeader : rows c)
160+ renderCfg :: PluginCustomConfig -> T. Text
161+ renderCfg (PluginCustomConfig pId pccParams) =
162+ T. unlines (pluginHeader : tableHeader : rows pccParams)
148163 where
149164 pluginHeader = " ## " <> pId
150- tableHeader = " | Property | Description | Default |"
151- rows (CustomConfig p) = toMarkdownTable p
152- toMarkdownTable :: Properties r -> [T. Text ]
153- toMarkdownTable EmptyProperties = mempty
154- toMarkdownTable (ConsProperties keyNameProxy k m xs) = renderRow (T. pack $ symbolVal keyNameProxy) (SomePropertyKeyWithMetaData k m) : toMarkdownTable xs
155- renderRow :: T. Text -> SomePropertyKeyWithMetaData -> T. Text
156- renderRow key (SomePropertyKeyWithMetaData k m) =
157- let (desc, defaultVal) = case m of
158- PropertiesMetaData _ desc _ -> (desc, False )
159- EnumMetaData _ desc _ _ -> (" " , True )
160- MetaData _ desc -> (desc, False )
161- in T. unwords [" |" , key, " |" , desc, " |" , if defaultVal then " yes" else " no" , " |" ]
162-
165+ tableHeader = " | Property | Description | Default |" <> " \n " <> " | --- | --- | --- |"
166+ rows = map renderRow
167+ renderRow (PluginCustomConfigParam name desc isDefault) =
168+ " | `" <> name <> " ` | " <> desc <> " | " <> if isDefault then " Yes" else " No" <> " |"
169+ pluginCfg :: PluginDescriptor r -> PluginCustomConfig
170+ pluginCfg PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {configCustomConfig = c}, pluginId = PluginId pId} =
171+ PluginCustomConfig pId (pccProcess c)
172+ where
173+ pccProcess :: CustomConfig -> [PluginCustomConfigParam ]
174+ pccProcess (CustomConfig EmptyProperties ) = mempty
175+ pccProcess (CustomConfig (ConsProperties keyNameProxy _k m xs)) =
176+ let (desc, isDefault) = case m of
177+ PropertiesMetaData _ desc _ -> (desc, False )
178+ EnumMetaData _ desc _ _ -> (desc, True )
179+ MetaData _ desc -> (desc, False )
180+ in PluginCustomConfigParam (T. pack $ symbolVal keyNameProxy) desc isDefault : pccProcess (CustomConfig xs)
0 commit comments