@@ -48,6 +48,7 @@ import Development.IDE.GHC.Compat hiding (Target,
48
48
TargetFile , TargetModule )
49
49
import qualified Development.IDE.GHC.Compat as GHC
50
50
import Development.IDE.GHC.Util
51
+ import Development.IDE.Graph (Action )
51
52
import Development.IDE.Session.VersionCheck
52
53
import Development.IDE.Types.Diagnostics
53
54
import Development.IDE.Types.Exports
@@ -56,7 +57,6 @@ import Development.IDE.Types.HscEnvEq (HscEnvEq, newHscEnvEq,
56
57
import Development.IDE.Types.Location
57
58
import Development.IDE.Types.Logger
58
59
import Development.IDE.Types.Options
59
- import Development.IDE.Graph (Action )
60
60
import GHC.Check
61
61
import qualified HIE.Bios as HieBios
62
62
import HIE.Bios.Environment hiding (getCacheDir )
@@ -85,12 +85,10 @@ import Control.Concurrent.STM (atomically)
85
85
import Control.Concurrent.STM.TQueue
86
86
import qualified Data.HashSet as Set
87
87
import Database.SQLite.Simple
88
- import HIE.Bios.Cradle ( yamlConfig )
88
+ import GHC.LanguageExtensions ( Extension ( EmptyCase ) )
89
89
import HieDb.Create
90
90
import HieDb.Types
91
91
import HieDb.Utils
92
- import Maybes (MaybeT (runMaybeT ))
93
- import GHC.LanguageExtensions (Extension (EmptyCase ))
94
92
95
93
-- | Bump this version number when making changes to the format of the data stored in hiedb
96
94
hiedbDataVersion :: String
@@ -100,15 +98,17 @@ data CacheDirs = CacheDirs
100
98
{ hiCacheDir , hieCacheDir , oCacheDir :: Maybe FilePath }
101
99
102
100
data SessionLoadingOptions = SessionLoadingOptions
103
- { findCradle :: FilePath -> IO (Maybe FilePath )
104
- , loadCradle :: FilePath -> IO (HieBios. Cradle Void )
101
+ { findCradle :: FilePath -> IO (Maybe FilePath )
102
+ -- | Load the cradle for give Config. If the config is 'Nothing', use the provided
103
+ -- project root directory to determine the 'Cradle' type.
104
+ , loadCradle :: Maybe FilePath -> FilePath -> IO (HieBios. Cradle Void )
105
105
-- | Given the project name and a set of command line flags,
106
106
-- return the path for storing generated GHC artifacts,
107
107
-- or 'Nothing' to respect the cradle setting
108
- , getCacheDirs :: String -> [String ] -> IO CacheDirs
108
+ , getCacheDirs :: String -> [String ] -> IO CacheDirs
109
109
-- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
110
- , getInitialGhcLibDir :: IO (Maybe LibDir )
111
- , fakeUid :: InstalledUnitId
110
+ , getInitialGhcLibDir :: IO (Maybe LibDir )
111
+ , fakeUid :: InstalledUnitId
112
112
-- ^ unit id used to tag the internal component built by ghcide
113
113
-- To reuse external interface files the unit ids must match,
114
114
-- thus make sure to build them with `--this-unit-id` set to the
@@ -118,17 +118,40 @@ data SessionLoadingOptions = SessionLoadingOptions
118
118
instance Default SessionLoadingOptions where
119
119
def = SessionLoadingOptions
120
120
{findCradle = HieBios. findCradle
121
- ,loadCradle = HieBios. loadCradle
121
+ ,loadCradle = loadWithImplicitCradle
122
122
,getCacheDirs = getCacheDirsDefault
123
123
,getInitialGhcLibDir = getInitialGhcLibDirDefault
124
124
,fakeUid = toInstalledUnitId (stringToUnitId " main" )
125
125
}
126
126
127
+ -- | Find the cradle for a given 'hie.yaml' configuration.
128
+ --
129
+ -- If a 'hie.yaml' is given, the cradle is read from the config.
130
+ -- If this config does not comply to the "hie.yaml"
131
+ -- specification, an error is raised.
132
+ --
133
+ -- If no location for "hie.yaml" is provided, the implicit config is used
134
+ -- using the provided root directory for discovering the project.
135
+ -- The implicit config uses different heuristics to determine the type
136
+ -- of the project that may or may not be accurate.
137
+ loadWithImplicitCradle :: Maybe FilePath
138
+ -- ^ Optional 'hie.yaml' location. Will be used if given.
139
+ -> FilePath
140
+ -- ^ Root directory of the project. Required as a fallback
141
+ -- if no 'hie.yaml' location is given.
142
+ -> IO (HieBios. Cradle Void )
143
+ loadWithImplicitCradle mHieYaml rootDir = do
144
+ crdl <- case mHieYaml of
145
+ Just yaml -> do
146
+ HieBios. loadCradle yaml
147
+ Nothing -> loadImplicitHieCradle $ addTrailingPathSeparator rootDir
148
+ return crdl
149
+
127
150
getInitialGhcLibDirDefault :: IO (Maybe LibDir )
128
151
getInitialGhcLibDirDefault = do
129
152
dir <- IO. getCurrentDirectory
130
- hieYaml <- runMaybeT $ yamlConfig dir
131
- cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) HieBios. loadCradle hieYaml
153
+ hieYaml <- findCradle def dir
154
+ cradle <- loadCradle def hieYaml dir
132
155
hPutStrLn stderr $ " setInitialDynFlags cradle: " ++ show cradle
133
156
libDirRes <- getRuntimeGhcLibDir cradle
134
157
case libDirRes of
@@ -400,7 +423,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
400
423
when (isNothing hieYaml) $
401
424
logWarning logger $ implicitCradleWarning lfp
402
425
403
- cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
426
+ cradle <- loadCradle hieYaml dir
404
427
405
428
when optTesting $ mRunLspT lspEnv $
406
429
sendNotification (SCustomMethod " ghcide/cradle/loaded" ) (toJSON cfp)
0 commit comments