Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Do not send Heap Stats to the LSP log #3111

Merged
merged 4 commits into from
Aug 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
{-# LANGUAGE OverloadedStrings #-}
module Main(main) where

import Control.Arrow ((&&&))
import Control.Monad.IO.Class (liftIO)
import Data.Function ((&))
import Data.Text (Text)
import qualified Development.IDE.Main as GhcideMain
import Development.IDE.Types.Logger (Doc,
Priority (Debug, Error, Info),
WithPriority (WithPriority, priority),
cfilter, cmapWithPrio,
defaultLayoutOptions,
layoutPretty,
makeDefaultStderrRecorder,
renderStrict,
payload, renderStrict,
withDefaultRecorder)
import qualified Development.IDE.Types.Logger as Logger
import Ide.Arguments (Arguments (..),
Expand Down Expand Up @@ -62,24 +64,28 @@ main = do
liftIO $ (cb1 <> cb2) env
}

let (minPriority, logFilePath, includeExamplePlugins) =
let (argsTesting, minPriority, logFilePath, includeExamplePlugins) =
case args of
Ghcide GhcideArguments{ argsTesting, argsDebugOn, argsLogFile, argsExamplePlugin } ->
let minPriority = if argsDebugOn || argsTesting then Debug else Info
in (minPriority, argsLogFile, argsExamplePlugin)
_ -> (Info, Nothing, False)
in (argsTesting, minPriority, argsLogFile, argsExamplePlugin)
_ -> (False, Info, Nothing, False)

withDefaultRecorder logFilePath Nothing minPriority $ \textWithPriorityRecorder -> do
let
recorder = cmapWithPrio pretty $ mconcat
recorder = cmapWithPrio (pretty &&& id) $ mconcat
[textWithPriorityRecorder
& cfilter (\WithPriority{ priority } -> priority >= minPriority)
& cmapWithPrio fst
, lspMessageRecorder
& cfilter (\WithPriority{ priority } -> priority >= Error)
& cmapWithPrio renderDoc
& cmapWithPrio (renderDoc . fst)
, lspLogRecorder
& cfilter (\WithPriority{ priority } -> priority >= minPriority)
& cmapWithPrio (renderStrict . layoutPretty defaultLayoutOptions)
& cmapWithPrio (renderStrict . layoutPretty defaultLayoutOptions . fst)
-- do not log heap stats to the LSP log as they interfere with the
-- ability of lsp-test to detect a stuck server in tests and benchmarks
& if argsTesting then cfilter (not . heapStats . snd . payload) else id
]
plugins = (Plugins.idePlugins (cmapWithPrio LogPlugins recorder) includeExamplePlugins)

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

issueTrackerUrl :: Doc a
issueTrackerUrl = "https://github.com/haskell/haskell-language-server/issues"

heapStats :: Log -> Bool
heapStats (LogIdeMain (IdeMain.LogIDEMain (GhcideMain.LogHeapStats _))) = True
heapStats _ = False