@@ -16,10 +16,11 @@ import Data.List.Extra (nubOrd)
16
16
import Data.String (IsString (fromString ))
17
17
import qualified Data.Text as T
18
18
import Ide.Plugin.Config
19
- import Ide.Plugin.Properties (toDefaultJSON ,
20
- toVSCodeExtensionSchema )
19
+ import Ide.Plugin.Properties (Properties ( .. ), toDefaultJSON ,
20
+ toVSCodeExtensionSchema , SPropertyKey ( SProperties ), MetaData ( .. ), SomePropertyKeyWithMetaData ( .. ) )
21
21
import Ide.Types
22
22
import Language.LSP.Protocol.Message
23
+ import GHC.TypeLits (symbolVal )
23
24
24
25
-- Attention:
25
26
-- 'diagnosticsOn' will never be added into the default config or the schema,
@@ -139,3 +140,25 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
139
140
]
140
141
withIdPrefix x = " haskell.plugin." <> pId <> " ." <> x
141
142
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