Skip to content

Commit bad0290

Browse files
committed
Add ShakeExtras arg to newHscEnvEq
1 parent fde147a commit bad0290

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
585585

586586
-- New HscEnv for the component in question, returns the new HscEnvEq and
587587
-- a mapping from FilePath to the newly created HscEnvEq.
588-
let new_cache = newComponentCache recorder optExtensions hieYaml _cfp hscEnv uids
588+
let new_cache = newComponentCache recorder extras optExtensions hieYaml _cfp hscEnv uids
589589
(cs, res) <- new_cache new
590590
-- Modified cache targets for everything else in the hie.yaml file
591591
-- which now uses the same EPS and so on
@@ -793,14 +793,15 @@ setNameCache nc hsc = hsc { hsc_NC = nc }
793793
-- | Create a mapping from FilePaths to HscEnvEqs
794794
newComponentCache
795795
:: Recorder (WithPriority Log)
796+
-> ShakeExtras
796797
-> [String] -- File extensions to consider
797798
-> Maybe FilePath -- Path to cradle
798799
-> NormalizedFilePath -- Path to file that caused the creation of this component
799800
-> HscEnv
800801
-> [(UnitId, DynFlags)]
801802
-> ComponentInfo
802803
-> IO ( [TargetDetails], (IdeResult HscEnvEq, DependencyInfo))
803-
newComponentCache recorder exts cradlePath cfp hsc_env uids ci = do
804+
newComponentCache recorder extras exts cradlePath cfp hsc_env uids ci = do
804805
let df = componentDynFlags ci
805806
hscEnv' <-
806807
#if MIN_VERSION_ghc(9,3,0)
@@ -823,7 +824,7 @@ newComponentCache recorder exts cradlePath cfp hsc_env uids ci = do
823824
#endif
824825

825826
let newFunc = maybe newHscEnvEqPreserveImportPaths newHscEnvEq cradlePath
826-
henv <- newFunc hscEnv' uids
827+
henv <- newFunc extras hscEnv' uids
827828
let targetEnv = ([], Just henv)
828829
targetDepends = componentDependencyInfo ci
829830
res = (targetEnv, targetDepends)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import Development.IDE.GHC.CoreFile
3131
import Development.IDE.GHC.Util
3232
import Development.IDE.Graph
3333
import Development.IDE.Import.DependencyInformation
34-
import Development.IDE.Types.HscEnvEq (HscEnvEq)
34+
import {-# SOURCE #-} Development.IDE.Types.HscEnvEq (HscEnvEq)
3535
import Development.IDE.Types.KnownTargets
3636
import GHC.Generics (Generic)
3737

ghcide/src/Development/IDE/Types/HscEnvEq.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Data.Set (Set)
2222
import qualified Data.Set as Set
2323
import Data.Unique (Unique)
2424
import qualified Data.Unique as Unique
25+
import Development.IDE.Core.Shake (ShakeExtras)
2526
import Development.IDE.GHC.Compat
2627
import qualified Development.IDE.GHC.Compat.Util as Maybes
2728
import Development.IDE.GHC.Error (catchSrcErrors)
@@ -59,19 +60,19 @@ updateHscEnvEq oldHscEnvEq newHscEnv = do
5960
update <$> Unique.newUnique
6061

6162
-- | Wrap an 'HscEnv' into an 'HscEnvEq'.
62-
newHscEnvEq :: FilePath -> HscEnv -> [(UnitId, DynFlags)] -> IO HscEnvEq
63-
newHscEnvEq cradlePath hscEnv0 deps = do
63+
newHscEnvEq :: FilePath -> ShakeExtras -> HscEnv -> [(UnitId, DynFlags)] -> IO HscEnvEq
64+
newHscEnvEq cradlePath se hscEnv0 deps = do
6465
let relativeToCradle = (takeDirectory cradlePath </>)
6566
hscEnv = removeImportPaths hscEnv0
6667

6768
-- Make Absolute since targets are also absolute
6869
importPathsCanon <-
6970
mapM makeAbsolute $ relativeToCradle <$> importPaths (hsc_dflags hscEnv0)
7071

71-
newHscEnvEqWithImportPaths (Just $ Set.fromList importPathsCanon) hscEnv deps
72+
newHscEnvEqWithImportPaths (Just $ Set.fromList importPathsCanon) se hscEnv deps
7273

73-
newHscEnvEqWithImportPaths :: Maybe (Set FilePath) -> HscEnv -> [(UnitId, DynFlags)] -> IO HscEnvEq
74-
newHscEnvEqWithImportPaths envImportPaths hscEnv deps = do
74+
newHscEnvEqWithImportPaths :: Maybe (Set FilePath) -> ShakeExtras -> HscEnv -> [(UnitId, DynFlags)] -> IO HscEnvEq
75+
newHscEnvEqWithImportPaths envImportPaths se hscEnv deps = do
7576

7677
let dflags = hsc_dflags hscEnv
7778

@@ -115,7 +116,7 @@ newHscEnvEqWithImportPaths envImportPaths hscEnv deps = do
115116

116117
-- | Wrap an 'HscEnv' into an 'HscEnvEq'.
117118
newHscEnvEqPreserveImportPaths
118-
:: HscEnv -> [(UnitId, DynFlags)] -> IO HscEnvEq
119+
:: ShakeExtras -> HscEnv -> [(UnitId, DynFlags)] -> IO HscEnvEq
119120
newHscEnvEqPreserveImportPaths = newHscEnvEqWithImportPaths Nothing
120121

121122
-- | Unwrap the 'HscEnv' with the original import paths.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module Development.IDE.Types.HscEnvEq (HscEnvEq) where
2+
3+
import Data.Set (Set)
4+
import Data.Unique (Unique)
5+
import Development.IDE.GHC.Compat
6+
import Development.IDE.Types.Exports (ExportsMap)
7+
8+
-- | An 'HscEnv' with equality. Two values are considered equal
9+
-- if they are created with the same call to 'newHscEnvEq'.
10+
data HscEnvEq = HscEnvEq
11+
{ envUnique :: !Unique
12+
, hscEnv :: !HscEnv
13+
, deps :: [(UnitId, DynFlags)]
14+
-- ^ In memory components for this HscEnv
15+
-- This is only used at the moment for the import dirs in
16+
-- the DynFlags
17+
, envImportPaths :: Maybe (Set FilePath)
18+
-- ^ If Just, import dirs originally configured in this env
19+
-- If Nothing, the env import dirs are unaltered
20+
, envPackageExports :: IO ExportsMap
21+
, envVisibleModuleNames :: IO (Maybe [ModuleName])
22+
-- ^ 'listVisibleModuleNames' is a pure function,
23+
-- but it could panic due to a ghc bug: https://github.com/haskell/haskell-language-server/issues/1365
24+
-- So it's wrapped in IO here for error handling
25+
-- If Nothing, 'listVisibleModuleNames' panic
26+
}

0 commit comments

Comments
 (0)