Skip to content

Commit 0781dd3

Browse files
committed
plugins' custom config params autogenerated docs — make it work
1 parent fe3bed5 commit 0781dd3

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,
@@ -139,24 +140,41 @@ pluginsToVSCodeExtensionSchema IdePlugins {..} = A.object $ mconcat $ singlePlug
139140
withIdPrefix x = "haskell.plugin." <> pId <> "." <> x
140141
toKey' = fromString . T.unpack . withIdPrefix
141142

143+
data PluginCustomConfig = PluginCustomConfig {
144+
pccHeader :: T.Text,
145+
pccParams :: [PluginCustomConfigParam]
146+
}
147+
data PluginCustomConfigParam = PluginCustomConfigParam {
148+
pccpName :: T.Text,
149+
pccpDescription :: T.Text,
150+
pccpIsDefault :: Bool
151+
}
152+
142153
-- | Generates markdown tables for custom config
143154
pluginsCustomConfigToMarkdownTables :: IdePlugins a -> T.Text
144-
pluginsCustomConfigToMarkdownTables IdePlugins {..} = T.unlines $ map singlePlugin ipMap
155+
pluginsCustomConfigToMarkdownTables IdePlugins {..} = T.unlines
156+
$ map renderCfg
157+
$ filter (\(PluginCustomConfig _ params) -> not $ null params)
158+
$ map pluginCfg ipMap
145159
where
146-
singlePlugin PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {configCustomConfig = c}, pluginId = PluginId pId} =
147-
T.unlines (pluginHeader : tableHeader : rows c)
160+
renderCfg :: PluginCustomConfig -> T.Text
161+
renderCfg (PluginCustomConfig pId pccParams) =
162+
T.unlines (pluginHeader : tableHeader : rows pccParams)
148163
where
149164
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-
165+
tableHeader = "| Property | Description | Default |" <> "\n" <> "| --- | --- | --- |"
166+
rows = map renderRow
167+
renderRow (PluginCustomConfigParam name desc isDefault) =
168+
"| `" <> name <> "` | " <> desc <> " | " <> if isDefault then "Yes" else "No" <> " |"
169+
pluginCfg :: PluginDescriptor r -> PluginCustomConfig
170+
pluginCfg PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {configCustomConfig = c}, pluginId = PluginId pId} =
171+
PluginCustomConfig pId (pccProcess c)
172+
where
173+
pccProcess :: CustomConfig -> [PluginCustomConfigParam]
174+
pccProcess (CustomConfig EmptyProperties) = mempty
175+
pccProcess (CustomConfig (ConsProperties keyNameProxy _k m xs)) =
176+
let (desc, isDefault) = case m of
177+
PropertiesMetaData _ desc _ -> (desc, False)
178+
EnumMetaData _ desc _ _ -> (desc, True)
179+
MetaData _ desc -> (desc, False)
180+
in PluginCustomConfigParam (T.pack $ symbolVal keyNameProxy) desc isDefault : pccProcess (CustomConfig xs)

src/Ide/Arguments.hs

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

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

src/Ide/Main.hs

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Data.Function ((&))
1616
import Data.List (sortOn)
1717
import Data.Text (Text)
1818
import qualified Data.Text as T
19+
import qualified Data.Text.IO as T (putStrLn)
1920
import Data.Text.Lazy.Encoding (decodeUtf8)
2021
import qualified Data.Text.Lazy.IO as LT
2122
import Development.IDE.Core.Rules hiding (Log, logToPriority)
@@ -29,7 +30,8 @@ import HIE.Bios.Types hiding (Log)
2930
import qualified HIE.Bios.Types as HieBios
3031
import Ide.Arguments
3132
import Ide.Logger as G
32-
import Ide.Plugin.ConfigUtils (pluginsToDefaultConfig,
33+
import Ide.Plugin.ConfigUtils (pluginsCustomConfigToMarkdownTables,
34+
pluginsToDefaultConfig,
3335
pluginsToVSCodeExtensionSchema)
3436
import Ide.Types (IdePlugins, PluginId (PluginId),
3537
describePlugin, ipMap, pluginId)
@@ -104,6 +106,8 @@ defaultMain recorder args idePlugins = do
104106

105107
VSCodeExtensionSchemaMode -> do
106108
LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToVSCodeExtensionSchema idePlugins
109+
PluginsCustomConfigMarkdownReferenceMode -> do
110+
T.putStrLn $ pluginsCustomConfigToMarkdownTables idePlugins
107111
DefaultConfigurationMode -> do
108112
LT.putStrLn $ decodeUtf8 $ encodePrettySorted $ pluginsToDefaultConfig idePlugins
109113
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)