Skip to content

Commit bcc4b96

Browse files
committed
Add logging
It piggy-backs existing args from ghcide, probably a bad idea
1 parent e27c7c6 commit bcc4b96

File tree

9 files changed

+66
-25
lines changed

9 files changed

+66
-25
lines changed

exe/Main.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import Development.IDE.Types.Options
4242
import Development.Shake (Action, Rules, action)
4343
import HIE.Bios
4444
import qualified Language.Haskell.LSP.Core as LSP
45+
import Ide.Logger
4546
import Ide.Plugin
4647
import Ide.Plugin.Config
4748
import Language.Haskell.LSP.Messages
@@ -53,6 +54,7 @@ import qualified System.Directory.Extra as IO
5354
import System.Exit
5455
import System.FilePath
5556
import System.IO
57+
import System.Log.Logger as L
5658
import System.Time.Extra
5759

5860
-- ---------------------------------------------------------------------
@@ -147,6 +149,11 @@ main = do
147149
if argsVersion then ghcideVersion >>= putStrLn >> exitSuccess
148150
else hPutStrLn stderr {- see WARNING above -} =<< ghcideVersion
149151

152+
-- LSP.setupLogger (optLogFile opts) ["hie", "hie-bios"]
153+
-- $ if optDebugOn opts then L.DEBUG else L.INFO
154+
LSP.setupLogger argsShakeProfiling ["hie", "hie-bios"]
155+
$ if argsTesting then L.DEBUG else L.INFO
156+
150157
-- lock to avoid overlapping output on stdout
151158
lock <- newLock
152159
let logger p = Logger $ \pri msg -> when (pri >= p) $ withLock lock $
@@ -177,7 +184,7 @@ main = do
177184
}
178185
debouncer <- newAsyncDebouncer
179186
initialise caps (cradleRules >> mainRule >> pluginRules plugins >> action kick)
180-
getLspId event (logger minBound) debouncer options vfs
187+
getLspId event hlsLogger debouncer options vfs
181188
else do
182189
putStrLn $ "(haskell-language-server)Ghcide setup tester in " ++ dir ++ "."
183190
putStrLn "Report bugs at https://github.com/haskell/haskell-language-server/issues"

exe/Wrapper.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import Data.List
1818
-- import qualified Data.Text.IO as T
1919
-- import Development.IDE.Types.Logger
2020
import HIE.Bios
21-
import Ide.Cradle (findLocalCradle, logm)
21+
import Ide.Cradle (findLocalCradle)
22+
import Ide.Logger (logm)
2223
import Ide.Version
2324
import System.Directory
2425
import System.Environment

haskell-language-server.cabal

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ library
2929
exposed-modules:
3030
Ide.Compat
3131
Ide.Cradle
32+
Ide.Logger
3233
Ide.Plugin
3334
Ide.Plugin.Config
3435
Ide.Plugin.Example
@@ -137,6 +138,7 @@ executable haskell-language-server
137138
, haskell-lsp
138139
, hie-bios >= 0.4
139140
, haskell-language-server
141+
, hslogger
140142
, optparse-applicative
141143
, shake >= 0.17.5
142144
, text

src/Ide/Cradle.hs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
module Ide.Cradle where
77

