@@ -48,6 +48,7 @@ import Development.IDE.GHC.Compat hiding (Target,
4848 TargetFile , TargetModule )
4949import qualified Development.IDE.GHC.Compat as GHC
5050import Development.IDE.GHC.Util
51+ import Development.IDE.Graph (Action )
5152import Development.IDE.Session.VersionCheck
5253import Development.IDE.Types.Diagnostics
5354import Development.IDE.Types.Exports
@@ -56,7 +57,6 @@ import Development.IDE.Types.HscEnvEq (HscEnvEq, newHscEnvEq,
5657import Development.IDE.Types.Location
5758import Development.IDE.Types.Logger
5859import Development.IDE.Types.Options
59- import Development.IDE.Graph (Action )
6060import GHC.Check
6161import qualified HIE.Bios as HieBios
6262import HIE.Bios.Environment hiding (getCacheDir )
@@ -85,12 +85,10 @@ import Control.Concurrent.STM (atomically)
8585import Control.Concurrent.STM.TQueue
8686import qualified Data.HashSet as Set
8787import Database.SQLite.Simple
88- import HIE.Bios.Cradle ( yamlConfig )
88+ import GHC.LanguageExtensions ( Extension ( EmptyCase ) )
8989import HieDb.Create
9090import HieDb.Types
9191import HieDb.Utils
92- import Maybes (MaybeT (runMaybeT ))
93- import GHC.LanguageExtensions (Extension (EmptyCase ))
9492
9593-- | Bump this version number when making changes to the format of the data stored in hiedb
9694hiedbDataVersion :: String
@@ -100,15 +98,17 @@ data CacheDirs = CacheDirs
10098 { hiCacheDir , hieCacheDir , oCacheDir :: Maybe FilePath }
10199
102100data 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 )
105105 -- | Given the project name and a set of command line flags,
106106 -- return the path for storing generated GHC artifacts,
107107 -- or 'Nothing' to respect the cradle setting
108- , getCacheDirs :: String -> [String ] -> IO CacheDirs
108+ , getCacheDirs :: String -> [String ] -> IO CacheDirs
109109 -- | 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
112112 -- ^ unit id used to tag the internal component built by ghcide
113113 -- To reuse external interface files the unit ids must match,
114114 -- thus make sure to build them with `--this-unit-id` set to the
@@ -118,17 +118,40 @@ data SessionLoadingOptions = SessionLoadingOptions
118118instance Default SessionLoadingOptions where
119119 def = SessionLoadingOptions
120120 {findCradle = HieBios. findCradle
121- ,loadCradle = HieBios. loadCradle
121+ ,loadCradle = loadWithImplicitCradle
122122 ,getCacheDirs = getCacheDirsDefault
123123 ,getInitialGhcLibDir = getInitialGhcLibDirDefault
124124 ,fakeUid = toInstalledUnitId (stringToUnitId " main" )
125125 }
126126
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+
127150getInitialGhcLibDirDefault :: IO (Maybe LibDir )
128151getInitialGhcLibDirDefault = do
129152 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
132155 hPutStrLn stderr $ " setInitialDynFlags cradle: " ++ show cradle
133156 libDirRes <- getRuntimeGhcLibDir cradle
134157 case libDirRes of
@@ -400,7 +423,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
400423 when (isNothing hieYaml) $
401424 logWarning logger $ implicitCradleWarning lfp
402425
403- cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
426+ cradle <- loadCradle hieYaml dir
404427
405428 when optTesting $ mRunLspT lspEnv $
406429 sendNotification (SCustomMethod " ghcide/cradle/loaded" ) (toJSON cfp)
0 commit comments