@@ -85,6 +85,10 @@ silenceStderr action = withTempFile $ \temp ->
85
85
hSetBuffering stderr buf
86
86
hClose old
87
87
88
+ -- | Restore cwd after running an action
89
+ keepCurrentDirectory :: IO a -> IO a
90
+ keepCurrentDirectory = bracket getCurrentDirectory setCurrentDirectory . const
91
+
88
92
-- | Host a server, and run a test session on it
89
93
-- Note: cwd will be shifted into @root@ in @Session a@
90
94
runSessionWithServer' ::
@@ -98,11 +102,9 @@ runSessionWithServer' ::
98
102
FilePath ->
99
103
Session a ->
100
104
IO a
101
- runSessionWithServer' plugin conf sconf caps root s = silenceStderr $ do
105
+ runSessionWithServer' plugin conf sconf caps root s = keepCurrentDirectory $ do
102
106
(inR, inW) <- createPipe
103
107
(outR, outW) <- createPipe
104
- -- restore cwd after running the session; otherwise the path to test data will be invalid
105
- cwd <- getCurrentDirectory
106
108
server <-
107
109
async $
108
110
Ghcide. defaultMain
@@ -116,11 +118,12 @@ runSessionWithServer' plugin conf sconf caps root s = silenceStderr $ do
116
118
in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2 }},
117
119
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide. descriptors
118
120
}
119
-
120
- x <-
121
- runSessionWithHandles inW outR sconf caps root s
122
- `finally` setCurrentDirectory cwd
121
+ x <- runSessionWithHandles inW outR sconf caps root s
123
122
timeout 3 (wait server) >>= \ case
124
123
Just () -> pure ()
125
- Nothing -> putStrLn " Server does not exit on time, canceling the async task..." >> cancel server
124
+ Nothing -> do
125
+ putStrLn " Server does not exit in 3s, canceling the async task..."
126
+ (t, _) <- duration $ cancel server
127
+ putStrLn $ " Finishing canceling (took " <> showDuration t <> " s)"
128
+ sleep 0.1
126
129
pure x
0 commit comments