@@ -85,6 +85,10 @@ silenceStderr action = withTempFile $ \temp ->
8585 hSetBuffering stderr buf
8686 hClose old
8787
88+ -- | Restore cwd after running an action
89+ keepCurrentDirectory :: IO a -> IO a
90+ keepCurrentDirectory = bracket getCurrentDirectory setCurrentDirectory . const
91+
8892-- | Host a server, and run a test session on it
8993-- Note: cwd will be shifted into @root@ in @Session a@
9094runSessionWithServer' ::
@@ -98,11 +102,9 @@ runSessionWithServer' ::
98102 FilePath ->
99103 Session a ->
100104 IO a
101- runSessionWithServer' plugin conf sconf caps root s = do
105+ runSessionWithServer' plugin conf sconf caps root s = keepCurrentDirectory $ do
102106 (inR, inW) <- createPipe
103107 (outR, outW) <- createPipe
104- -- restore cwd after running the session; otherwise the path to test data will be invalid
105- cwd <- getCurrentDirectory
106108 server <-
107109 async $
108110 Ghcide. defaultMain
@@ -115,14 +117,12 @@ runSessionWithServer' plugin conf sconf caps root s = do
115117 in ideOptions {optShakeOptions = (optShakeOptions ideOptions) {shakeThreads = 2 }},
116118 argsHlsPlugins = pluginDescToIdePlugins $ plugin ++ Ghcide. descriptors
117119 }
118-
119120 x <- runSessionWithHandles inW outR sconf caps root s
120121 timeout 3 (wait server) >>= \ case
121122 Just () -> pure ()
122123 Nothing -> do
123124 putStrLn " Server does not exit in 3s, canceling the async task..."
124125 (t, _) <- duration $ cancel server
125126 putStrLn $ " Finishing canceling (took " <> showDuration t <> " s)"
126- setCurrentDirectory cwd
127- sleep 0.05
127+ sleep 0.1
128128 pure x
0 commit comments