From dc06c41f408e6f71a6054788df179feb260cad20 Mon Sep 17 00:00:00 2001 From: jneira Date: Mon, 27 Dec 2021 22:47:19 +0100 Subject: [PATCH] Support for aeson-2 and extra-1.7.10 --- ghcide/src/Control/Concurrent/Strict.hs | 3 ++ ghcide/src/Development/IDE/GHC/Orphans.hs | 10 +++--- hls-plugin-api/src/Ide/Compat.hs | 31 +++++++++++++------ hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs | 16 ++++------ hls-plugin-api/src/Ide/Plugin/Properties.hs | 10 +++--- hls-plugin-api/src/Ide/Types.hs | 1 - .../hls-hlint-plugin/hls-hlint-plugin.cabal | 1 - stack-8.10.6.yaml | 2 ++ stack-8.10.7.yaml | 2 ++ stack-8.6.5.yaml | 4 +-- stack-8.8.4.yaml | 3 +- stack-9.0.1.yaml | 12 ++++--- stack.yaml | 2 ++ 13 files changed, 58 insertions(+), 39 deletions(-) diff --git a/ghcide/src/Control/Concurrent/Strict.hs b/ghcide/src/Control/Concurrent/Strict.hs index 3cbfd31a20..842252d51c 100644 --- a/ghcide/src/Control/Concurrent/Strict.hs +++ b/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) diff --git a/ghcide/src/Development/IDE/GHC/Orphans.hs b/ghcide/src/Development/IDE/GHC/Orphans.hs index 1891033247..b2352d0718 100644 --- a/ghcide/src/Development/IDE/GHC/Orphans.hs +++ b/ghcide/src/Development/IDE/GHC/Orphans.hs @@ -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 diff --git a/hls-plugin-api/src/Ide/Compat.hs b/hls-plugin-api/src/Ide/Compat.hs index 6a110ed401..026d2e1de6 100644 --- a/hls-plugin-api/src/Ide/Compat.hs +++ b/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 @@ -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 diff --git a/hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs b/hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs index a5752dacd6..6f80077c26 100644 --- a/hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs +++ b/hls-plugin-api/src/Ide/Plugin/ConfigUtils.hs @@ -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 @@ -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)) @@ -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 diff --git a/hls-plugin-api/src/Ide/Plugin/Properties.hs b/hls-plugin-api/src/Ide/Plugin/Properties.hs index 6fc594ce2b..a007c58b6b 100644 --- a/hls-plugin-api/src/Ide/Plugin/Properties.hs +++ b/hls-plugin-api/src/Ide/Plugin/Properties.hs @@ -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 @@ -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 -- --------------------------------------------------------------------- @@ -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 {..}) -> @@ -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 diff --git a/hls-plugin-api/src/Ide/Types.hs b/hls-plugin-api/src/Ide/Types.hs index 4d655cee0c..5c74b05534 100644 --- a/hls-plugin-api/src/Ide/Types.hs +++ b/hls-plugin-api/src/Ide/Types.hs @@ -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 diff --git a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal index 994c50fa8b..2b21de18e2 100644 --- a/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal +++ b/plugins/hls-hlint-plugin/hls-hlint-plugin.cabal @@ -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 diff --git a/stack-8.10.6.yaml b/stack-8.10.6.yaml index 6680b2d2bb..6863e2a43c 100644 --- a/stack-8.10.6.yaml +++ b/stack-8.10.6.yaml @@ -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 diff --git a/stack-8.10.7.yaml b/stack-8.10.7.yaml index 7a0683c453..804a9ad284 100644 --- a/stack-8.10.7.yaml +++ b/stack-8.10.7.yaml @@ -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 diff --git a/stack-8.6.5.yaml b/stack-8.6.5.yaml index 4635ba7fb4..911a0cedba 100644 --- a/stack-8.6.5.yaml +++ b/stack-8.6.5.yaml @@ -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 @@ -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 @@ -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 diff --git a/stack-8.8.4.yaml b/stack-8.8.4.yaml index 6cb159ed00..5e63618afe 100644 --- a/stack-8.8.4.yaml +++ b/stack-8.8.4.yaml @@ -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 @@ -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 diff --git a/stack-9.0.1.yaml b/stack-9.0.1.yaml index 5a744f6128..ab054c81dc 100644 --- a/stack-9.0.1.yaml +++ b/stack-9.0.1.yaml @@ -1,4 +1,4 @@ -resolver: nightly-2021-12-14 +resolver: nightly-2021-12-26 packages: - . @@ -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 @@ -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 @@ -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 @@ -79,7 +84,6 @@ flags: class: false tactic: false # Dependencies fail stylishHaskell: false - brittany: false retrie: BuildExecutable: false diff --git a/stack.yaml b/stack.yaml index 7a0683c453..804a9ad284 100644 --- a/stack.yaml +++ b/stack.yaml @@ -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