Skip to content

Commit 9146431

Browse files
authored
Merge pull request haskell#62 from michaelpj/mpj/brittany-lens
Avoid CPP by using lens-aeson
2 parents e49c437 + 2d15a5c commit 9146431

File tree

3 files changed

+7
-31
lines changed

3 files changed

+7
-31
lines changed

hls-plugin-api/hls-plugin-api.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ source-repository head
2626

2727
library
2828
exposed-modules:
29-
Ide.Compat
3029
Ide.Logger
3130
Ide.Plugin.Config
3231
Ide.Plugin.ConfigUtils
@@ -50,6 +49,7 @@ library
5049
, hls-graph >=1.4 && < 1.6
5150
, hslogger
5251
, lens
52+
, lens-aeson
5353
, lsp ^>=1.4.0.0
5454
, opentelemetry
5555
, optparse-applicative

hls-plugin-api/src/Ide/Compat.hs

Lines changed: 0 additions & 20 deletions
This file was deleted.

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55

66
module Ide.Plugin.ConfigUtils where
77

8+
import Control.Lens ((&), (?~), ix, at)
89
import qualified Data.Aeson as A
910
import qualified Data.Aeson.Types as A
11+
import Data.Aeson.Lens (_Object)
1012
import Data.Default (def)
1113
import qualified Data.Dependent.Map as DMap
1214
import qualified Data.Dependent.Sum as DSum
1315
import Data.List (nub)
1416
import Data.String (IsString (fromString))
1517
import qualified Data.Text as T
16-
import Ide.Compat (adjustJson)
1718
import Ide.Plugin.Config
1819
import Ide.Plugin.Properties (toDefaultJSON, toVSCodeExtensionSchema)
1920
import Ide.Types
@@ -27,17 +28,12 @@ import Language.LSP.Types
2728
-- | Generates a default 'Config', but remains only effective items
2829
pluginsToDefaultConfig :: IdePlugins a -> A.Value
2930
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
3735
where
3836
defaultConfig@Config {} = def
39-
unsafeValueToObject (A.Object o) = o
40-
unsafeValueToObject _ = error "impossible"
4137
elems = A.object $ mconcat $ singlePlugin <$> map snd ipMap
4238
-- Splice genericDefaultConfig and dedicatedDefaultConfig
4339
-- Example:

0 commit comments

Comments
 (0)