Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve wrapper cradle errors #2711

Merged
merged 4 commits into from
Feb 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 12 additions & 8 deletions exe/Wrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,22 @@ launchHaskellLanguageServer parsedArgs = do
callProcess e args
#else
let Cradle { cradleOptsProg = CradleAction { runGhcCmd } } = cradle
(CradleSuccess ghcBinary) <- fmap trim <$> runGhcCmd ["-v0", "-package-env=-", "-e", "putStr =<< System.Environment.getExecutablePath"]
(CradleSuccess libdir) <- HieBios.getRuntimeGhcLibDir cradle
-- we need to be compatible with NoImplicitPrelude
ghcBinary <- (fmap trim <$> runGhcCmd ["-v0", "-package-env=-", "-e", "do e <- System.Environment.getExecutablePath ; System.IO.putStr e"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth a comment, very non-obvious that you're doing it this way to be compatible with NoImplicitPrelude.

Also, this probably won't work with RebindableSyntax still, but surely nobody sets that globally...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RebindableSyntax

oh dear...

>>= cradleResult "Failed to get project GHC executable path"
libdir <- HieBios.getRuntimeGhcLibDir cradle
>>= cradleResult "Failed to get project GHC libdir path"
env <- Map.fromList <$> getEnvironment
let newEnv = Map.insert "GHC_BIN" ghcBinary $ Map.insert "GHC_LIBDIR" libdir env
executeFile e True args (Just (Map.toList newEnv))
#endif


cradleResult :: String -> CradleLoadResult a -> IO a
cradleResult _ (CradleSuccess a) = pure a
cradleResult str (CradleFail e) = die $ str ++ ": " ++ show e
cradleResult str CradleNone = die $ str ++ ": no cradle"

-- | Version of 'getRuntimeGhcVersion' that dies if we can't get it, and also
-- checks to see if the tool is missing if it is one of
getRuntimeGhcVersion' :: Show a => Cradle a -> IO String
Expand All @@ -134,12 +143,7 @@ getRuntimeGhcVersion' cradle = do
Direct -> checkToolExists "ghc"
_ -> pure ()

ghcVersionRes <- HieBios.getRuntimeGhcVersion cradle
case ghcVersionRes of
CradleSuccess ver -> do
return ver
CradleFail error -> die $ "Failed to get project GHC version:" ++ show error
CradleNone -> die "Failed get project GHC version, since we have a none cradle"
HieBios.getRuntimeGhcVersion cradle >>= cradleResult "Failed to get project GHC version"
where
checkToolExists exe = do
exists <- findExecutable exe
Expand Down