5
5
6
6
module Ide.Plugin.ConfigUtils where
7
7
8
+ import Control.Lens ((&) , (?~) , ix , at )
8
9
import qualified Data.Aeson as A
9
10
import qualified Data.Aeson.Types as A
11
+ import Data.Aeson.Lens (_Object )
10
12
import Data.Default (def )
11
13
import qualified Data.Dependent.Map as DMap
12
14
import qualified Data.Dependent.Sum as DSum
13
15
import Data.List (nub )
14
16
import Data.String (IsString (fromString ))
15
17
import qualified Data.Text as T
16
- import Ide.Compat (adjustJson )
17
18
import Ide.Plugin.Config
18
19
import Ide.Plugin.Properties (toDefaultJSON , toVSCodeExtensionSchema )
19
20
import Ide.Types
@@ -27,17 +28,12 @@ import Language.LSP.Types
27
28
-- | Generates a default 'Config', but remains only effective items
28
29
pluginsToDefaultConfig :: IdePlugins a -> A. Value
29
30
pluginsToDefaultConfig IdePlugins {.. } =
30
- A. Object $
31
- adjustJson
32
- ( \ (unsafeValueToObject -> obj) ->
33
- A. Object $ obj <> unsafeValueToObject (A. object [" plugin" A. .= elems]) -- inplace the "plugin" section with our 'elems', leaving others unchanged
34
- )
35
- " haskell"
36
- (unsafeValueToObject (A. toJSON defaultConfig))
31
+ -- Use 'ix' to look at all the "haskell" keys in the outer value (since we're not
32
+ -- setting it if missing), then we use '_Object' and 'at' to get at the "plugin" key
33
+ -- and actually set it.
34
+ A. toJSON defaultConfig & ix " haskell" . _Object . at " plugin" ?~ elems
37
35
where
38
36
defaultConfig@ Config {} = def
39
- unsafeValueToObject (A. Object o) = o
40
- unsafeValueToObject _ = error " impossible"
41
37
elems = A. object $ mconcat $ singlePlugin <$> map snd ipMap
42
38
-- Splice genericDefaultConfig and dedicatedDefaultConfig
43
39
-- Example:
0 commit comments