88
import Control.Exception
9-
import Control.Monad.IO.Class
109
import Data.Foldable (toList)
1110
import Data.Function ((&))
1211
import Data.List (isPrefixOf, sortOn, find)
@@ -24,6 +23,7 @@ import Distribution.Helper (Package, projectPackages, pUnits,
2423
Unit, unitInfo, uiComponents,
2524
ChEntrypoint(..), UnitInfo(..))
2625
import Distribution.Helper.Discover (findProjects, getDefaultDistDir)
26+
import Ide.Logger
2727
import HIE.Bios as Bios
2828
import qualified HIE.Bios.Cradle as Bios
2929
import HIE.Bios.Types (CradleAction(..))
@@ -32,7 +32,7 @@ import System.Directory (getCurrentDirectory, canonicalizePath, findEx
3232
import System.Exit
3333
import System.FilePath
3434
import System.Log.Logger
35-
import System.Process (readCreateProcessWithExitCode, shell, CreateProcess(..))
35+
import System.Process (readCreateProcessWithExitCode, shell)
3636

3737

3838
-- ---------------------------------------------------------------------
@@ -903,17 +903,3 @@ cradleDisplay cradle = fromString result
903903
name = Bios.actionName (Bios.cradleOptsProg cradle)
904904

905905
-- ---------------------------------------------------------------------
906-
907-
logm :: MonadIO m => String -> m ()
908-
logm s = liftIO $ infoM "hie" s
909-
910-
debugm :: MonadIO m => String -> m ()
911-
debugm s = liftIO $ debugM "hie" s
912-
913-
warningm :: MonadIO m => String -> m ()
914-
warningm s = liftIO $ warningM "hie" s
915-
916-
errorm :: MonadIO m => String -> m ()
917-
errorm s = liftIO $ errorM "hie" s
918-
919-
-- ---------------------------------------------------------------------

src/Ide/Logger.hs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module Ide.Logger
2+
(
3+
hlsLogger
4+
, logm
5+
, debugm
6+
, warningm
7+
, errorm
8+
) where
9+
10+
import Control.Monad.IO.Class
11+
import qualified Data.Text as T
12+
import qualified Development.IDE.Types.Logger as L
13+
import System.Log.Logger
14+
15+
-- ---------------------------------------------------------------------
16+
-- data Logger = Logger {logPriority :: Priority -> T.Text -> IO ()}
17+
hlsLogger :: L.Logger
18+
hlsLogger = L.Logger $ \pri txt ->
19+
case pri of
20+
L.Telemetry -> logm (T.unpack txt)
21+
L.Debug -> debugm (T.unpack txt)
22+
L.Info -> logm (T.unpack txt)
23+
L.Warning -> warningm (T.unpack txt)
24+
L.Error -> errorm (T.unpack txt)
25+
26+
-- ---------------------------------------------------------------------
27+
28+
logm :: MonadIO m => String -> m ()
29+
logm s = liftIO $ infoM "hie" s
30+
31+
debugm :: MonadIO m => String -> m ()
32+
debugm s = liftIO $ debugM "hie" s
33+
34+
warningm :: MonadIO m => String -> m ()
35+
warningm s = liftIO $ warningM "hie" s
36+
37+
errorm :: MonadIO m => String -> m ()
38+
errorm s = liftIO $ errorM "hie" s
39+
40+
-- ---------------------------------------------------------------------

src/Ide/Plugin/Pragmas.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ codeAction = codeActionProvider
8080
-- Pragmas are defined by a curated list of known pragmas, see 'possiblePragmas'.
8181
codeActionProvider :: CodeActionProvider
8282
codeActionProvider _ plId docId _ (J.CodeActionContext (J.List diags) _monly) = do
83-
-- cmds <- mapM mkCommand pragmas
84-
cmds <- mapM mkCommand ("FooPragma":pragmas)
83+
cmds <- mapM mkCommand pragmas
84+
-- cmds <- mapM mkCommand ("FooPragma":pragmas)
8585
return $ Right $ List cmds
8686
where
8787
-- Filter diagnostics that are from ghcmod

test/functional/PluginSpec.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE OverloadedStrings #-}
3+
{-# LANGUAGE TypeApplications #-}
34
module PluginSpec where
45

5-
-- import Control.Applicative.Combinators
6+
import Control.Applicative.Combinators
67
import Control.Lens hiding (List)
78
-- import Control.Monad
89
import Control.Monad.IO.Class
@@ -26,8 +27,8 @@ import TestUtils
2627
-- ---------------------------------------------------------------------
2728

2829
spec :: Spec
29-
spec = do
30-
describe "composes code actions" $ do
30+
spec =
31+
describe "composes code actions" $
3132
it "provides 3.8 code actions" $ runSession hieCommandExamplePlugin fullCaps "test/testdata" $ do
3233

3334
doc <- openDoc "Format.hs" "haskell"
@@ -54,6 +55,9 @@ spec = do
5455
executeCodeAction ca
5556
liftIO $ putStrLn $ "B" -- AZ
5657

58+
_ <- skipManyTill anyMessage (message @RegisterCapabilityRequest)
59+
liftIO $ putStrLn $ "B2" -- AZ
60+
5761
contents <- getDocumentEdit doc
5862
liftIO $ putStrLn $ "C" -- AZ
5963
liftIO $ contents `shouldBe` "main = undefined\nfoo x = x\n"

test/utils/TestUtils.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ logFilePath = "hie-" ++ stackYaml ++ ".log"
205205
-- stack just puts all project executables on PATH.
206206
hieCommand :: String
207207
-- hieCommand = "hie --lsp --bios-verbose -d -l test-logs/" ++ logFilePath
208-
hieCommand = "haskell-language-server --lsp"
208+
-- hieCommand = "haskell-language-server --lsp"
209+
hieCommand = "haskell-language-server --lsp --test --shake-profiling=test-logs/" ++ logFilePath
209210

210211
hieCommandVomit :: String
211212
hieCommandVomit = hieCommand ++ " --vomit"

0 commit comments

Comments
 (0)