@@ -47,6 +47,7 @@ import Development.IDE.GHC.Compat hiding (Target,
4747 TargetFile , TargetModule )
4848import qualified Development.IDE.GHC.Compat as GHC
4949import Development.IDE.GHC.Util
50+ import Development.IDE.Graph (Action )
5051import Development.IDE.Session.VersionCheck
5152import Development.IDE.Types.Diagnostics
5253import Development.IDE.Types.Exports
@@ -55,7 +56,6 @@ import Development.IDE.Types.HscEnvEq (HscEnvEq, newHscEnvEq,
5556import Development.IDE.Types.Location
5657import Development.IDE.Types.Logger
5758import Development.IDE.Types.Options
58- import Development.IDE.Graph (Action )
5959import GHC.Check
6060import qualified HIE.Bios as HieBios
6161import HIE.Bios.Environment hiding (getCacheDir )
@@ -84,12 +84,10 @@ import Control.Concurrent.STM (atomically)
8484import Control.Concurrent.STM.TQueue
8585import qualified Data.HashSet as Set
8686import Database.SQLite.Simple
87- import HIE.Bios.Cradle ( yamlConfig )
87+ import GHC.LanguageExtensions ( Extension ( EmptyCase ) )
8888import HieDb.Create
8989import HieDb.Types
9090import HieDb.Utils
91- import Maybes (MaybeT (runMaybeT ))
92- import GHC.LanguageExtensions (Extension (EmptyCase ))
9391
9492-- | Bump this version number when making changes to the format of the data stored in hiedb
9593hiedbDataVersion :: String
@@ -99,15 +97,18 @@ data CacheDirs = CacheDirs
9997 { hiCacheDir , hieCacheDir , oCacheDir :: Maybe FilePath }
10098
10199data SessionLoadingOptions = SessionLoadingOptions
102- { findCradle :: FilePath -> IO (Maybe FilePath )
103- , loadCradle :: FilePath -> IO (HieBios. Cradle Void )
100+ { findCradle :: FilePath -> IO (Maybe FilePath )
101+ -- | Load the cradle with an optional 'hie.yaml' location.
102+ -- If a 'hie.yaml' is given, use it to load the cradle.
103+ -- Otherwise, use the provided project root directory to determine the cradle type.
104+ , loadCradle :: Maybe FilePath -> FilePath -> IO (HieBios. Cradle Void )
104105 -- | Given the project name and a set of command line flags,
105106 -- return the path for storing generated GHC artifacts,
106107 -- or 'Nothing' to respect the cradle setting
107- , getCacheDirs :: String -> [String ] -> IO CacheDirs
108+ , getCacheDirs :: String -> [String ] -> IO CacheDirs
108109 -- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
109- , getInitialGhcLibDir :: IO (Maybe LibDir )
110- , fakeUid :: InstalledUnitId
110+ , getInitialGhcLibDir :: IO (Maybe LibDir )
111+ , fakeUid :: InstalledUnitId
111112 -- ^ unit id used to tag the internal component built by ghcide
112113 -- To reuse external interface files the unit ids must match,
113114 -- thus make sure to build them with `--this-unit-id` set to the
@@ -117,17 +118,39 @@ data SessionLoadingOptions = SessionLoadingOptions
117118instance Default SessionLoadingOptions where
118119 def = SessionLoadingOptions
119120 {findCradle = HieBios. findCradle
120- ,loadCradle = HieBios. loadCradle
121+ ,loadCradle = loadWithImplicitCradle
121122 ,getCacheDirs = getCacheDirsDefault
122123 ,getInitialGhcLibDir = getInitialGhcLibDirDefault
123124 ,fakeUid = toInstalledUnitId (stringToUnitId " main" )
124125 }
125126
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 -> HieBios. loadCradle yaml
146+ Nothing -> loadImplicitHieCradle $ addTrailingPathSeparator rootDir
147+ return crdl
148+
126149getInitialGhcLibDirDefault :: IO (Maybe LibDir )
127150getInitialGhcLibDirDefault = do
128151 dir <- IO. getCurrentDirectory
129- hieYaml <- runMaybeT $ yamlConfig dir
130- cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) HieBios. loadCradle hieYaml
152+ hieYaml <- findCradle def dir
153+ cradle <- loadCradle def hieYaml dir
131154 hPutStrLn stderr $ " setInitialDynFlags cradle: " ++ show cradle
132155 libDirRes <- getRuntimeGhcLibDir cradle
133156 case libDirRes of
@@ -399,7 +422,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
399422 when (isNothing hieYaml) $
400423 logWarning logger $ implicitCradleWarning lfp
401424
402- cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
425+ cradle <- loadCradle hieYaml dir
403426
404427 when optTesting $ mRunLspT lspEnv $
405428 sendNotification (SCustomMethod " ghcide/cradle/loaded" ) (toJSON cfp)
0 commit comments