From 8845867fca2d8abc482b2b515a54673a2ddbc717 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Wed, 17 Aug 2022 10:50:21 +0200 Subject: [PATCH 1/4] Do not send Heap Stats to the LSP log It interferes with the ability of lsp-test to detect timeouts in e.g. benchmarks The assumption is that logging them to stderr serves the purpose they were designed for. --- exe/Main.hs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/exe/Main.hs b/exe/Main.hs index 098a427ef9..c35b84657f 100644 --- a/exe/Main.hs +++ b/exe/Main.hs @@ -8,6 +8,8 @@ module Main(main) where import Control.Monad.IO.Class (liftIO) import Data.Function ((&)) import Data.Text (Text) +import qualified Development.IDE.Main as GhcideMain +import qualified Development.IDE.Main.HeapStats as HeapStats import Development.IDE.Types.Logger (Doc, Priority (Debug, Error, Info), WithPriority (WithPriority, priority), @@ -16,7 +18,7 @@ import Development.IDE.Types.Logger (Doc, layoutPretty, makeDefaultStderrRecorder, renderStrict, - withDefaultRecorder) + withDefaultRecorder, payload) import qualified Development.IDE.Types.Logger as Logger import Ide.Arguments (Arguments (..), GhcideArguments (..), @@ -32,6 +34,7 @@ import Language.LSP.Types as LSP import qualified Plugins #if MIN_VERSION_prettyprinter(1,7,0) import Prettyprinter (Pretty (pretty), vsep) +import Control.Arrow ((&&&)) #else import Data.Text.Prettyprint.Doc (Pretty (pretty), vsep) #endif @@ -71,15 +74,19 @@ main = do 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 + & cfilter (not . heapStats . snd . payload) ] plugins = (Plugins.idePlugins (cmapWithPrio LogPlugins recorder) includeExamplePlugins) @@ -96,3 +103,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 From 30e86f5a841fae67cc456fdcbb47adeeeed9220b Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Wed, 17 Aug 2022 18:59:35 +0200 Subject: [PATCH 2/4] Fix imports --- exe/Main.hs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/exe/Main.hs b/exe/Main.hs index c35b84657f..e8793c8839 100644 --- a/exe/Main.hs +++ b/exe/Main.hs @@ -5,11 +5,11 @@ {-# 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 qualified Development.IDE.Main.HeapStats as HeapStats import Development.IDE.Types.Logger (Doc, Priority (Debug, Error, Info), WithPriority (WithPriority, priority), @@ -34,7 +34,6 @@ import Language.LSP.Types as LSP import qualified Plugins #if MIN_VERSION_prettyprinter(1,7,0) import Prettyprinter (Pretty (pretty), vsep) -import Control.Arrow ((&&&)) #else import Data.Text.Prettyprint.Doc (Pretty (pretty), vsep) #endif From b39b1126ccd075a6cea74daee5801949e051dd45 Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Wed, 17 Aug 2022 21:00:45 +0200 Subject: [PATCH 3/4] Formatting --- exe/Main.hs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exe/Main.hs b/exe/Main.hs index e8793c8839..4ea67f49ea 100644 --- a/exe/Main.hs +++ b/exe/Main.hs @@ -5,11 +5,11 @@ {-# LANGUAGE OverloadedStrings #-} module Main(main) where -import Control.Arrow ((&&&)) +import Control.Arrow ((&&&)) import Control.Monad.IO.Class (liftIO) import Data.Function ((&)) import Data.Text (Text) -import qualified Development.IDE.Main as GhcideMain +import qualified Development.IDE.Main as GhcideMain import Development.IDE.Types.Logger (Doc, Priority (Debug, Error, Info), WithPriority (WithPriority, priority), @@ -17,8 +17,8 @@ import Development.IDE.Types.Logger (Doc, defaultLayoutOptions, layoutPretty, makeDefaultStderrRecorder, - renderStrict, - withDefaultRecorder, payload) + payload, renderStrict, + withDefaultRecorder) import qualified Development.IDE.Types.Logger as Logger import Ide.Arguments (Arguments (..), GhcideArguments (..), @@ -105,4 +105,4 @@ issueTrackerUrl = "https://github.com/haskell/haskell-language-server/issues" heapStats :: Log -> Bool heapStats (LogIdeMain (IdeMain.LogIDEMain (GhcideMain.LogHeapStats _))) = True -heapStats _ = False +heapStats _ = False From eb320214c1daefde15e7787596e92e0d8885c9cc Mon Sep 17 00:00:00 2001 From: Pepe Iborra Date: Wed, 17 Aug 2022 23:25:59 +0200 Subject: [PATCH 4/4] guard with argsTesting --- exe/Main.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/exe/Main.hs b/exe/Main.hs index 4ea67f49ea..083f76a1b4 100644 --- a/exe/Main.hs +++ b/exe/Main.hs @@ -64,12 +64,12 @@ 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 @@ -85,7 +85,7 @@ main = do & 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 - & cfilter (not . heapStats . snd . payload) + & if argsTesting then cfilter (not . heapStats . snd . payload) else id ] plugins = (Plugins.idePlugins (cmapWithPrio LogPlugins recorder) includeExamplePlugins)