@@ -16,10 +16,11 @@ import Data.List.Extra (nubOrd)
1616import Data.String (IsString (fromString ))
1717import qualified Data.Text as T
1818import Ide.Plugin.Config
19- import Ide.Plugin.Properties (toDefaultJSON ,
20- toVSCodeExtensionSchema )
19+ import Ide.Plugin.Properties (Properties ( .. ), toDefaultJSON ,
20+ toVSCodeExtensionSchema , SPropertyKey ( SProperties ), MetaData ( .. ), SomePropertyKeyWithMetaData ( .. ) )
2121import Ide.Types
2222import Language.LSP.Protocol.Message
23+ import GHC.TypeLits (symbolVal )
2324
2425-- Attention:
2526-- 'diagnosticsOn' will never be added into the default config or the schema,
@@ -139,3 +140,25 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
139140 ]
140141 withIdPrefix x = " haskell.plugin." <> pId <> " ." <> x
141142 toKey' = fromString . T. unpack . withIdPrefix
143+
144+ -- | Generates markdown tables for custom config
145+ pluginsCustomConfigToMarkdownTables :: IdePlugins a -> T. Text
146+ pluginsCustomConfigToMarkdownTables IdePlugins {.. } = T. unlines $ map singlePlugin ipMap
147+ where
148+ singlePlugin PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {configCustomConfig = c}, pluginId = PluginId pId} =
149+ T. unlines (pluginHeader : tableHeader : rows c)
150+ where
151+ pluginHeader = " ## " <> pId
152+ tableHeader = " | Property | Description | Default |"
153+ rows (CustomConfig p) = toMarkdownTable p
154+ toMarkdownTable :: Properties r -> [T. Text ]
155+ toMarkdownTable EmptyProperties = mempty
156+ toMarkdownTable (ConsProperties keyNameProxy k m xs) = renderRow (T. pack $ symbolVal keyNameProxy) (SomePropertyKeyWithMetaData k m) : toMarkdownTable xs
157+ renderRow :: T. Text -> SomePropertyKeyWithMetaData -> T. Text
158+ renderRow key (SomePropertyKeyWithMetaData k m) =
159+ let (desc, defaultVal) = case m of
160+ PropertiesMetaData _ desc _ -> (desc, False )
161+ EnumMetaData _ desc _ _ -> (" " , True )
162+ MetaData _ desc -> (desc, False )
163+ in T. unwords [" |" , key, " |" , desc, " |" , if defaultVal then " yes" else " no" , " |" ]
164+
0 commit comments