Skip to content

Commit 16b3a66

Browse files
committed
Rebase on mpickering ghcide at wip/multi-rebase
Commit 256f8b50415a08454d471a6a28f742c0a1e39978
1 parent 1f56104 commit 16b3a66

File tree

4 files changed

+32
-9
lines changed

4 files changed

+32
-9
lines changed

exe/Arguments.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ data Arguments = Arguments
3636
-- them to just change the name of the exe and still work.
3737
, argsDebugOn :: Bool
3838
, argsLogFile :: Maybe String
39-
, argsThread :: Int
39+
, argsThreads :: Int
4040
} deriving Show
4141

4242
getArguments :: String -> IO Arguments

exe/Main.hs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
module Main(main) where
1414

1515
import Arguments
16+
import Control.Concurrent.Async
1617
import Control.Concurrent.Extra
1718
import Control.Exception
1819
import Control.Monad.Extra
@@ -190,8 +191,8 @@ main = do
190191
{ optReportProgress = clientSupportsProgress caps
191192
, optShakeProfiling = argsShakeProfiling
192193
, optTesting = argsTesting
194+
, optThreads = argsThreads
193195
, optInterfaceLoadingDiagnostics = argsTesting
194-
, optThreads = argsThread
195196
}
196197
debouncer <- newAsyncDebouncer
197198
initialise caps (mainRule >> pluginRules plugins >> action kick)
@@ -408,7 +409,6 @@ loadSession dir = liftIO $ do
408409
return res
409410

410411
lock <- newLock
411-
cradle_lock <- newLock
412412

413413
-- This caches the mapping from hie.yaml + Mod.hs -> [String]
414414
sessionOpts <- return $ \(hieYaml, file) -> do
@@ -435,17 +435,39 @@ loadSession dir = liftIO $ do
435435
finished_barrier <- newBarrier
436436
-- fork a new thread here which won't be killed by shake
437437
-- throwing an async exception
438-
void $ forkIO $ withLock cradle_lock $ do
439-
putStrLn $ "Shelling out to cabal " <> show file
438+
void $ forkIO $ do
439+
putStrLn $ "Consulting the cradle for " <> show file
440440
cradle <- maybe (loadImplicitCradle $ addTrailingPathSeparator dir) loadCradle hieYaml
441441
opts <- cradleToSessionOpts cradle cfp
442442
print opts
443443
res <- fst <$> session (hieYaml, toNormalizedFilePath' cfp, opts)
444444
signalBarrier finished_barrier res
445445
waitBarrier finished_barrier
446-
return $ \file -> liftIO $ mask_ $ withLock lock $ do
447-
hieYaml <- cradleLoc file
448-
sessionOpts (hieYaml, file)
446+
447+
dummyAs <- async $ return (error "Uninitialised")
448+
runningCradle <- newIORef dummyAs
449+
-- The main function which gets options for a file. We only want one of these running
450+
-- at a time.
451+
let getOptions file = do
452+
hieYaml <- cradleLoc file
453+
sessionOpts (hieYaml, file)
454+
-- The lock is on the `runningCradle` resource
455+
return $ \file -> liftIO $ withLock lock $ do
456+
as <- readIORef runningCradle
457+
finished <- poll as
458+
case finished of
459+
Just {} -> do
460+
as <- async $ getOptions file
461+
writeIORef runningCradle as
462+
wait as
463+
-- If it's not finished then wait and then get options, this could of course be killed still
464+
Nothing -> do
465+
_ <- wait as
466+
getOptions file
467+
468+
469+
470+
449471

450472
checkDependencyInfo :: Map.Map FilePath (Maybe UTCTime) -> IO Bool
451473
checkDependencyInfo old_di = do

haskell-language-server.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ executable haskell-language-server
133133
build-depends:
134134
base >=4.7 && <5
135135
, aeson
136+
, async
136137
, base16-bytestring
137138
, binary
138139
, bytestring

0 commit comments

Comments
 (0)