Skip to content

Commit 182bad5

Browse files
committed
plugins' custom config params autogenerated docs — make it work
1 parent 7df3522 commit 182bad5

File tree

5 files changed

+121
-20
lines changed

5 files changed

+121
-20
lines changed

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

+37-19
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import qualified Data.Dependent.Sum as DSum
1515
import Data.List.Extra (nubOrd)
1616
import Data.String (IsString (fromString))
1717
import qualified Data.Text as T
18+
import GHC.TypeLits (symbolVal)
1819
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)
2123
import Ide.Types
2224
import Language.LSP.Protocol.Message
23-
import GHC.TypeLits (symbolVal)
2425

2526
-- Attention:
2627
-- 'diagnosticsOn' will never be added into the default config or the schema,
@@ -141,24 +142,41 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
141142
withIdPrefix x = "haskell.plugin." <> pId <> "." <> x
142143
toKey' = fromString . T.unpack . withIdPrefix
143144

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+
144155
-- | Generates markdown tables for custom config
145156
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
147161
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)
150165
where
151166
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)

src/Ide/Arguments.hs

+4
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ getArguments exeName plugins = execParser opts
7070
<|> hsubparser
7171
( command "vscode-extension-schema" extensionSchemaCommand
7272
<> command "generate-default-config" generateDefaultConfigCommand
73+
<> command "plugins-custom-config-markdown-reference" pluginsCustomConfigMarkdownReferenceCommand
7374
)
7475
<|> listPluginsParser
7576
<|> BiosMode <$> biosParser
@@ -87,6 +88,9 @@ getArguments exeName plugins = execParser opts
8788
generateDefaultConfigCommand =
8889
info (pure DefaultConfigurationMode)
8990
(fullDesc <> progDesc "Print config supported by the server with default values")
91+
pluginsCustomConfigMarkdownReferenceCommand =
92+
info (pure PluginsCustomConfigMarkdownReferenceMode)
93+
(fullDesc <> progDesc "Print markdown reference for plugins custom config")
9094

9195
printVersionParser :: String -> Parser PrintVersion
9296
printVersionParser exeName =

src/Ide/Main.hs

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Data.Function ((&))
1515
import Data.List (sortOn)
1616
import Data.Text (Text)
1717
import qualified Data.Text as T
18+
import qualified Data.Text.IO as T (putStrLn)
1819
import Data.Text.Lazy.Encoding (decodeUtf8)
1920
import qualified Data.Text.Lazy.IO as LT
2021
import Development.IDE.Core.Rules hiding (Log)
@@ -28,7 +29,8 @@ import HIE.Bios.Types hiding (Log)
2829
import qualified HIE.Bios.Types as HieBios
2930
import Ide.Arguments
3031
import Ide.Logger as G
31-
import Ide.Plugin.ConfigUtils (pluginsToDefaultConfig,
32+
import Ide.Plugin.ConfigUtils (pluginsCustomConfigToMarkdownTables,
33+
pluginsToDefaultConfig,
3234
pluginsToVSCodeExtensionSchema)
3335
import Ide.Types (IdePlugins, PluginId (PluginId),
3436
describePlugin, ipMap, pluginId)
@@ -103,6 +105,8 @@ defaultMain recorder args idePlugins = do
103105

104106
VSCodeExtensionSchemaMode -> do
105107
LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToVSCodeExtensionSchema idePlugins
108+
PluginsCustomConfigMarkdownReferenceMode -> do
109+
T.putStrLn $ pluginsCustomConfigToMarkdownTables idePlugins
106110
DefaultConfigurationMode -> do
107111
LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToDefaultConfig idePlugins
108112
PrintLibDir -> do

test/functional/ConfigSchema.hs

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ tests = testGroup "generate schema"
3131
, goldenGitDiff "generate-default-config" (defaultConfigFp ghcVersion) $ do
3232
stdout <- readProcess hlsExeCommand ["generate-default-config"] ""
3333
pure $ BS.pack stdout
34+
, goldenGitDiff "plugins-custom-config-markdown-reference" (markdownReferenceFp ghcVersion) $ do
35+
stdout <- readProcess hlsExeCommand ["plugins-custom-config-markdown-reference"] ""
36+
pure $ BS.pack stdout
3437
]
3538

