Skip to content

Commit

Permalink
Support for aeson-2 and extra-1.7.10
Browse files Browse the repository at this point in the history
  • Loading branch information
jneira committed Dec 29, 2021
1 parent dfe6e37 commit dc06c41
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 39 deletions.
3 changes: 3 additions & 0 deletions ghcide/src/Control/Concurrent/Strict.hs
@@ -1,8 +1,11 @@
module Control.Concurrent.Strict
(modifyVar', modifyVarIO'
,modifyVar, modifyVar_
,module Control.Concurrent.Extra
) where

import Control.Concurrent.Extra hiding (modifyVar, modifyVar',
modifyVar_)
import qualified Control.Concurrent.Extra as Extra
import Control.Exception (evaluate)
import Control.Monad (void)
Expand Down
10 changes: 5 additions & 5 deletions ghcide/src/Development/IDE/GHC/Orphans.hs
Expand Up @@ -142,15 +142,15 @@ instance ToJSON RealSrcSpan where

instance FromJSON RealSrcSpan where
parseJSON = withObject "object" $ \obj -> do
file <- fromString <$> (obj .: srcSpanFileTag)
file <- fromString <$> (obj .: toJsonKey srcSpanFileTag)
mkRealSrcSpan
<$> (mkRealSrcLoc file
<$> obj .: srcSpanStartLineTag
<*> obj .: srcSpanStartColTag
<$> obj .: toJsonKey srcSpanStartLineTag
<*> obj .: toJsonKey srcSpanStartColTag
)
<*> (mkRealSrcLoc file
<$> obj .: srcSpanEndLineTag
<*> obj .: srcSpanEndColTag
<$> obj .: toJsonKey srcSpanEndLineTag
<*> obj .: toJsonKey srcSpanEndColTag
)

instance NFData Type where
Expand Down
31 changes: 21 additions & 10 deletions hls-plugin-api/src/Ide/Compat.hs
@@ -1,14 +1,16 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE CPP #-}
module Ide.Compat where

#if MIN_VERSION_aeson(2,0,0)
import Data.Aeson.Key as A (Key)
import qualified Data.Aeson.Key as A.Key
import qualified Data.Aeson.KeyMap as Map
import Data.Aeson.Key as A (Key)
import qualified Data.Aeson.Key as A.Key
import qualified Data.Aeson.KeyMap as A
import Data.Functor.Identity (Identity (..), runIdentity)
#else
import qualified Data.HashMap.Lazy as Map
import qualified Data.HashMap.Lazy as Map
#endif
import Data.Text as T
import Data.Aeson as A (Value)
import Data.Text as T

#if MIN_VERSION_aeson(2,0,0)
toJsonKey :: T.Text -> A.Key
Expand All @@ -19,9 +21,18 @@ toJsonKey = id
#endif

#if MIN_VERSION_aeson(2,0,0)
toJsonKey :: T.Text -> A.Key
toJsonKey = A.Key.fromText
insertJson :: A.Key -> A.Value -> A.KeyMap A.Value -> A.KeyMap A.Value
insertJson = A.insert
#else
toJsonKey :: T.Text -> T.Text
toJsonKey = id
insertJson :: T.Text -> A.Value -> Map.HashMap T.Text A.Value -> Map.HashMap T.Text A.Value
insertJson = Map.insert
#endif


