@@ -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 = 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
@@ -115,14 +117,12 @@ runSessionWithServer' plugin conf sconf caps root s = do
115
117
in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2 }},
116
118
argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide. descriptors
117
119
}
118
-
119
120
x <- runSessionWithHandles inW outR sconf caps root s
120
121
timeout 3 (wait server) >>= \ case
121
122
Just () -> pure ()
122
123
Nothing -> do
123
124
putStrLn " Server does not exit in 3s, canceling the async task..."
124
125
(t, _) <- duration $ cancel server
125
126
putStrLn $ " Finishing canceling (took " <> showDuration t <> " s)"
126
- setCurrentDirectory cwd
127
- sleep 0.05
127
+ sleep 0.1
128
128
pure x
0 commit comments