Skip to content

Commit 7a2ff3a

Browse files
committed
Fix cwd
1 parent b43f122 commit 7a2ff3a

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -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@
9094
runSessionWithServer' ::
@@ -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

Comments
 (0)