From 3906a1a8be457fc0bb1bf2e8297b93c372d78557 Mon Sep 17 00:00:00 2001 From: Junyoung/Clare Jang Date: Sun, 12 Dec 2021 16:04:19 -0500 Subject: [PATCH 1/2] Bump class plugin to work with GHC 9.0.1 --- .github/workflows/test.yml | 2 +- cabal-ghc901.project | 2 +- configuration-ghc-901.nix | 2 -- flake.nix | 2 +- plugins/hls-class-plugin/src/Ide/Plugin/Class.hs | 13 ++++++++++--- stack-9.0.1.yaml | 2 +- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a42991ef9d..2a1670149d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -179,7 +179,7 @@ jobs: name: Test hls-brittany-plugin run: cabal test hls-brittany-plugin --test-options="$TEST_OPTS" || cabal test hls-brittany-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-brittany-plugin --test-options="$TEST_OPTS" - - if: matrix.test && matrix.ghc != '9.0.1' + - if: matrix.test name: Test hls-class-plugin run: cabal test hls-class-plugin --test-options="$TEST_OPTS" || cabal test hls-class-plugin --test-options="$TEST_OPTS" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-class-plugin --test-options="$TEST_OPTS" diff --git a/cabal-ghc901.project b/cabal-ghc901.project index 18e63db8f3..6a4d747f47 100644 --- a/cabal-ghc901.project +++ b/cabal-ghc901.project @@ -41,7 +41,7 @@ index-state: 2021-11-29T08:11:07Z constraints: -- These plugins don't work on GHC9 yet - haskell-language-server +ignore-plugins-ghc-bounds -brittany -class -stylishhaskell -tactic, + haskell-language-server +ignore-plugins-ghc-bounds -brittany -stylishhaskell -tactic, ghc-lib-parser ^>= 9.0 -- although we are not building all plugins cabal solver phase is run for all packages diff --git a/configuration-ghc-901.nix b/configuration-ghc-901.nix index e8e977cd03..b5c00b4ef8 100644 --- a/configuration-ghc-901.nix +++ b/configuration-ghc-901.nix @@ -7,7 +7,6 @@ let "hls-brittany-plugin" "hls-stylish-haskell-plugin" "hls-fourmolu-plugin" - "hls-class-plugin" ]; hpkgsOverride = hself: hsuper: @@ -27,7 +26,6 @@ let hself.callCabal2nixWithOptions "haskell-language-server" ./. (pkgs.lib.concatStringsSep " " [ "-f-brittany" - "-f-class" "-f-fourmolu" "-f-stylishhaskell" "-f-tactic" diff --git a/flake.nix b/flake.nix index bb3aedc62b..d1b79ecdfe 100644 --- a/flake.nix +++ b/flake.nix @@ -70,7 +70,7 @@ with haskell.lib; { # Patches don't apply github = overrideCabal hsuper.github (drv: { patches = []; }); - # We need an older version + # We need an older version hiedb = hself.hiedb_0_4_1_0; implicit-hie-cradle = hself.callCabal2nix "implicit-hie-cradle" diff --git a/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs b/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs index fa81a76c07..215a15ff8d 100644 --- a/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs +++ b/plugins/hls-class-plugin/src/Ide/Plugin/Class.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE OverloadedStrings #-} @@ -32,6 +33,7 @@ import Ide.Types import Language.Haskell.GHC.ExactPrint import Language.Haskell.GHC.ExactPrint.Parsers (parseDecl) import Language.Haskell.GHC.ExactPrint.Types hiding (GhcPs, Parens) +import Language.Haskell.GHC.ExactPrint.Utils (rs) import Language.LSP.Server import Language.LSP.Types import qualified Language.LSP.Types.Lens as J @@ -85,20 +87,19 @@ addMethodPlaceholders state AddMinimalMethodsParams{..} = do Right (ann, d) -> Just (setPrecedingLines d 1 indent ann, d) Left _ -> Nothing - addMethodDecls :: ParsedSource -> [LHsDecl GhcPs] -> Transform (Located (HsModule GhcPs)) addMethodDecls ps mDecls = do d <- findInstDecl ps newSpan <- uniqueSrcSpanT let annKey = mkAnnKey d - newAnnKey = AnnKey newSpan (CN "HsValBinds") + newAnnKey = AnnKey (rs newSpan) (CN "HsValBinds") addWhere mkds@(Map.lookup annKey -> Just ann) = Map.insert newAnnKey ann2 mkds2 where ann1 = ann { annsDP = annsDP ann ++ [(G AnnWhere, DP (0, 1))] , annCapturedSpan = Just newAnnKey - , annSortKey = Just (fmap getLoc mDecls) + , annSortKey = Just (fmap (rs . getLoc) mDecls) } mkds2 = Map.insert annKey ann1 mkds ann2 = annNone @@ -168,9 +169,15 @@ codeAction state plId (CodeActionParams _ _ docId _ context) = liftIO $ fmap (fr pure $ head . head $ pointCommand hf (fromJust (fromCurrentRange pmap range) ^. J.start & J.character -~ 1) +#if !MIN_VERSION_ghc(9,0,0) ( (Map.keys . Map.filter isClassNodeIdentifier . nodeIdentifiers . nodeInfo) <=< nodeChildren ) +#else + ( (Map.keys . Map.filter isClassNodeIdentifier . sourcedNodeIdents . sourcedNodeInfo) + <=< nodeChildren + ) +#endif findClassFromIdentifier docPath (Right name) = do (hscEnv -> hscenv, _) <- MaybeT . runAction "classplugin" state $ useWithStale GhcSessionDeps docPath diff --git a/stack-9.0.1.yaml b/stack-9.0.1.yaml index 9320543613..9b8c62d6ab 100644 --- a/stack-9.0.1.yaml +++ b/stack-9.0.1.yaml @@ -9,7 +9,7 @@ packages: - ./hls-test-utils - ./shake-bench - ./plugins/hls-call-hierarchy-plugin - # - ./plugins/hls-class-plugin + - ./plugins/hls-class-plugin - ./plugins/hls-haddock-comments-plugin - ./plugins/hls-eval-plugin - ./plugins/hls-explicit-imports-plugin From 4b310c8f8668f161957c80944788fc9ccc395b4e Mon Sep 17 00:00:00 2001 From: "Junyoung \"Clare\" Jang" Date: Mon, 13 Dec 2021 05:53:19 -0500 Subject: [PATCH 2/2] Update class flag in hls cabal file --- haskell-language-server.cabal | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/haskell-language-server.cabal b/haskell-language-server.cabal index 1ca23e09dc..def82048f4 100644 --- a/haskell-language-server.cabal +++ b/haskell-language-server.cabal @@ -206,7 +206,7 @@ common example-plugins Ide.Plugin.Example2 common class - if flag(class) && (impl(ghc < 9.0.1) || flag(ignore-plugins-ghc-bounds)) + if flag(class) && (impl(ghc < 9.2.1) || flag(ignore-plugins-ghc-bounds)) build-depends: hls-class-plugin ^>=1.0.0.1 cpp-options: -Dclass