Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit c2a56d8

Browse files
committed
First pass at printing out debug info if started without --lsp
Example output Running HIE(hie) Version 1.0.0.0, Git revision 666626e (dirty) (3534 commits) x86_64 ghc-8.6.5 Current directory:/home/alanz/mysrc/github/alanz/haskell-ide-engine/app args:[] Looking for project config cradle... 2020-01-01 22:41:46.396914848 [ThreadId 4] - Cabal-Helper dirs: ["/home/alanz/mysrc/github/alanz/haskell-ide-engine","/home/alanz/mysrc/github/alanz/haskell-ide-engine/app/File.hs"] Resolving dependencies... Build profile: -w ghc-8.6.5 -O1 In order, the following would be built (use -v for more details): - hie-plugin-api-0.14.0.0 (lib) (configuration changed) - haskell-ide-engine-1.0.0.0 (lib) (configuration changed) - haskell-ide-engine-1.0.0.0 (test:wrapper-test) (configuration changed) - haskell-ide-engine-1.0.0.0 (exe:hie-wrapper) (configuration changed) - haskell-ide-engine-1.0.0.0 (lib:hie-test-utils) (configuration changed) - haskell-ide-engine-1.0.0.0 (exe:hie) (configuration changed) - haskell-ide-engine-1.0.0.0 (test:unit-test) (configuration changed) - haskell-ide-engine-1.0.0.0 (test:plugin-dispatcher-test) (configuration changed) - haskell-ide-engine-1.0.0.0 (test:dispatcher-test) (configuration changed) - haskell-ide-engine-1.0.0.0 (test:func-test) (configuration changed) Cradle:Cabal project
1 parent 666626e commit c2a56d8

File tree

4 files changed

+64
-21
lines changed

4 files changed

+64
-21
lines changed