#if MIN_VERSION_aeson(2,0,0)
adjustJson :: (A.Value -> A.Value) -> A.Key -> A.KeyMap A.Value -> A.KeyMap A.Value
adjustJson f k = runIdentity . A.alterF (Identity . fmap f) k
#else
adjustJson :: (A.Value -> A.Value) -> T.Text -> Map.HashMap T.Text A.Value -> Map.HashMap T.Text A.Value
adjustJson = Map.adjust
#endif
16 changes: 6 additions & 10 deletions hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs
Expand Up @@ -10,12 +10,8 @@ import qualified Data.Aeson.Types as A
import Data.Default (def)
import qualified Data.Dependent.Map as DMap
import qualified Data.Dependent.Sum as DSum
import Data.Functor.Identity
import qualified Data.HashMap.Lazy as Map
import Data.List (nub)
import Data.Maybe (fromJust)
import Data.Text (Text)
import Ide.Compat (toKey)
import Ide.Compat (adjustJson, insertJson, toJsonKey)
import Ide.Plugin.Config
import Ide.Plugin.Properties (toDefaultJSON, toVSCodeExtensionSchema)
import Ide.Types
Expand All @@ -29,10 +25,10 @@ import Language.LSP.Types
-- | Generates a default 'Config', but remains only effective items
pluginsToDefaultConfig :: IdePlugins a -> A.Value
pluginsToDefaultConfig IdePlugins {..} =
A.Object $ runIdentity $
Map.alterF
( \(unsafeValueToObject . fromJust -> o) ->
Identity $ Just $ A.Object $ Map.insert "plugin" elems o -- inplace the "plugin" section with our 'elems', leaving others unchanged
A.Object $
adjustJson
( \(unsafeValueToObject -> o) ->
A.Object $ insertJson "plugin" elems o -- inplace the "plugin" section with our 'elems', leaving others unchanged
)
"haskell"
(unsafeValueToObject (A.toJSON defaultConfig))
Expand All @@ -56,7 +52,7 @@ pluginsToDefaultConfig IdePlugins {..} =
-- }
singlePlugin PluginDescriptor {pluginConfigDescriptor = ConfigDescriptor {..}, ..} =
let x = genericDefaultConfig <> dedicatedDefaultConfig
in [(toKey pId) A..= A.object x | not $ null x]
in [toJsonKey pId A..= A.object x | not $ null x]
where
(PluginHandlers (DMap.toList -> handlers)) = pluginHandlers
customConfigToDedicatedDefaultConfig (CustomConfig p) = toDefaultJSON p
Expand Down
10 changes: 5 additions & 5 deletions hls-plugin-api/src/Ide/Plugin/Properties.hs
Expand Up @@ -50,7 +50,7 @@ import Data.Proxy (Proxy (..))
import qualified Data.Text as T
import GHC.OverloadedLabels (IsLabel (..))
import GHC.TypeLits
import Ide.Types (toJsonKey)
import Ide.Compat (toJsonKey)
import Unsafe.Coerce (unsafeCoerce)

-- | Types properties may have
Expand Down Expand Up @@ -249,9 +249,9 @@ parseProperty kn k x = case k of
)
x
where
key = toJsonKey . pack $ symbolVal kn
key = toJsonKey . T.pack $ symbolVal kn
parseEither :: forall a. A.FromJSON a => Either String a
parseEither = A.parseEither (A..: keyName) x
parseEither = A.parseEither (A..: key) x

-- ---------------------------------------------------------------------

