This repository was archived by the owner on Oct 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 206
/
Copy pathMainHie.hs
169 lines (141 loc) · 6.27 KB
/
MainHie.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
{-# LANGUAGE CPP #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
module Main where
import qualified Control.Exception as E
import Control.Monad
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Yaml as Yaml
import HIE.Bios.Types
import Haskell.Ide.Engine.Cradle (findLocalCradle, cradleDisplay
, getProjectGhcLibDir, CabalHelper)
import Haskell.Ide.Engine.MonadFunctions
import Haskell.Ide.Engine.MonadTypes
import Haskell.Ide.Engine.Options
import Haskell.Ide.Engine.Scheduler
import Haskell.Ide.Engine.Server
import Haskell.Ide.Engine.Version
import System.Directory
import System.Environment
import System.FilePath
import System.Info
-- ---------------------------------------------------------------------
import RunTest
-- ---------------------------------------------------------------------
-- plugins
import Haskell.Ide.Engine.Plugin.ApplyRefact
import Haskell.Ide.Engine.Plugin.Brittany
import Haskell.Ide.Engine.Plugin.Example2
import Haskell.Ide.Engine.Plugin.Floskell
import Haskell.Ide.Engine.Plugin.Generic
import Haskell.Ide.Engine.Plugin.GhcMod
-- import Haskell.Ide.Engine.Plugin.HaRe
import Haskell.Ide.Engine.Plugin.Haddock
import Haskell.Ide.Engine.Plugin.HfaAlign
import Haskell.Ide.Engine.Plugin.HsImport
import Haskell.Ide.Engine.Plugin.Liquid
import Haskell.Ide.Engine.Plugin.Ormolu
import Haskell.Ide.Engine.Plugin.Package
import Haskell.Ide.Engine.Plugin.Pragmas
-- ---------------------------------------------------------------------
-- | This will be read from a configuration, eventually
plugins :: Bool -> IdePlugins
plugins includeExamples = pluginDescToIdePlugins allPlugins
where
allPlugins = if includeExamples
then basePlugins ++ examplePlugins
else basePlugins
basePlugins =
[ applyRefactDescriptor "applyrefact"
, brittanyDescriptor "brittany"
, haddockDescriptor "haddock"
-- , hareDescriptor "hare"
, hsimportDescriptor "hsimport"
, liquidDescriptor "liquid"
, packageDescriptor "package"
, pragmasDescriptor "pragmas"
, floskellDescriptor "floskell"
, genericDescriptor "generic"
, ghcmodDescriptor "ghcmod"
, ormoluDescriptor "ormolu"
]
examplePlugins =
[example2Descriptor "eg2"
,hfaAlignDescriptor "hfaa"
]
-- ---------------------------------------------------------------------
main :: IO ()
main = do
origDir <- getCurrentDirectory
opts <- initApp
"haskell-ide-engine - Provide a common engine to power any Haskell IDE"
progName <- getProgName
args <- getArgs
let plugins' = plugins (optExamplePlugin opts)
case optMode opts of
LspMode -> do
-- Start up in LSP mode
logm $ "Run entered for HIE(" ++ progName ++ ") " ++ hieVersion
logm $ "Operating as a LSP server on stdio"
logm $ "Current directory:" ++ origDir
logm $ "Operating system:" ++ os
logm $ "args:" ++ show args
let initOpts = defaultCradleOpts { cradleOptsVerbosity = verbosity }
verbosity = if optBiosVerbose opts then Verbose else Silent
when (optBiosVerbose opts) $
logm "Enabling verbose mode for hie-bios. This option currently doesn't do anything."
when (optExamplePlugin opts) $
logm "Enabling Example2 plugin, will insert constant diagnostics etc."
-- launch the dispatcher.
scheduler <- newScheduler plugins' initOpts
server scheduler origDir plugins' (optCaptureFile opts)
ProjectLoadingMode projectLoadingOpts -> do
-- Provide debug info
cliOut $ "Running HIE(" ++ progName ++ ")"
cliOut $ " " ++ hieVersion
cliOut $ "To run as a LSP server on stdio, provide the '--lsp' argument"
cliOut $ "Current directory:" ++ origDir
-- args <- getArgs
cliOut $ "\nargs:" ++ show args
cliOut $ "\nLooking for project config cradle...\n"
ecradle <- getCradleInfo origDir
case ecradle of
Left e -> cliOut $ "Could not get cradle:" ++ show e
Right cradle -> do
projGhc <- getProjectGhcVersion cradle
mlibdir <- getProjectGhcLibDir cradle
cliOut "\n\n###################################################\n"
cliOut $ "Cradle: " ++ cradleDisplay cradle
cliOut $ "Project Ghc version: " ++ projGhc
cliOut $ "Libdir: " ++ show mlibdir
cliOut "Searching for Haskell source files..."
targets <- case optFiles projectLoadingOpts of
[] -> findAllSourceFiles origDir
xs -> concat <$> mapM findAllSourceFiles xs
cliOut $ "Found " ++ show (length targets) ++ " Haskell source files.\n"
cliOut "###################################################"
cliOut "\nFound the following files:\n"
mapM_ cliOut targets
cliOut ""
unless (optDryRun projectLoadingOpts) $ do
cliOut "\nLoad them all now. This may take a very long time.\n"
loadDiagnostics <- runServer mlibdir plugins' targets
cliOut ""
cliOut "###################################################"
cliOut "###################################################"
cliOut "\nDumping diagnostics:\n\n"
mapM_ (cliOut' . uncurry prettyPrintDiags) loadDiagnostics
cliOut "\n\nNote: loading of 'Setup.hs' is not supported."
-- ---------------------------------------------------------------------
getCradleInfo :: FilePath -> IO (Either Yaml.ParseException (Cradle CabalHelper))
getCradleInfo currentDir = do
let dummyCradleFile = currentDir </> "File.hs"
cradleRes <- E.try (findLocalCradle dummyCradleFile)
return cradleRes
-- ---------------------------------------------------------------------
cliOut :: String -> IO ()
cliOut = putStrLn
cliOut' :: T.Text -> IO ()
cliOut' = T.putStrLn
-- ---------------------------------------------------------------------