From 282387f6cbd4be07041c5402c34d72945f1357ed Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Sat, 3 Jul 2021 22:00:28 +0800 Subject: [PATCH 01/11] Eval plugin: support ghc 9.0.1 --- cabal-ghc901.project | 2 +- .../src/Ide/Plugin/Eval/CodeLens.hs | 59 ++++++++++++------- stack-9.0.1.yaml | 1 - 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/cabal-ghc901.project b/cabal-ghc901.project index c6242f007a..52215d3521 100644 --- a/cabal-ghc901.project +++ b/cabal-ghc901.project @@ -81,7 +81,7 @@ index-state: 2021-06-30T16:00:00Z constraints: -- These plugins doesn't work on GHC9 yet - haskell-language-server -brittany -class -eval -fourmolu -ormolu -splice -stylishhaskell -tactic -refineImports + haskell-language-server -brittany -class -fourmolu -ormolu -splice -stylishhaskell -tactic -refineImports allow-newer: diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs index c6b418372a..5e920cdb09 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs @@ -152,23 +152,29 @@ import System.IO (hClose) import UnliftIO.Temporary (withSystemTempFile) import Util (OverridingBool (Never)) - +import IfaceSyn (showToHeader) +import PprTyThing (pprTyThingInContext, pprTypeForUser) #if MIN_VERSION_ghc(9,0,0) -import GHC.Parser.Annotation (ApiAnns (apiAnnComments)) +import GHC.Parser.Annotation (ApiAnns (apiAnnRogueComments)) +import GHC.Parser.Lexer (mkParserFlags) +import GHC.Driver.Ways (hostFullWays, + wayGeneralFlags, + wayUnsetGeneralFlags) +import GHC.Types.SrcLoc (UnhelpfulSpanReason(UnhelpfulInteractive)) #else import GhcPlugins (interpWays, updateWays, wayGeneralFlags, wayUnsetGeneralFlags) -import IfaceSyn (showToHeader) -import PprTyThing (pprTyThingInContext) #endif #if MIN_VERSION_ghc(9,0,0) pattern RealSrcSpanAlready :: SrcLoc.RealSrcSpan -> SrcLoc.RealSrcSpan pattern RealSrcSpanAlready x = x +apiAnnComments' :: SrcLoc.ApiAnns -> [SrcLoc.RealLocated AnnotationComment] +apiAnnComments' = apiAnnRogueComments #else -apiAnnComments :: SrcLoc.ApiAnns -> Map.Map SrcSpan [SrcLoc.Located AnnotationComment] -apiAnnComments = snd +apiAnnComments' :: SrcLoc.ApiAnns -> [SrcLoc.Located AnnotationComment] +apiAnnComments' = concat . Map.elems . snd pattern RealSrcSpanAlready :: SrcLoc.RealSrcSpan -> SrcSpan pattern RealSrcSpanAlready x = SrcLoc.RealSrcSpan x @@ -190,9 +196,9 @@ codeLens st plId CodeLensParams{_textDocument} = isLHS = isLiterate fp dbg "fp" fp (ParsedModule{..}, posMap) <- liftIO $ - runAction "parsed" st $ useWithStale_ GetParsedModuleWithComments nfp - let comments = foldMap - ( foldMap $ \case + runAction "eval.GetParsedModuleWithComments" st $ useWithStale_ GetParsedModuleWithComments nfp + let comments = + foldMap (\case L (RealSrcSpanAlready real) bdy | unpackFS (srcSpanFile real) == fromNormalizedFilePath nfp @@ -210,16 +216,15 @@ codeLens st plId CodeLensParams{_textDocument} = _ -> mempty _ -> mempty ) - $ apiAnnComments pm_annotations + $ apiAnnComments' pm_annotations dbg "excluded comments" $ show $ DL.toList $ - foldMap - (foldMap $ \(L a b) -> + foldMap (\(L a b) -> case b of AnnLineComment{} -> mempty AnnBlockComment{} -> mempty _ -> DL.singleton (a, b) ) - $ apiAnnComments pm_annotations + $ apiAnnComments' pm_annotations dbg "comments" $ show comments -- Extract tests from source code @@ -546,7 +551,7 @@ evals (st, fp) df stmts = do eans <- liftIO $ try @GhcException $ parseDynamicFlagsCmdLine ndf - (map (L $ UnhelpfulSpan "") flags) + (map (L $ UnhelpfulSpan unhelpfulReason) flags) dbg "parsed flags" $ eans <&> (_1 %~ showDynFlags >>> _3 %~ map warnMsg) case eans of @@ -572,7 +577,7 @@ evals (st, fp) df stmts = do Just (cmd, arg) <- parseGhciLikeCmd $ T.pack stmt = evalGhciLikeCmd cmd arg | -- A statement - isStmt df stmt = + isStmt pf stmt = do dbg "{STMT " stmt res <- exec stmt l @@ -582,7 +587,7 @@ evals (st, fp) df stmts = do dbg "STMT} -> " r return r | -- An import - isImport df stmt = + isImport pf stmt = do dbg "{IMPORT " stmt _ <- addImport stmt @@ -593,6 +598,13 @@ evals (st, fp) df stmts = do dbg "{DECL " stmt void $ runDecls stmt return Nothing +#if !MIN_VERSION_ghc(9,0,0) + pf = df + unhelpfulReason = "" +#else + pf = mkParserFlags df + unhelpfulReason = UnhelpfulInteractive +#endif exec stmt l = let opts = execOptions{execSourceFile = fp, execLineNumber = l} in myExecStmt stmt opts @@ -752,7 +764,7 @@ doTypeCmd :: DynFlags -> Text -> Ghc (Maybe Text) doTypeCmd dflags arg = do let (emod, expr) = parseExprMode arg ty <- exprType emod $ T.unpack expr - let rawType = T.strip $ T.pack $ showSDoc dflags $ ppr ty + let rawType = T.strip $ T.pack $ showSDoc dflags $ pprTypeForUser ty broken = T.any (\c -> c == '\r' || c == '\n') rawType pure $ Just $ @@ -761,7 +773,7 @@ doTypeCmd dflags arg = do T.pack $ showSDoc dflags $ text (T.unpack expr) - $$ nest 2 ("::" <+> ppr ty) + $$ nest 2 ("::" <+> pprTypeForUser ty) else expr <> " :: " <> rawType <> "\n" parseExprMode :: Text -> (TcRnExprMode, T.Text) @@ -804,13 +816,18 @@ setupDynFlagsForGHCiLike env dflags = do , ghcLink = LinkInMemory } platform = targetPlatform dflags3 - dflags3a = updateWays $ dflags3{ways = interpWays} +#if MIN_VERSION_ghc(9,0,0) + evalWays = hostFullWays +#else + evalWays = interpWays +#endif + dflags3a = dflags3{ways = evalWays} dflags3b = foldl gopt_set dflags3a $ - concatMap (wayGeneralFlags platform) interpWays + concatMap (wayGeneralFlags platform) evalWays dflags3c = foldl gopt_unset dflags3b $ - concatMap (wayUnsetGeneralFlags platform) interpWays + concatMap (wayUnsetGeneralFlags platform) evalWays dflags4 = dflags3c `gopt_set` Opt_ImplicitImportQualified diff --git a/stack-9.0.1.yaml b/stack-9.0.1.yaml index c335fa7947..25d616c129 100644 --- a/stack-9.0.1.yaml +++ b/stack-9.0.1.yaml @@ -105,7 +105,6 @@ configure-options: flags: haskell-language-server: pedantic: true - eval: false class: false splice: false refineImports: false From 02b692cc2b769fd70cc46ec068e8c52bd8d8a5ce Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Sun, 4 Jul 2021 10:03:56 +0800 Subject: [PATCH 02/11] Update CI and stack --- .github/workflows/test.yml | 2 +- stack-9.0.1.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 63c4a8f7bb..1c902b0c97 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -170,7 +170,7 @@ jobs: name: Test hls-class-plugin run: cabal test hls-class-plugin --test-options="-j1 --rerun-update" || cabal test hls-class-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-class-plugin --test-options="-j1 --rerun" - - if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test && matrix.ghc != '9.0.1' }} + - if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test }} name: Test hls-eval-plugin run: cabal test hls-eval-plugin --test-options="-j1 --rerun-update" || cabal test hls-eval-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-eval-plugin --test-options="-j1 --rerun" diff --git a/stack-9.0.1.yaml b/stack-9.0.1.yaml index 25d616c129..8facf065b1 100644 --- a/stack-9.0.1.yaml +++ b/stack-9.0.1.yaml @@ -11,7 +11,7 @@ packages: # - ./shake-bench # - ./plugins/hls-class-plugin - ./plugins/hls-haddock-comments-plugin - # - ./plugins/hls-eval-plugin + - ./plugins/hls-eval-plugin - ./plugins/hls-explicit-imports-plugin # - ./plugins/hls-refine-imports-plugin - ./plugins/hls-hlint-plugin From f8ebeac67087a99da4ea6833d25dbfb710a3be42 Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Sun, 4 Jul 2021 10:04:44 +0800 Subject: [PATCH 03/11] Use pprTypeForUser for printing kinds --- plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs index 5e920cdb09..28c867a95e 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs @@ -751,13 +751,13 @@ doKindCmd :: Bool -> DynFlags -> Text -> Ghc (Maybe Text) doKindCmd False df arg = do let input = T.strip arg (_, kind) <- typeKind False $ T.unpack input - let kindText = text (T.unpack input) <+> "::" <+> ppr kind + let kindText = text (T.unpack input) <+> "::" <+> pprTypeForUser kind pure $ Just $ T.pack (showSDoc df kindText) doKindCmd True df arg = do let input = T.strip arg (ty, kind) <- typeKind True $ T.unpack input - let kindDoc = text (T.unpack input) <+> "::" <+> ppr kind - tyDoc = "=" <+> ppr ty + let kindDoc = text (T.unpack input) <+> "::" <+> pprTypeForUser kind + tyDoc = "=" <+> pprTypeForUser ty pure $ Just $ T.pack (showSDoc df $ kindDoc $$ tyDoc) doTypeCmd :: DynFlags -> Text -> Ghc (Maybe Text) From a9e218dcbbded36f93793a0d8a619c36bd4ce46a Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Sun, 4 Jul 2021 10:05:33 +0800 Subject: [PATCH 04/11] test: remove forall --- .../testdata/TSameDefaultLanguageExtensionsAsGhci.expected.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hls-eval-plugin/test/testdata/TSameDefaultLanguageExtensionsAsGhci.expected.hs b/plugins/hls-eval-plugin/test/testdata/TSameDefaultLanguageExtensionsAsGhci.expected.hs index dad95db872..ac69b2a0ef 100644 --- a/plugins/hls-eval-plugin/test/testdata/TSameDefaultLanguageExtensionsAsGhci.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/TSameDefaultLanguageExtensionsAsGhci.expected.hs @@ -24,4 +24,4 @@ It therefore suffices to test for ExtendedDefaultRules and NoMonomorphismRestric -- >>> plus = (+) -- >>> :t plus --- plus :: forall a. Num a => a -> a -> a +-- plus :: Num a => a -> a -> a From 4f4490b63619cc13f77057ee14b9b0d01f85f4c5 Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Sun, 4 Jul 2021 10:07:54 +0800 Subject: [PATCH 05/11] test: [Char] -> String --- plugins/hls-eval-plugin/test/testdata/T8.expected.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/hls-eval-plugin/test/testdata/T8.expected.hs b/plugins/hls-eval-plugin/test/testdata/T8.expected.hs index 2089d3d78f..94db41d104 100644 --- a/plugins/hls-eval-plugin/test/testdata/T8.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/T8.expected.hs @@ -5,7 +5,7 @@ module T8 where -- Variable not in scope: noFunctionWithThisName -- >>> "a" + "bc" --- No instance for (Num [Char]) arising from a use of ‘+’ +-- No instance for (Num String) arising from a use of ‘+’ -- >>> " -- lexical error in string/character literal at end of input From 1a8fa2c277920e9a8c9030501ebcfbdc1daf7440 Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Sun, 4 Jul 2021 10:23:23 +0800 Subject: [PATCH 06/11] test: update forall --- .../test/testdata/T21.expected.hs | 2 +- .../test/testdata/T23.expected.hs | 2 +- .../test/testdata/TFlags.expected.hs | 17 ++++++----------- plugins/hls-eval-plugin/test/testdata/TFlags.hs | 14 ++++---------- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/plugins/hls-eval-plugin/test/testdata/T21.expected.hs b/plugins/hls-eval-plugin/test/testdata/T21.expected.hs index 5ffcc3906d..6e23213474 100644 --- a/plugins/hls-eval-plugin/test/testdata/T21.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/T21.expected.hs @@ -11,6 +11,6 @@ fun _ _ _ = () -- >>> :type fun -- fun --- :: forall k1 (k2 :: Nat) (n :: Nat) (a :: k1). +-- :: forall {k1} {k2 :: Nat} {n :: Nat} {a :: k1}. -- (KnownNat k2, KnownNat n, Typeable a) => -- Proxy k2 -> Proxy n -> Proxy a -> () diff --git a/plugins/hls-eval-plugin/test/testdata/T23.expected.hs b/plugins/hls-eval-plugin/test/testdata/T23.expected.hs index 3039ca8a8c..dbe7fa6ff0 100644 --- a/plugins/hls-eval-plugin/test/testdata/T23.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/T23.expected.hs @@ -10,6 +10,6 @@ f :: forall k n a. (KnownNat k, KnownNat n, Typeable a) f _ _ _ = () -- >>> :type f --- f :: forall k1 (k2 :: Nat) (n :: Nat) (a :: k1). +-- f :: forall {k1} {k2 :: Nat} {n :: Nat} {a :: k1}. -- (KnownNat k2, KnownNat n, Typeable a) => -- Proxy k2 -> Proxy n -> Proxy a -> () diff --git a/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs b/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs index 9d6196e5bf..b15a988534 100644 --- a/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs @@ -51,14 +51,14 @@ It still works {- -fprint-* families ->>> import Data.Proxy ->>> :set -XPolyKinds ->>> :t Proxy -Proxy :: forall k (t :: k). Proxy t +>>> :t id +id :: a -> a + >>> :set -fprint-explicit-foralls ->>> :t Proxy -Proxy :: forall {k} {t :: k}. Proxy t +>>> :t id +id :: forall {a}. a -> a + -} {- Invalid option/flags are reported, but valid ones will be reflected @@ -68,9 +68,4 @@ Proxy :: forall {k} {t :: k}. Proxy t -XDatatypeContexts is deprecated: It was widely considered a misfeature, and has been removed from the Haskell language. Some flags have not been recognized: -XAbsent, -XWrong, -fprint-nothing-at-all -Still, Rank2Types is enabled, as in GHCi: - ->>> f = const 42 :: (forall x. x) -> Int ->>> f undefined -42 -} diff --git a/plugins/hls-eval-plugin/test/testdata/TFlags.hs b/plugins/hls-eval-plugin/test/testdata/TFlags.hs index a821ea4ec1..c8b49a6e2a 100644 --- a/plugins/hls-eval-plugin/test/testdata/TFlags.hs +++ b/plugins/hls-eval-plugin/test/testdata/TFlags.hs @@ -47,22 +47,16 @@ It still works {- -fprint-* families ->>> import Data.Proxy ->>> :set -XPolyKinds ->>> :t Proxy -Proxy :: forall k (t :: k). Proxy t +>>> :t id + >>> :set -fprint-explicit-foralls ->>> :t Proxy -Proxy :: forall {k} {t :: k}. Proxy t +>>> :t id + -} {- Invalid option/flags are reported, but valid ones will be reflected >>> :set -XRank2Types -XAbsent -XDatatypeContexts -XWrong -fprint-nothing-at-all -Still, Rank2Types is enabled, as in GHCi: - ->>> f = const 42 :: (forall x. x) -> Int ->>> f undefined -} From 2cddd7666df3c903a7a28cc21e085d655d81e720 Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Sun, 4 Jul 2021 10:35:09 +0800 Subject: [PATCH 07/11] Keep tests only for GHC 9 --- .github/workflows/test.yml | 2 +- hls-test-utils/src/Test/Hls/Util.hs | 5 ++++- plugins/hls-eval-plugin/test/Main.hs | 6 +++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c902b0c97..b3affa8b1f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -170,7 +170,7 @@ jobs: name: Test hls-class-plugin run: cabal test hls-class-plugin --test-options="-j1 --rerun-update" || cabal test hls-class-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-class-plugin --test-options="-j1 --rerun" - - if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test }} + - if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test && matrix.ghc == '9.0.1' }} name: Test hls-eval-plugin run: cabal test hls-eval-plugin --test-options="-j1 --rerun-update" || cabal test hls-eval-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-eval-plugin --test-options="-j1 --rerun" diff --git a/hls-test-utils/src/Test/Hls/Util.hs b/hls-test-utils/src/Test/Hls/Util.hs index 182a2500c5..e54f018e33 100644 --- a/hls-test-utils/src/Test/Hls/Util.hs +++ b/hls-test-utils/src/Test/Hls/Util.hs @@ -112,10 +112,13 @@ data GhcVersion | GHC88 | GHC86 | GHC84 + | GHC901 deriving (Eq,Show) ghcVersion :: GhcVersion -#if (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,10,0,0))) +#if (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(9,0,1,0))) +ghcVersion = GHC901 +#elif (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,10,0,0))) ghcVersion = GHC810 #elif (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,8,0,0))) ghcVersion = GHC88 diff --git a/plugins/hls-eval-plugin/test/Main.hs b/plugins/hls-eval-plugin/test/Main.hs index 03972a96c0..4264391742 100644 --- a/plugins/hls-eval-plugin/test/Main.hs +++ b/plugins/hls-eval-plugin/test/Main.hs @@ -20,7 +20,11 @@ import System.FilePath (()) import Test.Hls main :: IO () -main = defaultTestRunner tests +main = defaultTestRunner $ if ghcVersion == GHC901 then tests else dummyTestCase + +-- | Now we only maintain test cases for GHC 9.0.1 +dummyTestCase :: TestTree +dummyTestCase = testCase "Tests are skipped before GHC 9.0.1" $ pure () evalPlugin :: PluginDescriptor IdeState evalPlugin = Eval.descriptor "eval" From 7bad4dbb30646f43c091974860aa9cb58669b04a Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Sun, 4 Jul 2021 14:54:29 +0800 Subject: [PATCH 08/11] Update nix and CI --- .github/workflows/test.yml | 2 +- configuration-ghc-901.nix | 2 -- plugins/hls-eval-plugin/test/Main.hs | 10 ++++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b3affa8b1f..34526ab0d5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -170,7 +170,7 @@ jobs: name: Test hls-class-plugin run: cabal test hls-class-plugin --test-options="-j1 --rerun-update" || cabal test hls-class-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-class-plugin --test-options="-j1 --rerun" - - if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test && matrix.ghc == '9.0.1' }} + - if: ${{ needs.pre_job.outputs.should_skip != 'true' && matrix.test && matrix.ghc }} name: Test hls-eval-plugin run: cabal test hls-eval-plugin --test-options="-j1 --rerun-update" || cabal test hls-eval-plugin --test-options="-j1 --rerun" || LSP_TEST_LOG_COLOR=0 LSP_TEST_LOG_MESSAGES=true LSP_TEST_LOG_STDERR=true cabal test hls-eval-plugin --test-options="-j1 --rerun" diff --git a/configuration-ghc-901.nix b/configuration-ghc-901.nix index 9c74864608..1a59bff132 100644 --- a/configuration-ghc-901.nix +++ b/configuration-ghc-901.nix @@ -9,7 +9,6 @@ let "hls-fourmolu-plugin" "hls-splice-plugin" "hls-ormolu-plugin" - "hls-eval-plugin" "hls-class-plugin" "hls-refine-imports-plugin" ]; @@ -106,7 +105,6 @@ let (pkgs.lib.concatStringsSep " " [ "-f-brittany" "-f-class" - "-f-eval" "-f-fourmolu" "-f-ormolu" "-f-splice" diff --git a/plugins/hls-eval-plugin/test/Main.hs b/plugins/hls-eval-plugin/test/Main.hs index 4264391742..2098526fcd 100644 --- a/plugins/hls-eval-plugin/test/Main.hs +++ b/plugins/hls-eval-plugin/test/Main.hs @@ -20,11 +20,13 @@ import System.FilePath (()) import Test.Hls main :: IO () -main = defaultTestRunner $ if ghcVersion == GHC901 then tests else dummyTestCase +main = defaultTestRunner $ ignore tests --- | Now we only maintain test cases for GHC 9.0.1 -dummyTestCase :: TestTree -dummyTestCase = testCase "Tests are skipped before GHC 9.0.1" $ pure () +ignore :: TestTree -> TestTree +ignore = + if ghcVersion == GHC901 + then id + else ignoreTestBecause "Eval plugin tests are enabled for GHC 9.0.1" evalPlugin :: PluginDescriptor IdeState evalPlugin = Eval.descriptor "eval" From 9489c226a1f45799d2dade9318e4e072788fec8f Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Sun, 4 Jul 2021 15:02:16 +0800 Subject: [PATCH 09/11] Mark one hlint test as known broken --- test/functional/FunctionalCodeAction.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/FunctionalCodeAction.hs b/test/functional/FunctionalCodeAction.hs index 13dd7eca67..877987505c 100644 --- a/test/functional/FunctionalCodeAction.hs +++ b/test/functional/FunctionalCodeAction.hs @@ -151,7 +151,7 @@ hlintTests = testGroup "hlint suggestions" [ doc <- openDoc "ApplyRefact4.hs" "haskell" expectNoMoreDiagnostics 3 doc "hlint" - , knownBrokenForGhcVersions [GHC810] "hlint plugin doesn't honour HLINT annotations (#838)" $ + , knownBrokenForGhcVersions [GHC810, GHC901] "hlint plugin doesn't honour HLINT annotations (#838)" $ testCase "hlint diagnostics ignore hints honouring HLINT annotations" $ runHlintSession "" $ do doc <- openDoc "ApplyRefact5.hs" "haskell" expectNoMoreDiagnostics 3 doc "hlint" From d89b418694e3c076ff1306c7ee8d9a70594f128a Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Sun, 4 Jul 2021 23:08:14 +0800 Subject: [PATCH 10/11] Re-enable tests for other ghc versions --- plugins/hls-eval-plugin/hls-eval-plugin.cabal | 7 +-- plugins/hls-eval-plugin/test/Main.hs | 53 +++++++++++++++---- .../test/testdata/T21.expected.hs | 16 ------ plugins/hls-eval-plugin/test/testdata/T21.hs | 1 - .../test/testdata/T23.expected.hs | 15 ------ plugins/hls-eval-plugin/test/testdata/T23.hs | 1 - .../test/testdata/T8.expected.hs | 14 ----- plugins/hls-eval-plugin/test/testdata/T8.hs | 10 +--- .../test/testdata/TFlags.expected.hs | 11 ---- .../hls-eval-plugin/test/testdata/TFlags.hs | 9 ---- 10 files changed, 48 insertions(+), 89 deletions(-) delete mode 100644 plugins/hls-eval-plugin/test/testdata/T21.expected.hs delete mode 100644 plugins/hls-eval-plugin/test/testdata/T23.expected.hs delete mode 100644 plugins/hls-eval-plugin/test/testdata/T8.expected.hs diff --git a/plugins/hls-eval-plugin/hls-eval-plugin.cabal b/plugins/hls-eval-plugin/hls-eval-plugin.cabal index ff901f7bef..2be1a9dd71 100644 --- a/plugins/hls-eval-plugin/hls-eval-plugin.cabal +++ b/plugins/hls-eval-plugin/hls-eval-plugin.cabal @@ -19,13 +19,13 @@ build-type: Simple extra-source-files: LICENSE README.md + test/cabal.project + test/info-util/*.cabal + test/info-util/*.hs test/testdata/*.cabal test/testdata/*.hs test/testdata/*.lhs test/testdata/*.yaml - test/info-util/*.cabal - test/info-util/*.hs - test/cabal.project flag pedantic description: Enable -Werror @@ -110,3 +110,4 @@ test-suite tests , hls-test-utils ^>=1.0 , lens , lsp-types + , text diff --git a/plugins/hls-eval-plugin/test/Main.hs b/plugins/hls-eval-plugin/test/Main.hs index 2098526fcd..2933a2ca00 100644 --- a/plugins/hls-eval-plugin/test/Main.hs +++ b/plugins/hls-eval-plugin/test/Main.hs @@ -18,15 +18,10 @@ import Ide.Plugin.Eval.Types (EvalParams (..), Section (..), import Language.LSP.Types.Lens (arguments, command, range, title) import System.FilePath (()) import Test.Hls +import qualified Data.Text as T main :: IO () -main = defaultTestRunner $ ignore tests - -ignore :: TestTree -> TestTree -ignore = - if ghcVersion == GHC901 - then id - else ignoreTestBecause "Eval plugin tests are enabled for GHC 9.0.1" +main = defaultTestRunner tests evalPlugin :: PluginDescriptor IdeState evalPlugin = Eval.descriptor "eval" @@ -67,7 +62,14 @@ tests = , goldenWithEval "Refresh an evaluation" "T5" "hs" , goldenWithEval "Refresh an evaluation w/ lets" "T6" "hs" , goldenWithEval "Refresh a multiline evaluation" "T7" "hs" - , goldenWithEval "Semantic and Lexical errors are reported" "T8" "hs" + , testCase "Semantic and Lexical errors are reported" $ do + evalInFile "T8.hs" "-- >>> noFunctionWithThisName" "-- Variable not in scope: noFunctionWithThisName" + evalInFile "T8.hs" "-- >>> \"a\" + \"bc\"" $ + if ghcVersion == GHC901 + then "-- No instance for (Num String) arising from a use of ‘+’" + else "-- No instance for (Num [Char]) arising from a use of ‘+’" + evalInFile "T8.hs" "-- >>> \"" "-- lexical error in string/character literal at end of input" + evalInFile "T8.hs" "-- >>> 3 `div` 0" "-- divide by zero" , goldenWithEval "Applies file LANGUAGE extensions" "T9" "hs" , goldenWithEval "Evaluate a type with :kind!" "T10" "hs" , goldenWithEval "Reports an error for an incorrect type with :kind!" "T11" "hs" @@ -81,9 +83,24 @@ tests = , goldenWithEval "Returns defaulted type for :type +d reflecting the default declaration specified in the >>> prompt" "T19" "hs" , expectFailBecause "known issue - see a note in P.R. #361" $ goldenWithEval ":type +d reflects the `default' declaration of the module" "T20" "hs" - , goldenWithEval ":type handles a multilined result properly" "T21" "hs" + , testCase ":type handles a multilined result properly" $ + evalInFile "T21.hs" "-- >>> :type fun" $ T.unlines [ + "-- fun", + if ghcVersion == GHC901 + then "-- :: forall {k1} {k2 :: Nat} {n :: Nat} {a :: k1}." + else "-- :: forall k1 (k2 :: Nat) (n :: Nat) (a :: k1).", + "-- (KnownNat k2, KnownNat n, Typeable a) =>", + "-- Proxy k2 -> Proxy n -> Proxy a -> ()" + ] , goldenWithEval ":t behaves exactly the same as :type" "T22" "hs" - , goldenWithEval ":type does \"dovetails\" for short identifiers" "T23" "hs" + , testCase ":type does \"dovetails\" for short identifiers" $ + evalInFile "T23.hs" "-- >>> :type f" $ T.unlines [ + if ghcVersion == GHC901 + then "-- f :: forall {k1} {k2 :: Nat} {n :: Nat} {a :: k1}." + else "-- f :: forall k1 (k2 :: Nat) (n :: Nat) (a :: k1).", + "-- (KnownNat k2, KnownNat n, Typeable a) =>", + "-- Proxy k2 -> Proxy n -> Proxy a -> ()" + ] , goldenWithEval ":kind! treats a multilined result properly" "T24" "hs" , goldenWithEval ":kind treats a multilined result properly" "T25" "hs" , goldenWithEval "local imports" "T26" "hs" @@ -97,6 +114,12 @@ tests = -- , goldenWithEval "Local Modules can be imported in a test" "TLocalImportInTest" "hs" , goldenWithEval "Setting language option TupleSections" "TLanguageOptionsTupleSections" "hs" , goldenWithEval ":set accepts ghci flags" "TFlags" "hs" + , testCase ":set -fprint-explicit-foralls works" $ do + evalInFile "T8.hs" "-- >>> :t id" "-- id :: a -> a" + evalInFile "T8.hs" "-- >>> :set -fprint-explicit-foralls\n-- >>> :t id" $ + if ghcVersion == GHC901 + then "-- id :: forall {a}. a -> a" + else "-- id :: forall a. a -> a" , goldenWithEval "The default language extensions for the eval plugin are the same as those for ghci" "TSameDefaultLanguageExtensionsAsGhci" "hs" , goldenWithEval "IO expressions are supported, stdout/stderr output is ignored" "TIO" "hs" , goldenWithEval "Property checking" "TProperty" "hs" @@ -202,3 +225,13 @@ codeLensTestOutput codeLens = do testDataDir :: FilePath testDataDir = "test" "testdata" + +evalInFile :: FilePath -> T.Text -> T.Text -> IO () +evalInFile fp e expected = runSessionWithServer evalPlugin testDataDir $ do + doc <- openDoc fp "haskell" + origin <- documentContents doc + let withEval = origin <> e + changeDoc doc [TextDocumentContentChangeEvent Nothing Nothing withEval] + executeLensesBackwards doc + result <- fmap T.strip . T.stripPrefix withEval <$> documentContents doc + liftIO $ result @?= Just (T.strip expected) diff --git a/plugins/hls-eval-plugin/test/testdata/T21.expected.hs b/plugins/hls-eval-plugin/test/testdata/T21.expected.hs deleted file mode 100644 index 6e23213474..0000000000 --- a/plugins/hls-eval-plugin/test/testdata/T21.expected.hs +++ /dev/null @@ -1,16 +0,0 @@ -{-# LANGUAGE PolyKinds #-} -{-# LANGUAGE ScopedTypeVariables #-} -module T21 where -import Data.Proxy (Proxy(..)) -import GHC.TypeNats (KnownNat) -import Type.Reflection (Typeable) - -fun :: forall k n a. (KnownNat k, KnownNat n, Typeable a) - => Proxy k -> Proxy n -> Proxy a -> () -fun _ _ _ = () - --- >>> :type fun --- fun --- :: forall {k1} {k2 :: Nat} {n :: Nat} {a :: k1}. --- (KnownNat k2, KnownNat n, Typeable a) => --- Proxy k2 -> Proxy n -> Proxy a -> () diff --git a/plugins/hls-eval-plugin/test/testdata/T21.hs b/plugins/hls-eval-plugin/test/testdata/T21.hs index 0570b8d36e..64068f55ed 100644 --- a/plugins/hls-eval-plugin/test/testdata/T21.hs +++ b/plugins/hls-eval-plugin/test/testdata/T21.hs @@ -9,4 +9,3 @@ fun :: forall k n a. (KnownNat k, KnownNat n, Typeable a) => Proxy k -> Proxy n -> Proxy a -> () fun _ _ _ = () --- >>> :type fun diff --git a/plugins/hls-eval-plugin/test/testdata/T23.expected.hs b/plugins/hls-eval-plugin/test/testdata/T23.expected.hs deleted file mode 100644 index dbe7fa6ff0..0000000000 --- a/plugins/hls-eval-plugin/test/testdata/T23.expected.hs +++ /dev/null @@ -1,15 +0,0 @@ -{-# LANGUAGE PolyKinds #-} -{-# LANGUAGE ScopedTypeVariables #-} -module T23 where -import Data.Proxy (Proxy (..)) -import GHC.TypeNats (KnownNat) -import Type.Reflection (Typeable) - -f :: forall k n a. (KnownNat k, KnownNat n, Typeable a) - => Proxy k -> Proxy n -> Proxy a -> () -f _ _ _ = () - --- >>> :type f --- f :: forall {k1} {k2 :: Nat} {n :: Nat} {a :: k1}. --- (KnownNat k2, KnownNat n, Typeable a) => --- Proxy k2 -> Proxy n -> Proxy a -> () diff --git a/plugins/hls-eval-plugin/test/testdata/T23.hs b/plugins/hls-eval-plugin/test/testdata/T23.hs index 6f9c73a12e..0a9edaa5c9 100644 --- a/plugins/hls-eval-plugin/test/testdata/T23.hs +++ b/plugins/hls-eval-plugin/test/testdata/T23.hs @@ -9,4 +9,3 @@ f :: forall k n a. (KnownNat k, KnownNat n, Typeable a) => Proxy k -> Proxy n -> Proxy a -> () f _ _ _ = () --- >>> :type f diff --git a/plugins/hls-eval-plugin/test/testdata/T8.expected.hs b/plugins/hls-eval-plugin/test/testdata/T8.expected.hs deleted file mode 100644 index 94db41d104..0000000000 --- a/plugins/hls-eval-plugin/test/testdata/T8.expected.hs +++ /dev/null @@ -1,14 +0,0 @@ --- Semantic and Lexical errors are reported -module T8 where - --- >>> noFunctionWithThisName --- Variable not in scope: noFunctionWithThisName - --- >>> "a" + "bc" --- No instance for (Num String) arising from a use of ‘+’ - --- >>> " --- lexical error in string/character literal at end of input - --- >>> 3 `div` 0 --- divide by zero diff --git a/plugins/hls-eval-plugin/test/testdata/T8.hs b/plugins/hls-eval-plugin/test/testdata/T8.hs index a0188670b0..44cd164a09 100644 --- a/plugins/hls-eval-plugin/test/testdata/T8.hs +++ b/plugins/hls-eval-plugin/test/testdata/T8.hs @@ -1,10 +1,2 @@ --- Semantic and Lexical errors are reported +-- An empty playground module T8 where - --- >>> noFunctionWithThisName - --- >>> "a" + "bc" - --- >>> " - --- >>> 3 `div` 0 diff --git a/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs b/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs index b15a988534..2ee96ac131 100644 --- a/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs +++ b/plugins/hls-eval-plugin/test/testdata/TFlags.expected.hs @@ -49,17 +49,6 @@ It still works -} -{- -fprint-* families - ->>> :t id -id :: a -> a - - ->>> :set -fprint-explicit-foralls ->>> :t id -id :: forall {a}. a -> a - --} {- Invalid option/flags are reported, but valid ones will be reflected diff --git a/plugins/hls-eval-plugin/test/testdata/TFlags.hs b/plugins/hls-eval-plugin/test/testdata/TFlags.hs index c8b49a6e2a..7218f3d7bf 100644 --- a/plugins/hls-eval-plugin/test/testdata/TFlags.hs +++ b/plugins/hls-eval-plugin/test/testdata/TFlags.hs @@ -45,15 +45,6 @@ It still works -} -{- -fprint-* families - ->>> :t id - - ->>> :set -fprint-explicit-foralls ->>> :t id - --} {- Invalid option/flags are reported, but valid ones will be reflected From 3aeccce9a7a292d6063cf2f18f6a939de2d5a4ef Mon Sep 17 00:00:00 2001 From: Potato Hatsue <1793913507@qq.com> Date: Mon, 5 Jul 2021 14:40:17 +0800 Subject: [PATCH 11/11] Update test --- plugins/hls-eval-plugin/test/Main.hs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/hls-eval-plugin/test/Main.hs b/plugins/hls-eval-plugin/test/Main.hs index 2933a2ca00..38fbf660a6 100644 --- a/plugins/hls-eval-plugin/test/Main.hs +++ b/plugins/hls-eval-plugin/test/Main.hs @@ -86,7 +86,7 @@ tests = , testCase ":type handles a multilined result properly" $ evalInFile "T21.hs" "-- >>> :type fun" $ T.unlines [ "-- fun", - if ghcVersion == GHC901 + if ghcVersion == GHC901 then "-- :: forall {k1} {k2 :: Nat} {n :: Nat} {a :: k1}." else "-- :: forall k1 (k2 :: Nat) (n :: Nat) (a :: k1).", "-- (KnownNat k2, KnownNat n, Typeable a) =>", @@ -95,7 +95,7 @@ tests = , goldenWithEval ":t behaves exactly the same as :type" "T22" "hs" , testCase ":type does \"dovetails\" for short identifiers" $ evalInFile "T23.hs" "-- >>> :type f" $ T.unlines [ - if ghcVersion == GHC901 + if ghcVersion == GHC901 then "-- f :: forall {k1} {k2 :: Nat} {n :: Nat} {a :: k1}." else "-- f :: forall k1 (k2 :: Nat) (n :: Nat) (a :: k1).", "-- (KnownNat k2, KnownNat n, Typeable a) =>", @@ -116,10 +116,8 @@ tests = , goldenWithEval ":set accepts ghci flags" "TFlags" "hs" , testCase ":set -fprint-explicit-foralls works" $ do evalInFile "T8.hs" "-- >>> :t id" "-- id :: a -> a" - evalInFile "T8.hs" "-- >>> :set -fprint-explicit-foralls\n-- >>> :t id" $ - if ghcVersion == GHC901 - then "-- id :: forall {a}. a -> a" - else "-- id :: forall a. a -> a" + evalInFile "T8.hs" "-- >>> :set -fprint-explicit-foralls\n-- >>> :t id" + "-- id :: forall {a}. a -> a" , goldenWithEval "The default language extensions for the eval plugin are the same as those for ghci" "TSameDefaultLanguageExtensionsAsGhci" "hs" , goldenWithEval "IO expressions are supported, stdout/stderr output is ignored" "TIO" "hs" , goldenWithEval "Property checking" "TProperty" "hs"