@@ -15,12 +15,13 @@ import qualified Data.Dependent.Sum as DSum
15
15
import Data.List.Extra (nubOrd )
16
16
import Data.String (IsString (fromString ))
17
17
import qualified Data.Text as T
18
+ import GHC.TypeLits (symbolVal )
18
19
import 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 )
21
23
import Ide.Types
22
24
import Language.LSP.Protocol.Message
23
- import GHC.TypeLits (symbolVal )
24
25
25
26
-- Attention:
26
27
-- 'diagnosticsOn' will never be added into the default config or the schema,
@@ -141,24 +142,41 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
141
142
withIdPrefix x = " haskell.plugin." <> pId <> " ." <> x
142
143
toKey' = fromString . T. unpack . withIdPrefix
143
144
145
+ data PluginCustomConfig = PluginCustomConfig {
146
+ pccHeader :: T. Text ,
147
+ pccParams :: [PluginCustomConfigParam ]
148
+ }
149
+ data PluginCustomConfigParam = PluginCustomConfigParam {
150
+ pccpName :: T. Text ,
151
+ pccpDescription :: T. Text ,
152
+ pccpIsDefault :: Bool
153
+ }
154
+
144
155
-- | Generates markdown tables for custom config
145
156
pluginsCustomConfigToMarkdownTables :: IdePlugins a -> T. Text
146
- pluginsCustomConfigToMarkdownTables IdePlugins {.. } = T. unlines $ map singlePlugin ipMap
157
+ pluginsCustomConfigToMarkdownTables IdePlugins {.. } = T. unlines
158
+ $ map renderCfg
159
+ $ filter (\ (PluginCustomConfig _ params) -> not $ null params)
160
+ $ map pluginCfg ipMap
147
161
where
148
- singlePlugin PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {configCustomConfig = c}, pluginId = PluginId pId} =
149
- T. unlines (pluginHeader : tableHeader : rows c)
162
+ renderCfg :: PluginCustomConfig -> T. Text
163
+ renderCfg (PluginCustomConfig pId pccParams) =
164
+ T. unlines (pluginHeader : tableHeader : rows pccParams)
150
165
where
151
166
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
-
167
+ tableHeader = " | Property | Description | Default |" <> " \n " <> " | --- | --- | --- |"
168
+ rows = map renderRow
169
+ renderRow (PluginCustomConfigParam name desc isDefault) =
170
+ " | `" <> name <> " ` | " <> desc <> " | " <> if isDefault then " Yes" else " No" <> " |"
171
+ pluginCfg :: PluginDescriptor r -> PluginCustomConfig
172
+ pluginCfg PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {configCustomConfig = c}, pluginId = PluginId pId} =
173
+ PluginCustomConfig pId (pccProcess c)
174
+ where
175
+ pccProcess :: CustomConfig -> [PluginCustomConfigParam ]
176
+ pccProcess (CustomConfig EmptyProperties ) = mempty
177
+ pccProcess (CustomConfig (ConsProperties keyNameProxy _k m xs)) =
178
+ let (desc, isDefault) = case m of
179
+ PropertiesMetaData _ desc _ -> (desc, False )
180
+ EnumMetaData _ desc _ _ -> (desc, True )
181
+ MetaData _ desc -> (desc, False )
182
+ in PluginCustomConfigParam (T. pack $ symbolVal keyNameProxy) desc isDefault : pccProcess (CustomConfig xs)
0 commit comments