2
2
{-# LANGUAGE RankNTypes #-}
3
3
module Main where
4
4
5
+ import qualified Control.Exception as E
5
6
import Control.Monad
6
7
import Data.Monoid ((<>) )
7
8
import Data.Version (showVersion )
9
+ import qualified Data.Yaml as Yaml
10
+ import HIE.Bios.Types
11
+ import Haskell.Ide.Engine.Cradle (findLocalCradle , cradleDisplay )
8
12
import Haskell.Ide.Engine.MonadFunctions
9
13
import Haskell.Ide.Engine.MonadTypes
10
14
import Haskell.Ide.Engine.Options
@@ -16,26 +20,26 @@ import Options.Applicative.Simple
16
20
import qualified Paths_haskell_ide_engine as Meta
17
21
import System.Directory
18
22
import System.Environment
19
- import qualified System.Log.Logger as L
20
- import HIE.Bios.Types
23
+ import System.FilePath ((</>) )
21
24
import System.IO
25
+ import qualified System.Log.Logger as L
22
26
23
27
-- ---------------------------------------------------------------------
24
28
-- plugins
25
29
26
30
import Haskell.Ide.Engine.Plugin.ApplyRefact
27
31
import Haskell.Ide.Engine.Plugin.Brittany
28
32
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
29
36
-- import Haskell.Ide.Engine.Plugin.HaRe
30
37
import Haskell.Ide.Engine.Plugin.Haddock
31
38
import Haskell.Ide.Engine.Plugin.HfaAlign
32
39
import Haskell.Ide.Engine.Plugin.HsImport
33
40
import Haskell.Ide.Engine.Plugin.Liquid
34
41
import Haskell.Ide.Engine.Plugin.Package
35
42
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
39
43
40
44
-- ---------------------------------------------------------------------
41
45
@@ -110,23 +114,56 @@ run opts = do
110
114
maybe (pure () ) setCurrentDirectory $ projectRoot opts
111
115
112
116
progName <- getProgName
113
- logm $ " Run entered for HIE(" ++ progName ++ " ) " ++ hieVersion
114
- logm $ " Current directory:" ++ origDir
115
117
args <- getArgs
116
- logm $ " args:" ++ show args
117
118
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
120
128
121
129
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."
124
132
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."
127
135
128
- let plugins' = plugins (optExamplePlugin opts)
136
+ let plugins' = plugins (optExamplePlugin opts)
129
137
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 $ " \n args:" ++ show args
148
+
149
+ cliOut $ " \n Looking 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
+ -- ---------------------------------------------------------------------
0 commit comments