3
3
{-|
4
4
The logic for setting up a ghcide session by tapping into hie-bios.
5
5
-}
6
- module Development.IDE.Session (loadSession ) where
6
+ module Development.IDE.Session
7
+ (SessionLoadingOptions (.. )
8
+ ,defaultLoadingOptions
9
+ ,loadSession
10
+ ,loadSessionWithOptions
11
+ ) where
7
12
8
13
-- Unfortunately, we cannot use loadSession with ghc-lib since hie-bios uses
9
14
-- the real GHC library and the types are incompatible. Furthermore, when
@@ -44,7 +49,7 @@ import Development.IDE.Types.Logger
44
49
import Development.IDE.Types.Options
45
50
import Development.Shake (Action )
46
51
import GHC.Check
47
- import HIE.Bios
52
+ import qualified HIE.Bios as HieBios
48
53
import HIE.Bios.Environment hiding (getCacheDir )
49
54
import HIE.Bios.Types
50
55
import Hie.Implicit.Cradle (loadImplicitHieCradle )
@@ -64,6 +69,18 @@ import Module
64
69
import NameCache
65
70
import Packages
66
71
import Control.Exception (evaluate )
72
+ import Data.Void
73
+
74
+ data SessionLoadingOptions = SessionLoadingOptions
75
+ { findCradle :: FilePath -> IO (Maybe FilePath )
76
+ , loadCradle :: FilePath -> IO (HieBios. Cradle Void )
77
+ }
78
+
79
+ defaultLoadingOptions :: SessionLoadingOptions
80
+ defaultLoadingOptions = SessionLoadingOptions
81
+ {findCradle = HieBios. findCradle
82
+ ,loadCradle = HieBios. loadCradle
83
+ }
67
84
68
85
-- | Given a root directory, return a Shake 'Action' which setups an
69
86
-- 'IdeGhcSession' given a file.
@@ -79,7 +96,10 @@ import Control.Exception (evaluate)
79
96
-- components mapping to the same hie.yaml file are mapped to the same
80
97
-- HscEnv which is updated as new components are discovered.
81
98
loadSession :: FilePath -> IO (Action IdeGhcSession )
82
- loadSession dir = do
99
+ loadSession = loadSessionWithOptions defaultLoadingOptions
100
+
101
+ loadSessionWithOptions :: SessionLoadingOptions -> FilePath -> IO (Action IdeGhcSession )
102
+ loadSessionWithOptions SessionLoadingOptions {.. } dir = do
83
103
-- Mapping from hie.yaml file to HscEnv, one per hie.yaml file
84
104
hscEnvs <- newVar Map. empty :: IO (Var HieMap )
85
105
-- Mapping from a Filepath to HscEnv
0 commit comments