99
1010module Arguments
1111 ( Arguments (.. )
12+ , LspArguments (.. )
13+ , PrintVersion (.. )
1214 , getArguments
1315 , haskellLanguageServerVersion
16+ , haskellLanguageServerNumericVersion
1417 ) where
1518
1619import Data.Version
@@ -21,11 +24,15 @@ import System.Environment
2124
2225-- ---------------------------------------------------------------------
2326
24- data Arguments = Arguments
27+ data Arguments
28+ = VersionMode PrintVersion
29+ | LspMode LspArguments
30+ deriving Show
31+
32+ data LspArguments = LspArguments
2533 { argLSP :: Bool
2634 ,argsCwd :: Maybe FilePath
2735 ,argFiles :: [FilePath ]
28- ,argsVersion :: Bool
2936 ,argsShakeProfiling :: Maybe FilePath
3037 ,argsTesting :: Bool
3138 ,argsExamplePlugin :: Bool
@@ -37,22 +44,36 @@ data Arguments = Arguments
3744 , argsProjectGhcVersion :: Bool
3845 } deriving Show
3946
47+ data PrintVersion
48+ = PrintVersion
49+ | PrintNumericVersion
50+ deriving (Show , Eq , Ord )
51+
4052getArguments :: String -> IO Arguments
4153getArguments exeName = execParser opts
4254 where
43- opts = info (arguments exeName <**> helper)
55+ opts = info ((
56+ VersionMode <$> printVersionParser exeName
57+ <|> LspMode <$> arguments)
58+ <**> helper)
4459 ( fullDesc
4560 <> progDesc " Used as a test bed to check your IDE Client will work"
4661 <> header (exeName ++ " - GHC Haskell LSP server" ))
4762
48- arguments :: String -> Parser Arguments
49- arguments exeName = Arguments
63+ printVersionParser :: String -> Parser PrintVersion
64+ printVersionParser exeName =
65+ flag' PrintVersion
66+ (long " version" <> help (" Show " ++ exeName ++ " and GHC versions" ))
67+ <|>
68+ flag' PrintNumericVersion
69+ (long " numeric-version" <> help (" Show numeric version of " ++ exeName))
70+
71+ arguments :: Parser LspArguments
72+ arguments = LspArguments
5073 <$> switch (long " lsp" <> help " Start talking to an LSP server" )
5174 <*> optional (strOption $ long " cwd" <> metavar " DIR"
5275 <> help " Change to this directory" )
5376 <*> many (argument str (metavar " FILES/DIRS..." ))
54- <*> switch (long " version"
55- <> help (" Show " ++ exeName ++ " and GHC versions" ))
5677 <*> optional (strOption $ long " shake-profiling" <> metavar " DIR"
5778 <> help " Dump profiling reports to this directory" )
5879 <*> switch (long " test"
@@ -83,13 +104,16 @@ arguments exeName = Arguments
83104
84105-- ---------------------------------------------------------------------
85106
107+ haskellLanguageServerNumericVersion :: String
108+ haskellLanguageServerNumericVersion = showVersion version
109+
86110haskellLanguageServerVersion :: IO String
87111haskellLanguageServerVersion = do
88112 path <- getExecutablePath
89113 let gitHashSection = case $ (gitHash) of
90114 x | x == " UNKNOWN" -> " "
91115 x -> " (GIT hash: " <> x <> " )"
92- return $ " haskell-language-server version: " <> showVersion version
116+ return $ " haskell-language-server version: " <> haskellLanguageServerNumericVersion
93117 <> " (GHC: " <> VERSION_ghc
94118 <> " ) (PATH: " <> path <> " )"
95119 <> gitHashSection
0 commit comments