diff --git a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Code.hs b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Code.hs index 61b3e8e2ba..7497ae783a 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Code.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/Code.hs @@ -3,7 +3,7 @@ {-# OPTIONS_GHC -Wwarn -fno-warn-orphans #-} -- | Expression execution -module Ide.Plugin.Eval.Code (Statement, testRanges, resultRange, evalExtensions, evalSetup, propSetup, testCheck, asStatements,myExecStmt) where +module Ide.Plugin.Eval.Code (Statement, testRanges, resultRange, evalSetup, propSetup, testCheck, asStatements,myExecStmt) where import Control.Lens ((^.)) import Data.Algorithm.Diff (Diff, PolyDiff (..), getDiff) @@ -13,7 +13,6 @@ import qualified Data.Text as T import Development.IDE.Types.Location (Position (..), Range (..)) import GHC (ExecOptions, ExecResult (..), execStmt) -import GHC.LanguageExtensions.Type (Extension (..)) import GhcMonad (Ghc, liftIO, modifySession) import HscTypes import Ide.Plugin.Eval.Types (Language (Plain), Loc, @@ -81,15 +80,6 @@ asStmts (Example e _ _) = NE.toList e asStmts (Property t _ _) = ["prop11 = " ++ t, "(propEvaluation prop11 :: IO String)"] --- |GHC extensions required for expression evaluation -evalExtensions :: [Extension] -evalExtensions = - [ OverlappingInstances - , UndecidableInstances - , FlexibleInstances - , IncoherentInstances - , TupleSections - ] -- |GHC declarations required for expression evaluation evalSetup :: Ghc () 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 ad97feb6ea..c6b418372a 100644 --- a/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs +++ b/plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs @@ -108,6 +108,7 @@ import GHC (ClsInst, setContext, setLogAction, setSessionDynFlags, setTargets, typeKind) +import qualified GHC.LanguageExtensions.Type as LangExt (Extension (..)) import GhcPlugins (DynFlags (..), defaultLogActionHPutStrDoc, elemNameSet, gopt_set, @@ -118,13 +119,13 @@ import GhcPlugins (DynFlags (..), pprInfixName, targetPlatform, tyThingParent_maybe, - xopt_set) + xopt_set, xopt_unset) + import HscTypes (InteractiveImport (IIModule), ModSummary (ms_mod), Target (Target), TargetId (TargetFile)) import Ide.Plugin.Eval.Code (Statement, asStatements, - evalExtensions, evalSetup, myExecStmt, propSetup, resultRange, testCheck, testRanges) @@ -316,8 +317,13 @@ runEvalCmd st EvalParams{..} = -- copy the package state to the interactive DynFlags idflags <- getInteractiveDynFlags df <- getSessionDynFlags - setInteractiveDynFlags $ - (foldl xopt_set idflags evalExtensions) + -- set the identical DynFlags as GHCi + -- Source: https://github.com/ghc/ghc/blob/5abf59976c7335df760e5d8609d9488489478173/ghc/GHCi/UI.hs#L473-L483 + -- This needs to be done manually since the default flags are not visible externally. + let df' = flip xopt_set LangExt.ExtendedDefaultRules + . flip xopt_unset LangExt.MonomorphismRestriction + $ idflags + setInteractiveDynFlags $ df' #if MIN_VERSION_ghc(9,0,0) { unitState = unitState diff --git a/plugins/hls-eval-plugin/test/Main.hs b/plugins/hls-eval-plugin/test/Main.hs index ff684a7281..03972a96c0 100644 --- a/plugins/hls-eval-plugin/test/Main.hs +++ b/plugins/hls-eval-plugin/test/Main.hs @@ -91,6 +91,7 @@ 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" + , 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" , goldenWithEval "Prelude has no special treatment, it is imported as stated in the module" "TPrelude" "hs" diff --git a/plugins/hls-eval-plugin/test/testdata/TSameDefaultLanguageExtensionsAsGhci.expected.hs b/plugins/hls-eval-plugin/test/testdata/TSameDefaultLanguageExtensionsAsGhci.expected.hs new file mode 100644 index 0000000000..dad95db872 --- /dev/null +++ b/plugins/hls-eval-plugin/test/testdata/TSameDefaultLanguageExtensionsAsGhci.expected.hs @@ -0,0 +1,27 @@ +-- The default language extensions for the eval plugin are the same as those for ghci + +module TSameDefaultLanguageExtensionsAsGhci where + +{- +Running `:showi language` within ghci currently lists NoDatatypeContexts, ExtendedDefaultRules, NoMonomorphismRestriction and NondecreasingIndentation. + +The flags NoDatatypeContexts and NondecreasingIndentation are globally set in Haskell2021, whereas ExtendedDefaultRules and NoMonomorphismRestriction are set manually within ghci. +(see https://github.com/ghc/ghc/blob/5abf59976c7335df760e5d8609d9488489478173/ghc/GHCi/UI.hs#L473-L483) + +It therefore suffices to test for ExtendedDefaultRules and NoMonomorphismRestriction only. +-} + + +-- ExtendedDefaultRules + +-- >>> [] +-- [] + +-- >>> reverse [] +-- [] + +-- NoMonomorphismRestriction + +-- >>> plus = (+) +-- >>> :t plus +-- plus :: forall a. Num a => a -> a -> a diff --git a/plugins/hls-eval-plugin/test/testdata/TSameDefaultLanguageExtensionsAsGhci.hs b/plugins/hls-eval-plugin/test/testdata/TSameDefaultLanguageExtensionsAsGhci.hs new file mode 100644 index 0000000000..148f0f86a8 --- /dev/null +++ b/plugins/hls-eval-plugin/test/testdata/TSameDefaultLanguageExtensionsAsGhci.hs @@ -0,0 +1,24 @@ +-- The default language extensions for the eval plugin are the same as those for ghci + +module TSameDefaultLanguageExtensionsAsGhci where + +{- +Running `:showi language` within ghci currently lists NoDatatypeContexts, ExtendedDefaultRules, NoMonomorphismRestriction and NondecreasingIndentation. + +The flags NoDatatypeContexts and NondecreasingIndentation are globally set in Haskell2021, whereas ExtendedDefaultRules and NoMonomorphismRestriction are set manually within ghci. +(see https://github.com/ghc/ghc/blob/5abf59976c7335df760e5d8609d9488489478173/ghc/GHCi/UI.hs#L473-L483) + +It therefore suffices to test for ExtendedDefaultRules and NoMonomorphismRestriction only. +-} + + +-- ExtendedDefaultRules + +-- >>> [] + +-- >>> reverse [] + +-- NoMonomorphismRestriction + +-- >>> plus = (+) +-- >>> :t plus diff --git a/plugins/hls-eval-plugin/test/testdata/test.cabal b/plugins/hls-eval-plugin/test/testdata/test.cabal index e3845f75f2..08856be2e2 100644 --- a/plugins/hls-eval-plugin/test/testdata/test.cabal +++ b/plugins/hls-eval-plugin/test/testdata/test.cabal @@ -50,6 +50,7 @@ library TLanguageOptionsTupleSections TIO TProperty + TSameDefaultLanguageExtensionsAsGhci TPrelude TCPP TLHS