@@ -17,12 +17,18 @@ import Ide.Plugin.Properties (toDefaultJSON, toVSCodeExtensionSchema)
17
17
import Ide.Types
18
18
import Language.LSP.Types
19
19
20
+ -- Attention:
21
+ -- 'diagnosticsOn' will never be added into the default config or the schema,
22
+ -- since diagnostics emit in arbitrary shake rules -- we don't know
23
+ -- whether a plugin is capable of producing diagnostics.
24
+
25
+ -- | Generates a defalut 'Config', but remains only effective items
20
26
pluginsToDefaultConfig :: IdePlugins a -> A. Value
21
27
pluginsToDefaultConfig IdePlugins {.. } =
22
28
A. Object $
23
29
HMap. adjust
24
30
( \ (unsafeValueToObject -> o) ->
25
- A. Object $ HMap. insert " plugin" elems o
31
+ A. Object $ HMap. insert " plugin" elems o -- inplace the "plugin" section with our 'elems', leaving others unchanged
26
32
)
27
33
" haskell"
28
34
(unsafeValueToObject (A. toJSON defaultConfig))
@@ -31,25 +37,56 @@ pluginsToDefaultConfig IdePlugins {..} =
31
37
unsafeValueToObject (A. Object o) = o
32
38
unsafeValueToObject _ = error " impossible"
33
39
elems = A. object $ mconcat $ singlePlugin <$> Map. elems ipMap
40
+ -- Splice genericDefaultConfig and dedicatedDefaultConfig
41
+ -- Example:
42
+ --
43
+ -- {
44
+ -- "plugin-id": {
45
+ -- "globalOn": true,
46
+ -- "codeActionsOn": true,
47
+ -- "codeLensOn": true,
48
+ -- "config": {
49
+ -- "property1": "foo"
50
+ -- }
51
+ -- }
52
+ -- }
34
53
singlePlugin PluginDescriptor {.. } =
35
- let x = geenericDefaultConfig <> dedicatedDefaultConfig
54
+ let x = genericDefaultConfig <> dedicatedDefaultConfig
36
55
in [pId A. .= A. object x | not $ null x]
37
56
where
38
57
(PluginHandlers (DMap. toList -> handlers)) = pluginHandlers
39
58
customConfigToDedicatedDefaultConfig (CustomConfig p) = toDefaultJSON p
59
+ -- Example:
60
+ --
61
+ -- {
62
+ -- "globalOn": true,
63
+ -- "codeActionsOn": true,
64
+ -- "codeLensOn": true
65
+ -- }
66
+ --
40
67
-- we don't generate the config section if the plugin doesn't register any of the following six methods,
41
- -- which avoids producing redundant configuration for formatters:
68
+ -- which avoids producing trivial configuration for formatters:
42
69
--
43
70
-- "stylish-haskell": {
44
71
-- "globalOn": true
45
72
-- }
46
- geenericDefaultConfig =
73
+ genericDefaultConfig =
47
74
let x = mconcat (handlersToGenericDefaultConfig <$> handlers)
48
75
in [" globalOn" A. .= True | not $ null x] <> x
76
+ -- Example:
77
+ --
78
+ -- {
79
+ -- "config": {
80
+ -- "property1": "foo"
81
+ -- }
82
+ -- }
49
83
dedicatedDefaultConfig =
50
84
let x = customConfigToDedicatedDefaultConfig pluginCustomConfig
51
85
in [" config" A. .= A. object x | not $ null x]
86
+
52
87
(PluginId pId) = pluginId
88
+
89
+ -- This function captures ide methods registered by the plugin, and then converts it to kv pairs
53
90
handlersToGenericDefaultConfig :: DSum. DSum IdeMethod f -> [A. Pair ]
54
91
handlersToGenericDefaultConfig (IdeMethod m DSum. :=> _) = case m of
55
92
STextDocumentCodeAction -> [" codeActionsOn" A. .= True ]
@@ -60,6 +97,8 @@ pluginsToDefaultConfig IdePlugins {..} =
60
97
STextDocumentCompletion -> [" completionOn" A. .= True ]
61
98
_ -> []
62
99
100
+ -- | Generates json schema used in haskell vscode extension
101
+ -- Similar to 'pluginsToDefaultConfig' but simpler, since schema has a flatten structure
63
102
pluginsToVSCodeExtensionSchema :: IdePlugins a -> A. Value
64
103
pluginsToVSCodeExtensionSchema IdePlugins {.. } = A. object $ mconcat $ singlePlugin <$> Map. elems ipMap
65
104
where
0 commit comments