@@ -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,
@@ -137,3 +138,25 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
137138 ]
138139 withIdPrefix x = " haskell.plugin." <> pId <> " ." <> x
139140 toKey' = fromString . T. unpack . withIdPrefix
141+
142+ -- | Generates markdown tables for custom config
143+ pluginsCustomConfigToMarkdownTables :: IdePlugins a -> T. Text
144+ pluginsCustomConfigToMarkdownTables IdePlugins {.. } = T. unlines $ map singlePlugin ipMap
145+ where
146+ singlePlugin PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {configCustomConfig = c}, pluginId = PluginId pId} =
147+ T. unlines (pluginHeader : tableHeader : rows c)
148+ where
149+ 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+
0 commit comments