Skip to content

Commit cddcc55

Browse files
committed
Refactors session loading logic
Renames getOptions to getOptionsWorker for clarity Removes redundant getOptionsLoop function Ensures session loading is called under the same `Action` context
1 parent 7314509 commit cddcc55

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,9 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
780780
-- at a time. Therefore the IORef contains the currently running cradle, if we try
781781
-- to get some more options then we wait for the currently running action to finish
782782
-- before attempting to do so.
783-
let getOptions :: FilePath -> IO ()
784-
getOptions file = do
783+
let getOptionsWorker :: FilePath -> IO ()
784+
getOptionsWorker file = do
785+
logWith recorder Info (LogGetOptionsLoop file)
785786
let ncfp = toNormalizedFilePath' file
786787
cachedHieYamlLocation <- atomically $ STM.lookup ncfp filesMap
787788
hieYaml <- cradleLoc file
@@ -795,14 +796,6 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
795796
-- delete file from pending files
796797
S.delete file pendingFileSet
797798

798-
let getOptionsLoop :: IO ()
799-
getOptionsLoop = do
800-
-- Get the next file to load
801-
absFile <- atomically $ S.readQueue pendingFileSet
802-
logWith recorder Info (LogGetOptionsLoop absFile)
803-
getOptions absFile
804-
getOptionsLoop
805-
806799
-- | Given a file, this function will return the HscEnv and the dependencies
807800
-- it would look up the cache first, if the cache is not available, it would
808801
-- submit a request to the getOptionsLoop to get the options for the file
@@ -828,11 +821,12 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
828821
Nothing -> do
829822
-- if not ok, we need to reload the session
830823
atomically $ S.insert absFile pendingFileSet
824+
-- line up the session to load
825+
atomically $ writeTQueue que (getOptionsWorker absFile)
831826
lookupOrWaitCache absFile
832827

833828
-- see Note [Serializing runs in separate thread]
834829
-- Start the getOptionsLoop if the queue is empty
835-
liftIO $ atomically $ Extra.whenM (isEmptyTQueue que) $ writeTQueue que getOptionsLoop
836830
returnWithVersion $ \file -> do
837831
let absFile = toAbsolutePath file
838832
second Map.keys <$> lookupOrWaitCache absFile

0 commit comments

Comments
 (0)