5
5
6
6
module Ide.Plugin.ConfigUtils where
7
7
8
- import qualified Data.Aeson as A
9
- import qualified Data.Aeson.Types as A
10
- import Data.Default (def )
11
- import qualified Data.Dependent.Map as DMap
12
- import qualified Data.Dependent.Sum as DSum
13
- import qualified Data.HashMap.Lazy as HMap
8
+ import qualified Data.Aeson as A
9
+ import qualified Data.Aeson.Types as A
10
+ import Data.Containers.ListUtils (nubOrd )
11
+ import Data.Default (def )
12
+ import qualified Data.Dependent.Map as DMap
13
+ import qualified Data.Dependent.Sum as DSum
14
+ import qualified Data.HashMap.Lazy as HMap
14
15
import Ide.Plugin.Config
15
- import Ide.Plugin.Properties (toDefaultJSON , toVSCodeExtensionSchema )
16
+ import Ide.Plugin.Properties (toDefaultJSON ,
17
+ toVSCodeExtensionSchema )
16
18
import Ide.Types
17
19
import Language.LSP.Types
18
20
@@ -49,7 +51,7 @@ pluginsToDefaultConfig IdePlugins {..} =
49
51
-- }
50
52
-- }
51
53
-- }
52
- singlePlugin PluginDescriptor {.. } =
54
+ singlePlugin PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor { .. }, .. } =
53
55
let x = genericDefaultConfig <> dedicatedDefaultConfig
54
56
in [pId A. .= A. object x | not $ null x]
55
57
where
@@ -58,20 +60,17 @@ pluginsToDefaultConfig IdePlugins {..} =
58
60
-- Example:
59
61
--
60
62
-- {
61
- -- "globalOn": true,
62
63
-- "codeActionsOn": true,
63
64
-- "codeLensOn": true
64
65
-- }
65
66
--
66
- -- we don't generate the config section if the plugin doesn't register any of the following six methods,
67
- -- which avoids producing trivial configuration for formatters:
68
- --
69
- -- "stylish-haskell": {
70
- -- "globalOn": true
71
- -- }
72
67
genericDefaultConfig =
73
- let x = mconcat (handlersToGenericDefaultConfig <$> handlers)
74
- in [" globalOn" A. .= True | not $ null x] <> x
68
+ let x = [" diagnosticsOn" A. .= True | configHasDiagnostics] <> nubOrd (mconcat (handlersToGenericDefaultConfig <$> handlers))
69
+ in case x of
70
+ -- if the plugin has only one capability, we produce globalOn instead of the specific one;
71
+ -- otherwise we don't produce globalOn at all
72
+ [_] -> [" globalOn" A. .= True ]
73
+ _ -> x
75
74
-- Example:
76
75
--
77
76
-- {
@@ -80,7 +79,7 @@ pluginsToDefaultConfig IdePlugins {..} =
80
79
-- }
81
80
-- }
82
81
dedicatedDefaultConfig =
83
- let x = customConfigToDedicatedDefaultConfig pluginCustomConfig
82
+ let x = customConfigToDedicatedDefaultConfig configCustomConfig
84
83
in [" config" A. .= A. object x | not $ null x]
85
84
86
85
(PluginId pId) = pluginId
@@ -101,13 +100,21 @@ pluginsToDefaultConfig IdePlugins {..} =
101
100
pluginsToVSCodeExtensionSchema :: IdePlugins a -> A. Value
102
101
pluginsToVSCodeExtensionSchema IdePlugins {.. } = A. object $ mconcat $ singlePlugin <$> map snd ipMap
103
102
where
104
- singlePlugin PluginDescriptor {.. } = genericSchema <> dedicatedSchema
103
+ singlePlugin PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor { .. }, .. } = genericSchema <> dedicatedSchema
105
104
where
106
105
(PluginHandlers (DMap. toList -> handlers)) = pluginHandlers
107
106
customConfigToDedicatedSchema (CustomConfig p) = toVSCodeExtensionSchema (withIdPrefix " config." ) p
108
107
(PluginId pId) = pluginId
109
- genericSchema = withIdPrefix " globalOn" A. .= schemaEntry " plugin" : mconcat (handlersToGenericSchema <$> handlers)
110
- dedicatedSchema = customConfigToDedicatedSchema pluginCustomConfig
108
+ genericSchema =
109
+ let x =
110
+ [withIdPrefix " diagnosticsOn" A. .= schemaEntry " diagnostics" | configHasDiagnostics]
111
+ <> nubOrd (mconcat (handlersToGenericSchema <$> handlers))
112
+ in case x of
113
+ -- If the plugin has only one capability, we produce globalOn instead of the specific one;
114
+ -- otherwise we don't produce globalOn at all
115
+ [_] -> [withIdPrefix " globalOn" A. .= schemaEntry " plugin" ]
116
+ _ -> x
117
+ dedicatedSchema = customConfigToDedicatedSchema configCustomConfig
111
118
handlersToGenericSchema (IdeMethod m DSum. :=> _) = case m of
112
119
STextDocumentCodeAction -> [withIdPrefix " codeActionsOn" A. .= schemaEntry " code actions" ]
113
120
STextDocumentCodeLens -> [withIdPrefix " codeLensOn" A. .= schemaEntry " code lenses" ]
0 commit comments