app/MainHie.hs

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22
{-# LANGUAGE RankNTypes #-}
33
module Main where
44

5+
import qualified Control.Exception as E
56
import Control.Monad
67
import Data.Monoid ((<>))
78
import Data.Version (showVersion)
9+
import qualified Data.Yaml as Yaml
10+
import HIE.Bios.Types
11+
import Haskell.Ide.Engine.Cradle (findLocalCradle, cradleDisplay)
812
import Haskell.Ide.Engine.MonadFunctions
913
import Haskell.Ide.Engine.MonadTypes
1014
import Haskell.Ide.Engine.Options
@@ -16,26 +20,26 @@ import Options.Applicative.Simple
1620
import qualified Paths_haskell_ide_engine as Meta
1721
import System.Directory
1822
import System.Environment
19-
import qualified System.Log.Logger as L
20-
import HIE.Bios.Types
23+
import System.FilePath ((</>))
2124
import System.IO
25+
import qualified System.Log.Logger as L
2226

2327
-- ---------------------------------------------------------------------
2428
-- plugins
2529

2630
import Haskell.Ide.Engine.Plugin.ApplyRefact
2731
import Haskell.Ide.Engine.Plugin.Brittany
2832
import Haskell.Ide.Engine.Plugin.Example2
33+
import Haskell.Ide.Engine.Plugin.Floskell
34+
import Haskell.Ide.Engine.Plugin.Generic
35+
import Haskell.Ide.Engine.Plugin.GhcMod
2936
-- import Haskell.Ide.Engine.Plugin.HaRe
3037
import Haskell.Ide.Engine.Plugin.Haddock
3138
import Haskell.Ide.Engine.Plugin.HfaAlign
3239
import Haskell.Ide.Engine.Plugin.HsImport
3340
import Haskell.Ide.Engine.Plugin.Liquid
3441
import Haskell.Ide.Engine.Plugin.Package
3542
import Haskell.Ide.Engine.Plugin.Pragmas
36-
import Haskell.Ide.Engine.Plugin.Floskell
37-
import Haskell.Ide.Engine.Plugin.Generic
38-
import Haskell.Ide.Engine.Plugin.GhcMod
3943

4044
-- ---------------------------------------------------------------------
4145

@@ -110,23 +114,56 @@ run opts = do
110114
maybe (pure ()) setCurrentDirectory $ projectRoot opts
111115

112116
progName <- getProgName
113-
logm $ "Run entered for HIE(" ++ progName ++ ") " ++ hieVersion
114-
logm $ "Current directory:" ++ origDir
115117
args <- getArgs
116-
logm $ "args:" ++ show args
117118

118-
let initOpts = defaultCradleOpts { cradleOptsVerbosity = verbosity }
119-
verbosity = if optBiosVerbose opts then Verbose else Silent
119+
if optLsp opts
120+
then do
121+
-- Start up in LSP mode
122+
logm $ "Run entered for HIE(" ++ progName ++ ") " ++ hieVersion
123+
logm $ "Current directory:" ++ origDir
124+
logm $ "args:" ++ show args
125+
126+
let initOpts = defaultCradleOpts { cradleOptsVerbosity = verbosity }
127+
verbosity = if optBiosVerbose opts then Verbose else Silent
120128

121129

122-
when (optBiosVerbose opts) $
123-
logm "Enabling verbose mode for hie-bios. This option currently doesn't do anything."
130+
when (optBiosVerbose opts) $
131+
logm "Enabling verbose mode for hie-bios. This option currently doesn't do anything."
124132

125-
when (optExamplePlugin opts) $
126-
logm "Enabling Example2 plugin, will insert constant diagnostics etc."
133+
when (optExamplePlugin opts) $
134+
logm "Enabling Example2 plugin, will insert constant diagnostics etc."
127135

128-
let plugins' = plugins (optExamplePlugin opts)
136+
let plugins' = plugins (optExamplePlugin opts)
129137

130-
-- launch the dispatcher.
131-
scheduler <- newScheduler plugins' initOpts
132-
server scheduler origDir plugins' (optCaptureFile opts)
138+
-- launch the dispatcher.
139+
scheduler <- newScheduler plugins' initOpts
140+
server scheduler origDir plugins' (optCaptureFile opts)
141+
else do
142+
-- Provide debug info
143+
cliOut $ "Running HIE(" ++ progName ++ ")"
144+
cliOut $ " " ++ hieVersion
145+
cliOut $ "Current directory:" ++ origDir
146+
-- args <- getArgs
147+
cliOut $ "\nargs:" ++ show args
148+
149+
cliOut $ "\nLooking for project config cradle...\n"
150+
151+
ecradle <- getCradleInfo origDir
152+
case ecradle of
153+
Left e -> cliOut $ "Could not get cradle:" ++ show e
154+
Right cradle -> cliOut $ "Cradle:" ++ cradleDisplay cradle
155+
156+
-- ---------------------------------------------------------------------
157+
158+
getCradleInfo :: FilePath -> IO (Either Yaml.ParseException Cradle)
159+
getCradleInfo currentDir = do
160+
let dummyCradleFile = currentDir </> "File.hs"
161+
cradleRes <- E.try (findLocalCradle dummyCradleFile)
162+
return cradleRes
163+
164+
-- ---------------------------------------------------------------------
165+
166+
cliOut :: String -> IO ()
167+
cliOut = putStrLn
168+
169+
-- ---------------------------------------------------------------------

cabal.project

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ tests: true
99
package haskell-ide-engine
1010
test-show-details: direct
1111

12+
-- Match the flag settings we use in stac builds
13+
constraints:
14+
haskell-ide-engine +pedantic
15+
hie-plugin-api +pedantic
16+
1217
write-ghc-environment-files: never

haskell-ide-engine.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ executable hie
118118
, hie-plugin-api
119119
, hslogger
120120
, optparse-simple
121+
, yaml
121122
ghc-options: -threaded -rtsopts -with-rtsopts=-N -Wall -Wredundant-constraints
122123
-with-rtsopts=-T
123124
if flag(pedantic)

src/Haskell/Ide/Engine/Options.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Options.Applicative.Simple
66
data GlobalOpts = GlobalOpts
77
{ optDebugOn :: Bool
88
, optLogFile :: Maybe String
9-
, _optLsp :: Bool -- Kept for a while, to not break legacy clients
9+
, optLsp :: Bool -- Kept for a while, to not break legacy clients
1010
, projectRoot :: Maybe String
1111
, optBiosVerbose :: Bool
1212
, optCaptureFile :: Maybe FilePath
@@ -26,9 +26,9 @@ globalOptsParser = GlobalOpts
2626
<> metavar "LOGFILE"
2727
<> help "File to log to, defaults to stdout"
2828
))
29-
<*> flag True True
29+
<*> flag False True
3030
( long "lsp"
31-
<> help "Legacy flag, no longer used, to enable LSP mode. Not required.")
31+
<> help "Start HIE as an LSP server. Otherwise it dumps debug info to stdout")
3232
<*> optional (strOption
3333
( long "project-root"
3434
<> short 'r'

0 commit comments

Comments
 (0)