-
-
Notifications
You must be signed in to change notification settings - Fork 389
/
Copy pathArguments.hs
209 lines (190 loc) · 7.4 KB
/
Arguments.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE CPP #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
module Ide.Arguments
( Arguments(..)
, GhcideArguments(..)
, PrintVersion(..)
, BiosAction(..)
, getArguments
, haskellLanguageServerVersion
, haskellLanguageServerNumericVersion
) where
import Data.Version
import Development.IDE (IdeState)
import Development.IDE.Main (Command (..), commandP)
import GitHash (giHash, tGitInfoCwdTry)
import Ide.Logger (Priority (..))
import Ide.Types (IdePlugins)
import Options.Applicative
import Paths_haskell_language_server
import System.Environment
-- ---------------------------------------------------------------------
data Arguments
= VersionMode PrintVersion
| ProbeToolsMode
| ListPluginsMode
| BiosMode BiosAction
| Ghcide GhcideArguments
| VSCodeExtensionSchemaMode
| PluginsCustomConfigMarkdownReferenceMode
| DefaultConfigurationMode
| PrintLibDir
data GhcideArguments = GhcideArguments
{ argsCommand :: Command
, argsCwd :: Maybe FilePath
, argsShakeProfiling :: Maybe FilePath
, argsTesting :: Bool
, argsExamplePlugin :: Bool
, argsLogLevel :: Priority
, argsLogFile :: Maybe String
-- ^ the minimum log level to show
, argsLogStderr :: Bool
, argsLogClient :: Bool
, argsThreads :: Int
, argsProjectGhcVersion :: Bool
} deriving Show
data PrintVersion
= PrintVersion
| PrintNumericVersion
deriving (Show, Eq, Ord)
data BiosAction
= PrintCradleType
deriving (Show, Eq, Ord)
getArguments :: String -> IdePlugins IdeState -> IO Arguments
getArguments exeName plugins = execParser opts
where
opts = info ((
VersionMode <$> printVersionParser exeName
<|> probeToolsParser exeName
<|> hsubparser
( command "vscode-extension-schema" extensionSchemaCommand
<> command "generate-default-config" generateDefaultConfigCommand
<> command "plugins-custom-config-markdown-reference" pluginsCustomConfigMarkdownReferenceCommand
)
<|> listPluginsParser
<|> BiosMode <$> biosParser
<|> Ghcide <$> arguments plugins
<|> flag' PrintLibDir (long "print-libdir" <> help "Print project GHCs libdir")
)
<**> helper)
( fullDesc
<> progDesc "Used as a test bed to check your IDE Client will work"
<> header (exeName ++ " - GHC Haskell LSP server"))
extensionSchemaCommand =
info (pure VSCodeExtensionSchemaMode)
(fullDesc <> progDesc "Print generic config schema for plugins (used in the package.json of haskell vscode extension)")
generateDefaultConfigCommand =
info (pure DefaultConfigurationMode)
(fullDesc <> progDesc "Print config supported by the server with default values")
pluginsCustomConfigMarkdownReferenceCommand =
info (pure PluginsCustomConfigMarkdownReferenceMode)
(fullDesc <> progDesc "Print markdown reference for plugins custom config")
printVersionParser :: String -> Parser PrintVersion
printVersionParser exeName =
flag' PrintVersion
(long "version" <> help ("Show " ++ exeName ++ " and GHC versions"))
<|>
flag' PrintNumericVersion
(long "numeric-version" <> help ("Show numeric version of " ++ exeName))
biosParser :: Parser BiosAction
biosParser =
flag' PrintCradleType
(long "print-cradle" <> help "Print the project cradle type")
probeToolsParser :: String -> Parser Arguments
probeToolsParser exeName =
flag' ProbeToolsMode
(long "probe-tools" <> help ("Show " ++ exeName ++ " version and other tools of interest"))
listPluginsParser :: Parser Arguments
listPluginsParser =
flag' ListPluginsMode
(long "list-plugins" <> help "List all available plugins")
arguments :: IdePlugins IdeState -> Parser GhcideArguments
arguments plugins = GhcideArguments
<$> (commandP plugins <|> lspCommand <|> checkCommand)
<*> optional (strOption $ long "cwd" <> metavar "DIR"
<> help "Change to this directory")
<*> optional (strOption $ long "shake-profiling" <> metavar "DIR"
<> help "Dump profiling reports to this directory")
<*> switch (long "test"
<> help "Enable additional lsp messages used by the testsuite")
<*> switch (long "example"
<> help "Include the Example Plugin. For Plugin devs only")
<*>
(option @Priority auto
(long "log-level"
<> help "Only show logs at or above this log level"
<> metavar "LOG_LEVEL"
<> value Info
<> showDefault
)
<|>
flag' Debug
(long "debug"
<> short 'd'
<> help "Sets the log level to Debug, alias for '--log-level Debug'"
)
)
-- This option is a little inconsistent with the other log options, since
-- it's not a boolean and there is no way to turn it off. That's okay
-- since the default is off.
<*> (optional (strOption
( long "log-file"
<> metavar "LOGFILE"
<> help "Send logs to a file"
)) <|> (optional (strOption
( long "logfile"
<> short 'l'
<> metavar "LOGFILE"
<> help "Send logs to a file"
-- deprecated alias so users don't need to update their CLI calls
-- immediately
<> internal
)))
)
-- Boolean option so we can toggle the default in a consistent way
<*> option auto
( long "log-stderr"
<> help "Send logs to stderr"
<> metavar "BOOL"
<> value True
<> showDefault
)
-- Boolean option so we can toggle the default in a consistent way
<*> option auto
( long "log-client"
<> help "Send logs to the client using the window/logMessage LSP method"
<> metavar "BOOL"
-- This is off by default, since some clients will show duplicate logs
-- if we log both to stderr and the client
<> value False
<> showDefault
)
<*> option auto
(short 'j'
<> help "Number of threads (0: automatic)"
<> metavar "NUM"
<> value 0
<> showDefault
)
<*> switch (long "project-ghc-version"
<> help "Work out the project GHC version and print it")
where
lspCommand = LSP <$ flag' True (long "lsp" <> help "Start talking to an LSP server")
checkCommand = Check <$> many (argument str (metavar "FILES/DIRS..."))
-- ---------------------------------------------------------------------
haskellLanguageServerNumericVersion :: String
haskellLanguageServerNumericVersion = showVersion version
haskellLanguageServerVersion :: IO String
haskellLanguageServerVersion = do
path <- getExecutablePath
let gi = $$tGitInfoCwdTry
gitHashSection = case gi of
Right gi -> " (GIT hash: " <> giHash gi <> ")"
Left _ -> ""
return $ "haskell-language-server version: " <> haskellLanguageServerNumericVersion
<> " (GHC: " <> VERSION_ghc
<> ") (PATH: " <> path <> ")"
<> gitHashSection