Skip to content

Commit 5a51fbd

Browse files
authored
Minimal fix for eval regression (#488)
* Add a test reproducing the regression * Fix regression in Eval plugin * Fix redundant import
1 parent a6e6c0b commit 5a51fbd

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

plugins/default/src/Ide/Plugin/Eval.hs

+9-5
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ import Data.Bifunctor (Bifunctor (first))
3535
import Data.Char (isSpace)
3636
import qualified Data.HashMap.Strict as Map
3737
import Data.List (find)
38-
import Data.Maybe (catMaybes)
38+
import Data.Maybe (fromMaybe, catMaybes)
3939
import Data.String (IsString (fromString))
4040
import Data.Text (Text)
4141
import qualified Data.Text as T
4242
import Data.Time (getCurrentTime)
4343
import Development.IDE
44-
import Development.IDE.GHC.Compat (DynFlags, ExecResult (..), GeneralFlag (Opt_IgnoreHpcChanges, Opt_IgnoreOptimChanges, Opt_ImplicitImportQualified),
44+
import Development.IDE.GHC.Compat (DynFlags(importPaths), ExecResult (..),
45+
GeneralFlag (Opt_IgnoreHpcChanges, Opt_IgnoreOptimChanges, Opt_ImplicitImportQualified),
4546
Ghc, GhcLink (LinkInMemory),
4647
GhcMode (CompManager),
4748
HscTarget (HscInterpreted),
@@ -61,10 +62,9 @@ import Development.IDE.GHC.Compat (DynFlags, ExecResult (..), GeneralF
6162
setTargets, simpleImportDecl,
6263
typeKind, ways)
6364
import DynamicLoading (initializePlugins)
64-
import DynFlags (targetPlatform)
6565
import GHC.Generics (Generic)
6666
import GhcMonad (modifySession)
67-
import GhcPlugins (defaultLogActionHPutStrDoc,
67+
import GhcPlugins (targetPlatform, defaultLogActionHPutStrDoc,
6868
gopt_set, gopt_unset, interpWays,
6969
updateWays, wayGeneralFlags,
7070
wayUnsetGeneralFlags)
@@ -195,7 +195,11 @@ runEvalCmd lsp state EvalParams {..} = withIndefiniteProgress lsp "Eval" Cancell
195195
hscEnv' <- ExceptT $
196196
evalGhcEnv (hscEnv session) $ do
197197
env <- getSession
198+
-- Install the module pragmas and options
198199
df <- liftIO $ setupDynFlagsForGHCiLike env $ ms_hspp_opts ms
200+
-- Restore the cradle import paths
201+
df <- return df{importPaths = fromMaybe (importPaths df) $ envImportPaths session}
202+
-- Set the modified flags in the session
199203
_lp <- setSessionDynFlags df
200204

201205
-- copy the package state to the interactive DynFlags
@@ -295,7 +299,7 @@ evalGhciLikeCmd cmd arg = do
295299
df <- getSessionDynFlags
296300
case lookup cmd ghciLikeCommands
297301
<|> snd <$> find (T.isPrefixOf cmd . fst) ghciLikeCommands of
298-
Just hndler ->
302+
Just hndler ->
299303
fmap
300304
(T.unlines . map ("-- " <>) . T.lines
301305
)

test/functional/Eval.hs

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ tests = testGroup
8888
$ goldenTest "T24.hs"
8989
, testCase ":kind treats a multilined result properly"
9090
$ goldenTest "T25.hs"
91+
, testCase "local imports"
92+
$ goldenTest "T26.hs"
9193
]
9294

9395
goldenTest :: FilePath -> IO ()

test/testdata/eval/T26.hs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module T26 where
2+
import T25 ()
3+
4+
-- >>> "hello"

test/testdata/eval/T26.hs.expected

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module T26 where
2+
import T25 ()
3+
4+
-- >>> "hello"
5+
-- "hello"

test/testdata/eval/hie.yaml

+29-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
cradle: {direct: {arguments: ["T1", "T2", "T3", "T4"]}}
1+
cradle:
2+
direct:
3+
arguments:
4+
- "T1"
5+
- "T2"
6+
- "T3"
7+
- "T4"
8+
- "T5"
9+
- "T6"
10+
- "T7"
11+
- "T8"
12+
- "T9"
13+
- "T10"
14+
- "T11"
15+
- "T12"
16+
- "T13"
17+
- "T14"
18+
- "T15"
19+
- "T16"
20+
- "T17"
21+
- "T18"
22+
- "T19"
23+
- "T20"
24+
- "T21"
25+
- "T22"
26+
- "T23"
27+
- "T24"
28+
- "T25"
29+
- "T26"

0 commit comments

Comments
 (0)