Skip to content

Commit dcd2163

Browse files
pepeiborrajneiramergify[bot]
authored
Fix regression in Eval plugin and add test (#2441)
* Fix regression and add test * Fix tests Co-authored-by: Javier Neira <[email protected]> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent a83c850 commit dcd2163

File tree

9 files changed

+40
-14
lines changed

9 files changed

+40
-14
lines changed

ghcide/src/Development/IDE/Core/RuleTypes.hs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
-- using the "Shaker" abstraction layer for in-memory use.
1313
--
1414
module Development.IDE.Core.RuleTypes(
15+
GhcSessionDeps(.., GhcSessionDeps),
1516
module Development.IDE.Core.RuleTypes
1617
) where
1718

@@ -407,9 +408,15 @@ data GhcSession = GhcSession
407408
instance Hashable GhcSession
408409
instance NFData GhcSession
409410

410-
data GhcSessionDeps = GhcSessionDeps deriving (Eq, Show, Typeable, Generic)
411-
instance Hashable GhcSessionDeps
412-
instance NFData GhcSessionDeps
411+
newtype GhcSessionDeps = GhcSessionDeps_
412+
{ -- | Load full ModSummary values in the GHC session.
413+
-- Required for interactive evaluation, but leads to more cache invalidations
414+
fullModSummary :: Bool
415+
}
416+
deriving newtype (Eq, Show, Typeable, Hashable, NFData)
417+
418+
pattern GhcSessionDeps :: GhcSessionDeps
419+
pattern GhcSessionDeps = GhcSessionDeps_ False
413420

414421
data GetModIfaceFromDisk = GetModIfaceFromDisk
415422
deriving (Eq, Show, Typeable, Generic)

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -697,22 +697,23 @@ loadGhcSession ghcSessionDepsConfig = do
697697
Nothing -> LBS.toStrict $ B.encode (hash (snd val))
698698
return (Just cutoffHash, val)
699699

700-
defineNoDiagnostics $ \GhcSessionDeps file -> do
700+
defineNoDiagnostics $ \(GhcSessionDeps_ fullModSummary) file -> do
701701
env <- use_ GhcSession file
702-
ghcSessionDepsDefinition ghcSessionDepsConfig env file
702+
ghcSessionDepsDefinition fullModSummary ghcSessionDepsConfig env file
703703

704-
data GhcSessionDepsConfig = GhcSessionDepsConfig
704+
newtype GhcSessionDepsConfig = GhcSessionDepsConfig
705705
{ checkForImportCycles :: Bool
706-
, fullModSummary :: Bool
707706
}
708707
instance Default GhcSessionDepsConfig where
709708
def = GhcSessionDepsConfig
710709
{ checkForImportCycles = True
711-
, fullModSummary = False
712710
}
713711

714-
ghcSessionDepsDefinition :: GhcSessionDepsConfig -> HscEnvEq -> NormalizedFilePath -> Action (Maybe HscEnvEq)
715-
ghcSessionDepsDefinition GhcSessionDepsConfig{..} env file = do
712+
ghcSessionDepsDefinition
713+
:: -- | full mod summary
714+
Bool ->
715+
GhcSessionDepsConfig -> HscEnvEq -> NormalizedFilePath -> Action (Maybe HscEnvEq)
716+
ghcSessionDepsDefinition fullModSummary GhcSessionDepsConfig{..} env file = do
716717
let hsc = hscEnv env
717718

718719
mbdeps <- mapM(fmap artifactFilePath . snd) <$> use_ GetLocatedImports file
@@ -724,7 +725,7 @@ ghcSessionDepsDefinition GhcSessionDepsConfig{..} env file = do
724725
then uses_ GetModSummary deps
725726
else uses_ GetModSummaryWithoutTimestamps deps
726727

727-
depSessions <- map hscEnv <$> uses_ GhcSessionDeps deps
728+
depSessions <- map hscEnv <$> uses_ (GhcSessionDeps_ fullModSummary) deps
728729
ifaces <- uses_ GetModIface deps
729730

730731
let inLoadOrder = map hirHomeMod ifaces

ghcide/src/Development/IDE/Core/Tracing.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE NoApplicativeDo #-}
33
{-# LANGUAGE PackageImports #-}
4+
{-# LANGUAGE PatternSynonyms #-}
45
{-# HLINT ignore #-}
56
module Development.IDE.Core.Tracing
67
( otTracedHandler

plugins/hls-eval-plugin/src/Ide/Plugin/Eval/CodeLens.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import Development.IDE (GetModSummary (..),
4949
GhcSessionIO (..), IdeState,
5050
ModSummaryResult (..),
5151
NeedsCompilation (NeedsCompilation),
52-
evalGhcEnv, hscEnv,
52+
evalGhcEnv,
5353
hscEnvWithImportPaths,
5454
prettyPrint, runAction,
5555
textToStringBuffer,
@@ -541,9 +541,8 @@ runGetSession st nfp = liftIO $ runAction "eval" st $ do
541541
let env = fromMaybe (error $ "Unknown file: " <> fp) res
542542
ghcSessionDepsConfig = def
543543
{ checkForImportCycles = False
544-
, fullModSummary = True
545544
}
546-
res <- fmap hscEnvWithImportPaths <$> ghcSessionDepsDefinition ghcSessionDepsConfig env nfp
545+
res <- fmap hscEnvWithImportPaths <$> ghcSessionDepsDefinition True ghcSessionDepsConfig env nfp
547546
return $ fromMaybe (error $ "Unable to load file: " <> fp) res
548547

549548
needsQuickCheck :: [(Section, Test)] -> Bool

plugins/hls-eval-plugin/test/Main.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ tests =
112112
, goldenWithEval "Evaluate expressions in Haddock comments in both single line and multi line format" "THaddock" "hs"
113113
, goldenWithEval "Compare results (for Haddock tests only)" "TCompare" "hs"
114114
, goldenWithEval "Local Modules imports are accessible in a test" "TLocalImport" "hs"
115+
, goldenWithEval "Transitive local dependency" "TTransitive" "hs"
115116
-- , goldenWithEval "Local Modules can be imported in a test" "TLocalImportInTest" "hs"
116117
, goldenWithEval "Setting language option TupleSections" "TLanguageOptionsTupleSections" "hs"
117118
, goldenWithEval ":set accepts ghci flags" "TFlags" "hs"

plugins/hls-eval-plugin/test/testdata/TLocalImport.expected.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ import qualified Util
44

55
-- >>> Util.tst 11 11
66
-- True
7+
8+
tst' :: Eq a => a -> a -> Bool
9+
tst' = Util.tst

plugins/hls-eval-plugin/test/testdata/TLocalImport.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ module TLocalImport where
33
import qualified Util
44

55
-- >>> Util.tst 11 11
6+
7+
tst' :: Eq a => a -> a -> Bool
8+
tst' = Util.tst
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module TTransitive where
2+
3+
import TLocalImport
4+
5+
-- >>> tst' 11 11
6+
-- True
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module TTransitive where
2+
3+
import TLocalImport
4+
5+
-- >>> tst' 11 11

0 commit comments

Comments
 (0)