Skip to content

Commit e20b026

Browse files
andys8fendor
andauthored
Probe-tools: Print stack ghc version (#3093)
* Probe-tools: Print stack ghc version The ghc version on the $PATH is often not relevant for stack projects. The ghc version stack is using is printed in addition. * Probetools: cradle ghc version added to wrapper * Revert stack ghc changes to Ide.Main * Update exe/Wrapper.hs Co-authored-by: fendor <fendor@users.noreply.github.com> * Probe tools: Print version with padded spaces Addressing <#3093 (comment)> Co-authored-by: fendor <fendor@users.noreply.github.com>
1 parent 2554981 commit e20b026

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

exe/Wrapper.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Main where
1414
import Control.Monad.Extra
1515
import Data.Char (isSpace)
1616
import Data.Default
17+
import Data.Either.Extra (eitherToMaybe)
1718
import Data.Foldable
1819
import Data.List
1920
import Data.Void
@@ -79,6 +80,10 @@ main = do
7980
putStrLn hlsVer
8081
putStrLn "Tool versions found on the $PATH"
8182
putStrLn $ showProgramVersionOfInterest programsOfInterest
83+
putStrLn "Tool versions in your project"
84+
cradle <- findProjectCradle' False
85+
ghcVersion <- runExceptT $ getRuntimeGhcVersion' cradle
86+
putStrLn $ showProgramVersion "ghc" $ mkVersion =<< eitherToMaybe ghcVersion
8287

8388
VersionMode PrintVersion ->
8489
putStrLn hlsVer

src/Ide/Version.hs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ data ProgramsOfInterest = ProgramsOfInterest
4646
showProgramVersionOfInterest :: ProgramsOfInterest -> String
4747
showProgramVersionOfInterest ProgramsOfInterest {..} =
4848
unlines
49-
[ "cabal:\t\t" ++ showVersionWithDefault cabalVersion
50-
, "stack:\t\t" ++ showVersionWithDefault stackVersion
51-
, "ghc:\t\t" ++ showVersionWithDefault ghcVersion
49+
[ showProgramVersion "cabal" cabalVersion
50+
, showProgramVersion "stack" stackVersion
51+
, showProgramVersion "ghc" ghcVersion
5252
]
53+
54+
showProgramVersion :: String -> Maybe Version -> String
55+
showProgramVersion name version =
56+
pad 16 (name ++ ":") ++ showVersionWithDefault version
5357
where
54-
showVersionWithDefault :: Maybe Version -> String
5558
showVersionWithDefault = maybe "Not found" showVersion
59+
pad n s = s ++ replicate (n - length s) ' '
5660

5761
findProgramVersions :: IO ProgramsOfInterest
5862
findProgramVersions = ProgramsOfInterest
@@ -69,8 +73,11 @@ findVersionOf tool =
6973
Nothing -> pure Nothing
7074
Just path ->
7175
readProcessWithExitCode path ["--numeric-version"] "" >>= \case
72-
(ExitSuccess, sout, _) -> pure $ consumeParser myVersionParser sout
76+
(ExitSuccess, sout, _) -> pure $ mkVersion sout
7377
_ -> pure Nothing
78+
79+
mkVersion :: String -> Maybe Version
80+
mkVersion = consumeParser myVersionParser
7481
where
7582
myVersionParser = do
7683
skipSpaces
@@ -79,4 +86,5 @@ findVersionOf tool =
7986
pure version
8087

8188
consumeParser :: ReadP a -> String -> Maybe a
82-
consumeParser p input = listToMaybe $ map fst . filter (null . snd) $ readP_to_S p input
89+
consumeParser p input =
90+
listToMaybe $ map fst . filter (null . snd) $ readP_to_S p input

0 commit comments

Comments
 (0)