Skip to content

Commit c24ef1c

Browse files
jacgcocreature
authored andcommitted
Add --version CLI option (#106)
* Add --version CLI option * Extract ghcide version from cabal * Extract precise GHC version from cabal preprocessor macro
1 parent cec3159 commit c24ef1c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

exe/Arguments.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ data Arguments = Arguments
1010
{argLSP :: Bool
1111
,argsCwd :: Maybe FilePath
1212
,argFiles :: [FilePath]
13+
,argsVersion :: Bool
1314
}
1415

1516
getArguments :: IO Arguments
@@ -25,3 +26,4 @@ arguments = Arguments
2526
<$> switch (long "lsp" <> help "Start talking to an LSP server")
2627
<*> optional (strOption $ long "cwd" <> metavar "DIR" <> help "Change to this directory")
2728
<*> many (argument str (metavar "FILES/DIRS..."))
29+
<*> switch (long "version" <> help "Show ghcide and GHC versions")

exe/Main.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
-- Copyright (c) 2019 The DAML Authors. All rights reserved.
22
-- SPDX-License-Identifier: Apache-2.0
33
{-# OPTIONS_GHC -Wno-dodgy-imports #-} -- GHC no longer exports def in GHC 8.6 and above
4+
{-# LANGUAGE CPP #-} -- To get precise GHC version
45

56
module Main(main) where
67

@@ -29,12 +30,13 @@ import qualified Data.Text as T
2930
import qualified Data.Text.IO as T
3031
import Language.Haskell.LSP.Messages
3132
import Linker
32-
import System.Info
3333
import Data.Version
3434
import Development.IDE.LSP.LanguageServer
3535
import System.Directory.Extra as IO
3636
import System.Environment
3737
import System.IO
38+
import System.Exit
39+
import Paths_ghcide
3840
import Development.Shake hiding (Env)
3941
import qualified Data.Set as Set
4042

@@ -47,13 +49,19 @@ import HIE.Bios
4749
getLibdir :: IO FilePath
4850
getLibdir = fromMaybe GHC.Paths.libdir <$> lookupEnv "NIX_GHC_LIBDIR"
4951

52+
ghcideVersion :: String
53+
ghcideVersion = "ghcide version: " <> showVersion version
54+
<> " (GHC: " <> VERSION_ghc <> ")"
55+
5056
main :: IO ()
5157
main = do
5258
-- WARNING: If you write to stdout before runLanguageServer
5359
-- then the language server will not work
54-
hPutStrLn stderr $ "Starting ghcide (GHC v" ++ showVersion compilerVersion ++ ")"
5560
Arguments{..} <- getArguments
5661

62+
if argsVersion then putStrLn ghcideVersion >> exitSuccess
63+
else hPutStrLn stderr {- see WARNING above -} ghcideVersion
64+
5765
-- lock to avoid overlapping output on stdout
5866
lock <- newLock
5967
let logger = Logger $ \pri msg -> withLock lock $

0 commit comments

Comments
 (0)