Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Commit 337fd9b

Browse files
authored
Merge pull request #1012 from alanz/803-no-system-ghc
hie-wrapper deals with missing System GHC
2 parents 03dcb8a + 814aa51 commit 337fd9b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

app/HieWrapper.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ run opts = do
8383

8484
let
8585
hieBin = "hie-" ++ ghcVersion
86-
backupHieBin = "hie-" ++ init (dropWhileEnd (/='.') ghcVersion)
86+
backupHieBin =
87+
case dropWhileEnd (/='.') ghcVersion of
88+
[] -> "hie"
89+
xs -> "hie-" ++ init xs
8790
candidates' = [hieBin, backupHieBin, "hie"]
8891
candidates = map (++ exeExtension) candidates'
8992

src/Haskell/Ide/Engine/Plugin/Base.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,27 @@ hieGhcDisplayVersion = compilerName ++ "-" ++ VERSION_ghc
105105

106106
getProjectGhcVersion :: IO String
107107
getProjectGhcVersion = do
108-
isStackProject <- doesFileExist "stack.yaml"
108+
isStackProject <- doesFileExist "stack.yaml"
109109
isStackInstalled <- isJust <$> findExecutable "stack"
110110
if isStackProject && isStackInstalled
111111
then do
112112
L.infoM "hie" "Using stack GHC version"
113113
catch (tryCommand "stack ghc -- --numeric-version") $ \e -> do
114114
L.errorM "hie" $ show (e :: SomeException)
115115
L.infoM "hie" "Couldn't find stack version, falling back to plain GHC"
116-
tryCommand "ghc --numeric-version"
116+
getGhcVersion
117117
else do
118118
L.infoM "hie" "Using plain GHC version"
119-
tryCommand "ghc --numeric-version"
119+
getGhcVersion
120120

121121
where
122+
getGhcVersion = do
123+
isGhcInstalled <- isJust <$> findExecutable "ghc"
124+
if isGhcInstalled
125+
then tryCommand "ghc --numeric-version"
126+
else return "No System GHC found"
127+
122128
tryCommand cmd =
123-
-- Drop '\n' from the output like "7.10.3\n", "8.4.3\n"
124129
init <$> readCreateProcess (shell cmd) ""
125130

126131
hieGhcVersion :: String

0 commit comments

Comments
 (0)