Expand Down Expand Up @@ -354,7 +354,7 @@ toDefaultJSON :: Properties r -> [A.Pair]
toDefaultJSON (Properties p) = [toEntry s v | (s, v) <- Map.toList p]
where
toEntry :: String -> SomePropertyKeyWithMetaData -> A.Pair
toEntry (toJsonKey . pack -> s) = \case
toEntry (toJsonKey . T.pack -> s) = \case
(SomePropertyKeyWithMetaData SNumber MetaData {..}) ->
s A..= defaultValue
(SomePropertyKeyWithMetaData SInteger MetaData {..}) ->
Expand All @@ -373,7 +373,7 @@ toDefaultJSON (Properties p) = [toEntry s v | (s, v) <- Map.toList p]
-- | Converts a properties definition into kv pairs as vscode schema
toVSCodeExtensionSchema :: T.Text -> Properties r -> [A.Pair]
toVSCodeExtensionSchema prefix (Properties p) =
[(toJsonKey prefix <> k) A..= toEntry v | (k, v) <- Map.toList p]
[toJsonKey (prefix <> T.pack k) A..= toEntry v | (k, v) <- Map.toList p]
where
toEntry :: SomePropertyKeyWithMetaData -> A.Value
toEntry = \case
Expand Down
1 change: 0 additions & 1 deletion hls-plugin-api/src/Ide/Types.hs
Expand Up @@ -28,7 +28,6 @@ import qualified System.Posix.Process as P (getProcessID)
import System.Posix.Signals
#endif
import Control.Lens ((^.))
import Control.Monad
import Data.Aeson hiding (defaultOptions)
import qualified Data.DList as DList
import qualified Data.Default
Expand Down
1 change: 0 additions & 1 deletion plugins/hls-hlint-plugin/hls-hlint-plugin.cabal
Expand Up @@ -92,7 +92,6 @@ library
-- This mirrors the logic in hlint.cabal for hlint-3.2
-- https://github.com/ndmitchell/hlint/blob/c7354e473c7d09213c8adc3dc94bf50a6eb4a42d/hlint.cabal#L79-L88
build-depends: hlint ^>=3.2
, extra < 1.7.10
if (!flag(ghc-lib) && impl(ghc >=8.10.1) && impl(ghc < 8.11.0))
build-depends: ghc >=8.10 && <9.0
else
Expand Down
2 changes: 2 additions & 0 deletions stack-8.10.6.yaml
Expand Up @@ -38,10 +38,12 @@ extra-deps:
- brittany-0.13.1.2@sha256:9922614f1df18c63755a37c144033988788e0769fd9c2630b64ed0dfb49462bd,8197
- bytestring-encoding-0.1.1.0@sha256:1c3b97eb6345fd7153006211c8272215cd78bb0cf440c41185290822f1e3f2c2,1738
- data-tree-print-0.1.0.2@sha256:d845e99f322df70e0c06d6743bf80336f5918d5423498528beb0593a2afc1703,1620
- extra-1.7.10
- floskell-0.10.5@sha256:77f0bc1569573d9666b10975a5357fef631d32266c071733739393ccae521dab,3803
- heapsize-0.3.0.1@sha256:0b69aa97a46d819b700ac7b145f3b5493c3565cf2c5b8298682238d405d0326e,1417
- hie-bios-0.8.0
- hiedb-0.4.1.0
- hlint-3.2.8
- implicit-hie-0.1.2.6@sha256:f50a908979a574a881f753c0f9a5224f023f438b30fdefc5b7fa01803b07a280,2998
- implicit-hie-cradle-0.3.0.5@sha256:5f5e575f549b2a9db664be7650b5c3c9226e313bddc46c79e2e83eb349f8e692,2610
- lsp-1.4.0.0
Expand Down
2 changes: 2 additions & 0 deletions stack-8.10.7.yaml
Expand Up @@ -39,10 +39,12 @@ extra-deps:
- brittany-0.13.1.2@sha256:9922614f1df18c63755a37c144033988788e0769fd9c2630b64ed0dfb49462bd,8197
- bytestring-encoding-0.1.1.0@sha256:1c3b97eb6345fd7153006211c8272215cd78bb0cf440c41185290822f1e3f2c2,1738
- data-tree-print-0.1.0.2@sha256:d845e99f322df70e0c06d6743bf80336f5918d5423498528beb0593a2afc1703,1620
- extra-1.7.10
- floskell-0.10.5@sha256:77f0bc1569573d9666b10975a5357fef631d32266c071733739393ccae521dab,3803
- heapsize-0.3.0.1@sha256:0b69aa97a46d819b700ac7b145f3b5493c3565cf2c5b8298682238d405d0326e,1417
- hie-bios-0.8.0
- hiedb-0.4.1.0
- hlint-3.2.8
- implicit-hie-0.1.2.6@sha256:f50a908979a574a881f753c0f9a5224f023f438b30fdefc5b7fa01803b07a280,2998
- implicit-hie-cradle-0.3.0.5@sha256:5f5e575f549b2a9db664be7650b5c3c9226e313bddc46c79e2e83eb349f8e692,2610
- lsp-1.4.0.0
Expand Down
4 changes: 2 additions & 2 deletions stack-8.6.5.yaml
Expand Up @@ -45,6 +45,7 @@ extra-deps:
- cabal-plan-0.6.2.0
- clock-0.7.2
- Diff-0.4.0
- extra-1.7.10
- floskell-0.10.4
- fourmolu-0.3.0.0
- fuzzy-0.1.0.1
Expand All @@ -61,7 +62,7 @@ extra-deps:
- hashable-1.3.0.0
- heapsize-0.3.0
- hie-bios-0.8.0
- hlint-3.2.3
- hlint-3.2.8
- HsYAML-0.2.1.0@rev:1
- HsYAML-aeson-0.2.0.0@rev:2
- implicit-hie-cradle-0.3.0.5
Expand Down Expand Up @@ -95,7 +96,6 @@ extra-deps:
- th-compat-0.1.2@sha256:3d55de1adc542c1a870c9ada90da2fbbe5f4e8bcd3eed545a55c3df9311b32a8,2854
- bytestring-encoding-0.1.0.0@sha256:460b49779fbf0112e8e2f1753c1ed9131eb18827600c298f4d6bb51c4e8c1c0d,1727
- hiedb-0.4.1.0
- extra-1.7.9@sha256:f1dec740f0f2025790c540732bfd52c556ec55bde4f5dfd7cf18e22bd44ff3d0,2683
- dependent-map-0.4.0.0@sha256:ca2b131046f4340a1c35d138c5a003fe4a5be96b14efc26291ed35fd08c62221,1657
- dependent-sum-0.7.1.0@sha256:5599aa89637db434431b1dd3fa7c34bc3d565ee44f0519bfbc877be1927c2531,2068
- dependent-sum-template-0.1.0.3@sha256:0bbbacdfbd3abf2a15aaf0cf2c27e5bdd159b519441fec39e1e6f2f54424adde,1682
Expand Down
3 changes: 2 additions & 1 deletion stack-8.8.4.yaml
Expand Up @@ -40,6 +40,7 @@ extra-deps:
- cabal-plan-0.6.2.0
- clock-0.7.2
- constrained-dynamic-0.1.0.0
- extra-1.7.10
- floskell-0.10.4
- fourmolu-0.3.0.0
- ghc-check-0.5.0.4
Expand All @@ -51,7 +52,7 @@ extra-deps:
- haskell-src-exts-1.21.1
- heapsize-0.3.0
- hie-bios-0.8.0
- hlint-3.2.3
- hlint-3.2.8
- HsYAML-aeson-0.2.0.0@rev:2
- hoogle-5.0.17.11
- hsimport-0.11.0
Expand Down
12 changes: 8 additions & 4 deletions stack-9.0.1.yaml
@@ -1,4 +1,4 @@
resolver: nightly-2021-12-14
resolver: nightly-2021-12-26

