Skip to content

Commit 1cd28fe

Browse files
committed
Change the default logger to print to stderr
1 parent 19884fc commit 1cd28fe

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

ghcide/src/Development/IDE/Main.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import Data.List.Extra (
1616
)
1717
import Data.Maybe (catMaybes, fromMaybe, isJust)
1818
import qualified Data.Text as T
19-
import Development.IDE (Action, Rules, noLogging)
19+
import qualified Data.Text.IO as T
20+
import Development.IDE (Action, Rules, Priority)
2021
import Development.IDE.Core.Debouncer (newAsyncDebouncer)
2122
import Development.IDE.Core.FileStore (makeVFSHandle)
2223
import Development.IDE.Core.OfInterest (
@@ -49,7 +50,6 @@ import Development.IDE.Plugin (
4950
import Development.IDE.Plugin.HLS (asGhcIdePlugin)
5051
import Development.IDE.Session (SessionLoadingOptions, loadSessionWithOptions, setInitialDynFlags, getHieDbLoc, runWithDb)
5152
import Development.IDE.Types.Location (toNormalizedFilePath')
52-
import Development.IDE.Types.Logger (Logger)
5353
import Development.IDE.Types.Options (
5454
IdeGhcSession,
5555
IdeOptions (optCheckParents, optCheckProject, optReportProgress),
@@ -66,10 +66,11 @@ import qualified Language.LSP.Server as LSP
6666
import qualified System.Directory.Extra as IO
6767
import System.Exit (ExitCode (ExitFailure), exitWith)
6868
import System.FilePath (takeExtension, takeFileName)
69-
import System.IO (hPutStrLn, hSetEncoding, stderr, stdout, utf8)
69+
import System.IO (hSetBuffering, hPutStrLn, hSetEncoding, stderr, stdout, utf8, BufferMode (LineBuffering))
7070
import System.Time.Extra (offsetTime, showDuration)
7171
import Text.Printf (printf)
7272
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
73+
import Development.IDE.Types.Logger (Logger(Logger))
7374

7475
data Arguments = Arguments
7576
{ argsOTMemoryProfiling :: Bool
@@ -89,7 +90,7 @@ instance Default Arguments where
8990
def = Arguments
9091
{ argsOTMemoryProfiling = False
9192
, argFiles = Nothing
92-
, argsLogger = noLogging
93+
, argsLogger = Logger stderrLogger
9394
, argsRules = mainRule >> action kick
9495
, argsGhcidePlugin = mempty
9596
, argsHlsPlugins = pluginDescToIdePlugins Ghcide.descriptors
@@ -100,9 +101,15 @@ instance Default Arguments where
100101
, argsGetHieDbLoc = getHieDbLoc
101102
}
102103

104+
-- | Cheap stderr logger that relies on LineBuffering
105+
stderrLogger :: Priority -> T.Text -> IO ()
106+
stderrLogger p m =
107+
T.hPutStrLn stderr $ "[" <> T.pack(show p) <> "] " <> m
108+
103109
defaultMain :: Arguments -> IO ()
104110
defaultMain Arguments{..} = do
105111
pid <- T.pack . show <$> getProcessID
112+
hSetBuffering stderr LineBuffering
106113

107114
let hlsPlugin = asGhcIdePlugin argsDefaultHlsConfig argsHlsPlugins
108115
hlsCommands = allLspCmdIds' pid argsHlsPlugins

0 commit comments

Comments
 (0)