Skip to content

Commit fe3bed5

Browse files
committed
wip
1 parent efe8913 commit fe3bed5

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs

+25-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ import Data.List.Extra (nubOrd)
1616
import Data.String (IsString (fromString))
1717
import qualified Data.Text as T
1818
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 (..))
2121
import Ide.Types
2222
import 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+

hls-plugin-api/src/Ide/Plugin/Properties.hs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ module Ide.Plugin.Properties
2121
MetaData (..),
2222
PropertyKey (..),
2323
SPropertyKey (..),
24+
SomePropertyKeyWithMetaData (..),
2425
KeyNameProxy (..),
2526
KeyNamePath (..),
26-
Properties,
27+
Properties(..),
2728
HasProperty,
2829
HasPropertyByPath,
2930
emptyProperties,

src/Ide/Arguments.hs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ data Arguments
3434
| BiosMode BiosAction
3535
| Ghcide GhcideArguments
3636
| VSCodeExtensionSchemaMode
37+
| PluginsCustomConfigMarkdownReferenceMode
3738
| DefaultConfigurationMode
3839
| PrintLibDir
3940

0 commit comments

Comments
 (0)