Skip to content

Commit c9ed045

Browse files
authored
Do not send Heap Stats to the LSP log (#3111)
1 parent 92f4bd4 commit c9ed045

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

exe/Main.hs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
{-# LANGUAGE OverloadedStrings #-}
66
module Main(main) where
77

8+
import Control.Arrow ((&&&))
89
import Control.Monad.IO.Class (liftIO)
910
import Data.Function ((&))
1011
import Data.Text (Text)
12+
import qualified Development.IDE.Main as GhcideMain
1113
import Development.IDE.Types.Logger (Doc,
1214
Priority (Debug, Error, Info),
1315
WithPriority (WithPriority, priority),
1416
cfilter, cmapWithPrio,
1517
defaultLayoutOptions,
1618
layoutPretty,
1719
makeDefaultStderrRecorder,
18-
renderStrict,
20+
payload, renderStrict,
1921
withDefaultRecorder)
2022
import qualified Development.IDE.Types.Logger as Logger
2123
import Ide.Arguments (Arguments (..),
@@ -62,24 +64,28 @@ main = do
6264
liftIO $ (cb1 <> cb2) env
6365
}
6466

65-
let (minPriority, logFilePath, includeExamplePlugins) =
67+
let (argsTesting, minPriority, logFilePath, includeExamplePlugins) =
6668
case args of
6769
Ghcide GhcideArguments{ argsTesting, argsDebugOn, argsLogFile, argsExamplePlugin } ->
6870
let minPriority = if argsDebugOn || argsTesting then Debug else Info
69-
in (minPriority, argsLogFile, argsExamplePlugin)
70-
_ -> (Info, Nothing, False)
71+
in (argsTesting, minPriority, argsLogFile, argsExamplePlugin)
72+
_ -> (False, Info, Nothing, False)
7173

7274
withDefaultRecorder logFilePath Nothing minPriority $ \textWithPriorityRecorder -> do
7375
let
74-
recorder = cmapWithPrio pretty $ mconcat
76+
recorder = cmapWithPrio (pretty &&& id) $ mconcat
7577
[textWithPriorityRecorder
7678
& cfilter (\WithPriority{ priority } -> priority >= minPriority)
79+
& cmapWithPrio fst
7780
, lspMessageRecorder
7881
& cfilter (\WithPriority{ priority } -> priority >= Error)
79-
& cmapWithPrio renderDoc
82+
& cmapWithPrio (renderDoc . fst)
8083
, lspLogRecorder
8184
& cfilter (\WithPriority{ priority } -> priority >= minPriority)
82-
& cmapWithPrio (renderStrict . layoutPretty defaultLayoutOptions)
85+
& cmapWithPrio (renderStrict . layoutPretty defaultLayoutOptions . fst)
86+
-- do not log heap stats to the LSP log as they interfere with the
87+
-- ability of lsp-test to detect a stuck server in tests and benchmarks
88+
& if argsTesting then cfilter (not . heapStats . snd . payload) else id
8389
]
8490
plugins = (Plugins.idePlugins (cmapWithPrio LogPlugins recorder) includeExamplePlugins)
8591

@@ -96,3 +102,7 @@ renderDoc d = renderStrict $ layoutPretty defaultLayoutOptions $ vsep
96102

97103
issueTrackerUrl :: Doc a
98104
issueTrackerUrl = "https://github.com/haskell/haskell-language-server/issues"
105+
106+
heapStats :: Log -> Bool
107+
heapStats (LogIdeMain (IdeMain.LogIDEMain (GhcideMain.LogHeapStats _))) = True
108+
heapStats _ = False

0 commit comments

Comments
 (0)