Skip to content

Commit b78efe3

Browse files
pepeiborracocreature
authored andcommitted
Extend version message to include path and git commit (#306)
1 parent 64693ed commit b78efe3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

exe/Main.hs

+14-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
-- SPDX-License-Identifier: Apache-2.0
33
{-# OPTIONS_GHC -Wno-dodgy-imports #-} -- GHC no longer exports def in GHC 8.6 and above
44
{-# LANGUAGE CPP #-} -- To get precise GHC version
5+
{-# LANGUAGE TemplateHaskell #-}
56

67
module Main(main) where
78

@@ -39,6 +40,7 @@ import System.Environment
3940
import System.IO
4041
import System.Exit
4142
import Paths_ghcide
43+
import Development.GitRev
4244
import Development.Shake (Action, action)
4345
import qualified Data.Set as Set
4446
import qualified Data.Map.Strict as Map
@@ -52,18 +54,25 @@ import HIE.Bios
5254
getLibdir :: IO FilePath
5355
getLibdir = fromMaybe GHC.Paths.libdir <$> lookupEnv "NIX_GHC_LIBDIR"
5456

55-
ghcideVersion :: String
56-
ghcideVersion = "ghcide version: " <> showVersion version
57-
<> " (GHC: " <> VERSION_ghc <> ")"
57+
ghcideVersion :: IO String
58+
ghcideVersion = do
59+
path <- getExecutablePath
60+
let gitHashSection = case $(gitHash) of
61+
x | x == "UNKNOWN" -> ""
62+
x -> " (GIT hash: " <> x <> ")"
63+
return $ "ghcide version: " <> showVersion version
64+
<> " (GHC: " <> VERSION_ghc
65+
<> ") (PATH: " <> path <> ")"
66+
<> gitHashSection
5867

5968
main :: IO ()
6069
main = do
6170
-- WARNING: If you write to stdout before runLanguageServer
6271
-- then the language server will not work
6372
Arguments{..} <- getArguments
6473

65-
if argsVersion then putStrLn ghcideVersion >> exitSuccess
66-
else hPutStrLn stderr {- see WARNING above -} ghcideVersion
74+
if argsVersion then ghcideVersion >>= putStrLn >> exitSuccess
75+
else hPutStrLn stderr {- see WARNING above -} =<< ghcideVersion
6776

6877
-- lock to avoid overlapping output on stdout
6978
lock <- newLock

ghcide.cabal

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ executable ghcide
162162
filepath,
163163
ghc-paths,
164164
ghc,
165+
gitrev,
165166
haskell-lsp,
166167
hie-bios >= 0.3.2 && < 0.4,
167168
ghcide,

0 commit comments

Comments
 (0)