Skip to content

Commit 7690955

Browse files
committed
Use async
1 parent 12c3d41 commit 7690955

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

hls-test-utils/hls-test-utils.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ library
5959
, temporary
6060
, text
6161
, unordered-containers
62+
, async
6263

6364
ghc-options: -Wall
6465

hls-test-utils/src/Test/Hls.hs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ module Test.Hls
1919
where
2020

2121
import Control.Applicative.Combinators
22-
import Control.Concurrent (forkIO, killThread)
22+
import Control.Concurrent.Async (withAsync)
2323
import Control.Exception.Base
2424
import Control.Monad.IO.Class
2525
import Data.ByteString.Lazy (ByteString)
2626
import Data.Default (def)
2727
import qualified Data.Text as T
28-
import Development.IDE (IdeState, hDuplicateTo',
29-
noLogging)
28+
import Development.IDE (IdeState, hDuplicateTo')
3029
import Development.IDE.Main
3130
import qualified Development.IDE.Main as Ghcide
3231
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
@@ -80,7 +79,6 @@ muteStderr action = withTempFile $ \tmp ->
8079
h `hDuplicateTo'` stderr
8180
bracket_ action (hClose old) (old `hDuplicateTo'` stderr)
8281

83-
8482
-- | Host a server, and run a test session on it
8583
-- Note: cwd will be shifted into @root@ in @Session a@
8684
runSessionWithServer' ::
@@ -99,18 +97,17 @@ runSessionWithServer' plugin conf sconf caps root s = do
9997
(outR, outW) <- createPipe
10098
-- restore cwd after running the session; otherwise the path to test data will be invalid
10199
cwd <- getCurrentDirectory
102-
threadId <-
103-
forkIO $
104-
Ghcide.defaultMain
105-
def
106-
{ argsHandleIn = pure inR,
107-
argsHandleOut = pure outW,
108-
argsLogger = pure noLogging,
109-
argsDefaultHlsConfig = conf,
110-
argsIdeOptions = \config sessionLoader ->
111-
let ideOptions = (argsIdeOptions def config sessionLoader) {optTesting = IdeTesting True}
112-
in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2}},
113-
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide.descriptors
114-
}
115-
runSessionWithHandles inW outR sconf caps root s
116-
`finally` (killThread threadId >> setCurrentDirectory cwd)
100+
let server =
101+
Ghcide.defaultMain
102+
def
103+
{ argsHandleIn = pure inR,
104+
argsHandleOut = pure outW,
105+
argsDefaultHlsConfig = conf,
106+
argsIdeOptions = \config sessionLoader ->
107+
let ideOptions = (argsIdeOptions def config sessionLoader) {optTesting = IdeTesting True}
108+
in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2}},
109+
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide.descriptors
110+
}
111+
withAsync server $ \_ ->
112+
runSessionWithHandles inW outR sconf caps root s
113+
`finally` setCurrentDirectory cwd

0 commit comments

Comments
 (0)