Skip to content

Commit 92fb93e

Browse files
committed
load modules concurrently purescript#4545
1 parent e06b9cc commit 92fb93e

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

src/Language/PureScript/Ide.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import Language.PureScript.Ide.Util (discardAnn, identifierFromIdeDeclaration, n
4343
import Language.PureScript.Ide.Usage (findUsages)
4444
import System.Directory (getCurrentDirectory, getDirectoryContents, doesDirectoryExist, doesFileExist)
4545
import System.FilePath ((</>), normalise)
46+
import Control.Concurrent.Async.Lifted (mapConcurrently, mapConcurrently_)
4647

4748
-- | Accepts a Command and runs it against psc-ide's State. This is the main
4849
-- entry point for the server.
@@ -219,16 +220,16 @@ loadModules moduleNames = do
219220
oDir <- outputDirectory
220221
let efPaths =
221222
map (\mn -> oDir </> toS (P.runModuleName mn) </> P.externsFileName) moduleNames
222-
efiles <- traverse readExternFile efPaths
223-
traverse_ insertExterns efiles
223+
efiles <- mapConcurrently readExternFile efPaths
224+
mapConcurrently_ insertExterns efiles
224225

225226
-- We parse all source files, log eventual parse failures and insert the
226227
-- successful parses into the state.
227228
(failures, allModules) <-
228229
partitionEithers <$> (parseModulesFromFiles =<< findAllSourceFiles)
229230
unless (null failures) $
230231
logWarnN ("Failed to parse: " <> show failures)
231-
traverse_ insertModule allModules
232+
mapConcurrently_ insertModule allModules
232233

233234
pure (TextResult ("Loaded " <> show (length efiles) <> " modules and "
234235
<> show (length allModules) <> " source files."))

src/Language/PureScript/Ide/Types.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Data.Map.Lazy qualified as M
1818
import Language.PureScript qualified as P
1919
import Language.PureScript.Errors.JSON qualified as P
2020
import Language.PureScript.Ide.Filter.Declaration (DeclarationType(..))
21+
import Control.Monad.Trans.Control (MonadBaseControl)
2122

2223
type ModuleIdent = Text
2324
type ModuleMap a = Map P.ModuleName a
@@ -173,7 +174,7 @@ data IdeEnvironment =
173174
, ideCacheDbTimestamp :: IORef (Maybe UTCTime)
174175
}
175176

176-
type Ide m = (MonadIO m, MonadReader IdeEnvironment m)
177+
type Ide m = (MonadIO m, MonadBaseControl IO m, MonadReader IdeEnvironment m)
177178

178179
data IdeState = IdeState
179180
{ ideFileState :: IdeFileState

0 commit comments

Comments
 (0)