3639
vscodeSchemaFp :: GhcVersion -> FilePath
@@ -39,11 +42,17 @@ vscodeSchemaFp ghcVer = "test" </> "testdata" </> "schema" </> prettyGhcVersion
3942
defaultConfigFp :: GhcVersion -> FilePath
4043
defaultConfigFp ghcVer = "test" </> "testdata" </> "schema" </> prettyGhcVersion ghcVer </> generateDefaultConfigJson
4144

45+
markdownReferenceFp :: GhcVersion -> FilePath
46+
markdownReferenceFp ghcVer = "test" </> "testdata" </> "schema" </> prettyGhcVersion ghcVer </> markdownReferenceMd
47+
4248
vscodeSchemaJson :: FilePath
4349
vscodeSchemaJson = "vscode-extension-schema.golden.json"
4450

4551
generateDefaultConfigJson :: FilePath
4652
generateDefaultConfigJson = "default-config.golden.json"
4753

54+
markdownReferenceMd :: FilePath
55+
markdownReferenceMd = "markdown-reference.md"
56+
4857
prettyGhcVersion :: GhcVersion -> String
4958
prettyGhcVersion ghcVer = map toLower (show ghcVer)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## ghcide-completions
2+
| Property | Description | Default |
3+
| --- | --- | --- |
4+
| autoExtendOn | Extends the import list automatically when completing a out-of-scope identifier | No |
5+
| snippetsOn | Inserts snippets when using code completions | No |
6+
7+
## semanticTokens
8+
| Property | Description | Default |
9+
| --- | --- | --- |
10+
| variableToken | LSP semantic token type to use for variables | Yes
11+
| functionToken | LSP semantic token type to use for functions | Yes
12+
| dataConstructorToken | LSP semantic token type to use for data constructors | Yes
13+
| typeVariableToken | LSP semantic token type to use for type variables | Yes
14+
| classMethodToken | LSP semantic token type to use for typeclass methods | Yes
15+
| patternSynonymToken | LSP semantic token type to use for pattern synonyms | Yes
16+
| typeConstructorToken | LSP semantic token type to use for type constructors | Yes
17+
| classToken | LSP semantic token type to use for typeclasses | Yes
18+
| typeSynonymToken | LSP semantic token type to use for type synonyms | Yes
19+
| typeFamilyToken | LSP semantic token type to use for type families | Yes
20+
| recordFieldToken | LSP semantic token type to use for record fields | Yes
21+
| operatorToken | LSP semantic token type to use for operators | Yes
22+
| moduleToken | LSP semantic token type to use for modules | Yes
23+
24+
## fourmolu
25+
| Property | Description | Default |
26+
| --- | --- | --- |
27+
| external | Call out to an external "fourmolu" executable, rather than using the bundled library. | No |
28+
| path | Set path to executable (for "external" mode). | No |
29+
30+
## cabal-gild
31+
| Property | Description | Default |
32+
| --- | --- | --- |
33+
| path | Set path to 'cabal-gild' executable | No |
34+
35+
## hlint
36+
| Property | Description | Default |
37+
| --- | --- | --- |
38+
| flags | Flags used by hlint | No |
39+
40+
## ormolu
41+
| Property | Description | Default |
42+
| --- | --- | --- |
43+
| external | Call out to an external "ormolu" executable, rather than using the bundled library | No |
44+
45+
## ghcide-type-lenses
46+
| Property | Description | Default |
47+
| --- | --- | --- |
48+
| mode | Control how type lenses are shown | Yes
49+
50+
## cabal-fmt
51+
| Property | Description | Default |
52+
| --- | --- | --- |
53+
| path | Set path to 'cabal-fmt' executable | No |
54+
55+
## eval
56+
| Property | Description | Default |
57+
| --- | --- | --- |
58+
| exception | Enable marking exceptions with `*** Exception:` similarly to doctest and GHCi. | No |
59+
| diff | Enable the diff output (WAS/NOW) of eval lenses | No |
60+
61+
## rename
62+
| Property | Description | Default |
63+
| --- | --- | --- |
64+
| crossModule | Enable experimental cross-module renaming | No |
65+
66+

0 commit comments

Comments
 (0)