@@ -115,39 +115,44 @@ loadCradle iniDynFlags (NewCradle fp) = do
115
115
traceShowM cradle
116
116
liftIO (GHC. newHscEnv iniDynFlags) >>= GHC. setSession
117
117
liftIO $ setCurrentDirectory (BIOS. cradleRootDir cradle)
118
- res <- withProgress " Initialising Cradle" NotCancellable (\ f ->
119
- BIOS. initializeFlagsWithCradleWithMessage (Just (toMessager f)) fp (fixCradle cradle)
120
- )
121
- case res of
122
- BIOS. CradleNone -> return (IdeResultOk () )
123
- BIOS. CradleFail err -> do
124
- logm $ " GhcException on cradle initialisation: " ++ show err
125
- return $ IdeResultFail $ IdeError
126
- { ideCode = OtherError
127
- , ideMessage = Text. pack $ show err
128
- , ideInfo = Aeson. Null
129
- }
130
- BIOS. CradleSuccess init_session -> do
131
- init_res <- gcatches (Right <$> init_session)
132
- [ErrorHandler (\ (ex :: GHC. GhcException )
133
- -> return $ Left (GHC. showGhcException ex " " ))]
134
- case init_res of
135
- Left err -> do
136
- logm $ " GhcException on cradle initialisation: " ++ show err
137
- return $ IdeResultFail $ IdeError
118
+ withProgress " Initialising Cradle" NotCancellable (initialiseCradle cradle)
119
+
120
+ where
121
+ isStackCradle :: BIOS. Cradle -> Bool
122
+ isStackCradle c = BIOS. actionName (BIOS. cradleOptsProg c) == " stack"
123
+
124
+ -- | Initialise the given cradle. This might fail and return an error via `IdeResultFail`.
125
+ initialiseCradle :: (MonadIde m , HasGhcModuleCache m , GHC. GhcMonad m , MonadBaseControl IO m )
126
+ => BIOS. Cradle -> (Progress -> IO () ) -> m (IdeResult () )
127
+ initialiseCradle cradle f = do
128
+ res <- BIOS. initializeFlagsWithCradleWithMessage (Just (toMessager f)) fp (fixCradle cradle)
129
+ case res of
130
+ BIOS. CradleNone -> return (IdeResultOk () )
131
+ BIOS. CradleFail err -> do
132
+ logm $ " GhcException on cradle initialisation: " ++ show err
133
+ return $ IdeResultFail $ IdeError
138
134
{ ideCode = OtherError
139
135
, ideMessage = Text. pack $ show err
140
136
, ideInfo = Aeson. Null
141
137
}
142
- -- Note: Don't setCurrentCradle because we want to try to reload
143
- -- it on a save whilst there are errors. Subsequent loads won't
144
- -- be that slow, even though the cradle isn't cached because the
145
- -- `.hi` files will be saved.
146
- Right () ->
147
- IdeResultOk <$> setCurrentCradle cradle
148
- where
149
- isStackCradle :: BIOS. Cradle -> Bool
150
- isStackCradle c = BIOS. actionName (BIOS. cradleOptsProg c) == " stack"
138
+ BIOS. CradleSuccess init_session -> do
139
+ init_res <- gcatches (Right <$> init_session)
140
+ [ErrorHandler (\ (ex :: GHC. GhcException )
141
+ -> return $ Left (GHC. showGhcException ex " " ))]
142
+ case init_res of
143
+ Left err -> do
144
+ logm $ " GhcException on cradle initialisation: " ++ show err
145
+ return $ IdeResultFail $ IdeError
146
+ { ideCode = OtherError
147
+ , ideMessage = Text. pack $ show err
148
+ , ideInfo = Aeson. Null
149
+ }
150
+ -- Note: Don't setCurrentCradle because we want to try to reload
151
+ -- it on a save whilst there are errors. Subsequent loads won't
152
+ -- be that slow, even though the cradle isn't cached because the
153
+ -- `.hi` files will be saved.
154
+ Right () ->
155
+ IdeResultOk <$> setCurrentCradle cradle
151
156
152
157
-- The stack cradle doesn't return the target as well, so add the
153
158
-- FilePath onto the end of the options to make sure at least one target
0 commit comments