@@ -19,14 +19,13 @@ module Test.Hls
19
19
where
20
20
21
21
import Control.Applicative.Combinators
22
- import Control.Concurrent ( forkIO , killThread )
22
+ import Control.Concurrent.Async ( withAsync )
23
23
import Control.Exception.Base
24
24
import Control.Monad.IO.Class
25
25
import Data.ByteString.Lazy (ByteString )
26
26
import Data.Default (def )
27
27
import qualified Data.Text as T
28
- import Development.IDE (IdeState , hDuplicateTo' ,
29
- noLogging )
28
+ import Development.IDE (IdeState , hDuplicateTo' )
30
29
import Development.IDE.Main
31
30
import qualified Development.IDE.Main as Ghcide
32
31
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
@@ -80,7 +79,6 @@ muteStderr action = withTempFile $ \tmp ->
80
79
h `hDuplicateTo'` stderr
81
80
bracket_ action (hClose old) (old `hDuplicateTo'` stderr)
82
81
83
-
84
82
-- | Host a server, and run a test session on it
85
83
-- Note: cwd will be shifted into @root@ in @Session a@
86
84
runSessionWithServer' ::
@@ -99,18 +97,17 @@ runSessionWithServer' plugin conf sconf caps root s = do
99
97
(outR, outW) <- createPipe
100
98
-- restore cwd after running the session; otherwise the path to test data will be invalid
101
99
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