packages:
- .
Expand All @@ -20,7 +20,7 @@ packages:
- ./plugins/hls-retrie-plugin
- ./plugins/hls-splice-plugin
# - ./plugins/hls-tactics-plugin
# - ./plugins/hls-brittany-plugin
- ./plugins/hls-brittany-plugin
# - ./plugins/hls-stylish-haskell-plugin
- ./plugins/hls-floskell-plugin
- ./plugins/hls-fourmolu-plugin
Expand All @@ -30,10 +30,14 @@ packages:
- ./plugins/hls-alternate-number-format-plugin

extra-deps:
- aeson-2.0.2.0
- brittany-0.14.0.0
- butcher-1.3.3.2
- bytestring-encoding-0.1.1.0
- data-tree-print-0.1.0.2
- dependent-map-0.4.0.0
- dependent-sum-0.7.1.0
- extra-1.7.9 # for ghcide, https://github.com/haskell/haskell-language-server/pull/2131
- extra-1.7.10
- hspec-2.7.10 # for hls-test-utils
- hspec-core-2.7.10 # for hls-test-utils
- some-1.0.2 # for dependent-sum, https://github.com/obsidiansystems/dependent-sum/issues/66
Expand All @@ -44,6 +48,7 @@ extra-deps:
- implicit-hie-0.1.2.6
- implicit-hie-cradle-0.3.0.5
- monad-dijkstra-0.1.1.3
- multistate-0.8.0.3
- retrie-1.1.0.0
- lsp-1.4.0.0
- lsp-test-0.14.0.2
Expand Down Expand Up @@ -79,7 +84,6 @@ flags:
class: false
tactic: false # Dependencies fail
stylishHaskell: false
brittany: false

retrie:
BuildExecutable: false
Expand Down
2 changes: 2 additions & 0 deletions stack.yaml
Expand Up @@ -39,10 +39,12 @@ extra-deps:
- brittany-0.13.1.2@sha256:9922614f1df18c63755a37c144033988788e0769fd9c2630b64ed0dfb49462bd,8197
- bytestring-encoding-0.1.1.0@sha256:1c3b97eb6345fd7153006211c8272215cd78bb0cf440c41185290822f1e3f2c2,1738
- data-tree-print-0.1.0.2@sha256:d845e99f322df70e0c06d6743bf80336f5918d5423498528beb0593a2afc1703,1620
- extra-1.7.10
- floskell-0.10.5@sha256:77f0bc1569573d9666b10975a5357fef631d32266c071733739393ccae521dab,3803
- heapsize-0.3.0.1@sha256:0b69aa97a46d819b700ac7b145f3b5493c3565cf2c5b8298682238d405d0326e,1417
- hie-bios-0.8.0
- hiedb-0.4.1.0
- hlint-3.2.8
- implicit-hie-0.1.2.6@sha256:f50a908979a574a881f753c0f9a5224f023f438b30fdefc5b7fa01803b07a280,2998
- implicit-hie-cradle-0.3.0.5@sha256:5f5e575f549b2a9db664be7650b5c3c9226e313bddc46c79e2e83eb349f8e692,2610
- lsp-1.4.0.0
Expand Down

0 comments on commit dc06c41

Please sign in to comment.