@@ -59,6 +59,7 @@ import Language.LSP.Types hiding
5959import Language.LSP.Types.Capabilities (ClientCapabilities )
6060import System.Directory (getCurrentDirectory ,
6161 setCurrentDirectory )
62+ import System.Environment.Blank (getEnvDefault )
6263import System.FilePath
6364import System.IO.Extra
6465import System.IO.Unsafe (unsafePerformIO )
@@ -133,15 +134,19 @@ runSessionWithServerFormatter plugin formatter =
133134
134135-- | Run an action, with stderr silenced
135136silenceStderr :: IO a -> IO a
136- silenceStderr action = withTempFile $ \ temp ->
137- bracket (openFile temp ReadWriteMode ) hClose $ \ h -> do
138- old <- hDuplicate stderr
139- buf <- hGetBuffering stderr
140- h `hDuplicateTo'` stderr
141- action `finally` do
142- old `hDuplicateTo'` stderr
143- hSetBuffering stderr buf
144- hClose old
137+ silenceStderr action = do
138+ showStderr <- getEnvDefault " LSP_TEST_LOG_STDERR" " 0"
139+ case showStderr of
140+ " 0" -> withTempFile $ \ temp ->
141+ bracket (openFile temp ReadWriteMode ) hClose $ \ h -> do
142+ old <- hDuplicate stderr
143+ buf <- hGetBuffering stderr
144+ h `hDuplicateTo'` stderr
145+ action `finally` do
146+ old `hDuplicateTo'` stderr
147+ hSetBuffering stderr buf
148+ hClose old
149+ _ -> action
145150
146151-- | Restore cwd after running an action
147152keepCurrentDirectory :: IO a -> IO a
0 commit comments