Skip to content

Commit

Permalink
Log stderr of stack exec ghc for better feedback (#254)
Browse files Browse the repository at this point in the history
* Log stderr of `stack exec ghc` for better feedback

* Execute `stack setup` on its own

* Add changes to ChangeLog
  • Loading branch information
fendor authored Mar 25, 2021
1 parent 9dd7293 commit 84d4c37
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# ChangeLog hie-bios

## TBA - 0.7.6

* Log stderr of stack to display more informative error messages to users. [#254](https://github.com/mpickering/hie-bios/pull/254)
## 2021-03-21 - 0.7.5

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion hie-bios.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Cabal-Version: 2.2
Name: hie-bios
Version: 0.7.5
Version: 0.7.6
Author: Matthew Pickering <matthewtpickering@gmail.com>
Maintainer: Matthew Pickering <matthewtpickering@gmail.com>
License: BSD-3-Clause
Expand Down
14 changes: 9 additions & 5 deletions src/HIE/Bios/Cradle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ configFileName :: FilePath
configFileName = "hie.yaml"

-- | Pass '-dynamic' flag when GHC is built with dynamic linking.
--
--
-- Append flag to options of 'defaultCradle' and 'directCradle' if GHC is dynmically linked,
-- because unlike the case of using build tools, which means '-dynamic' can be set via
-- '.cabal' or 'package.yaml', users have to create an explicit hie.yaml to pass this flag.
Expand Down Expand Up @@ -608,10 +608,14 @@ stackCradle wdir mc syaml =
, cradleOptsProg = CradleAction
{ actionName = Types.Stack
, runCradle = stackAction wdir mc syaml
, runGhcCmd = \args ->
readProcessWithCwd wdir "stack"
(stackYamlProcessArgs syaml <> ["exec", "--silent", "ghc", "--"] <> args)
""
, runGhcCmd = \args -> do
-- Setup stack silently, since stack might print stuff to stdout in some cases (e.g. on Win)
-- Issue 242 from HLS: https://github.com/haskell/haskell-language-server/issues/242
stackSetup <- readProcessWithCwd wdir "stack" (stackYamlProcessArgs syaml <> ["setup", "--silent"]) ""
stackSetup `bindIO` \_ ->
readProcessWithCwd wdir "stack"
(stackYamlProcessArgs syaml <> ["exec", "ghc", "--"] <> args)
""
}
}

Expand Down
23 changes: 22 additions & 1 deletion src/HIE/Bios/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
{-# LANGUAGE DeriveFunctor #-}
{-# OPTIONS_GHC -Wno-orphans #-}

{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
module HIE.Bios.Types where

import System.Exit
Expand Down Expand Up @@ -74,7 +76,26 @@ data CradleLoadResult r
= CradleSuccess r -- ^ The cradle succeeded and returned these options.
| CradleFail CradleError -- ^ We tried to load the cradle and it failed.
| CradleNone -- ^ No attempt was made to load the cradle.
deriving (Functor, Show, Eq)
deriving (Functor, Foldable, Traversable, Show, Eq)


instance Applicative CradleLoadResult where
pure = CradleSuccess
CradleSuccess a <*> CradleSuccess b = CradleSuccess (a b)
CradleFail err <*> _ = CradleFail err
_ <*> CradleFail err = CradleFail err
_ <*> _ = CradleNone

instance Monad CradleLoadResult where
return = CradleSuccess
CradleSuccess r >>= k = k r
CradleFail err >>= _ = CradleFail err
CradleNone >>= _ = CradleNone

bindIO :: CradleLoadResult a -> (a -> IO (CradleLoadResult b)) -> IO (CradleLoadResult b)
bindIO (CradleSuccess r) k = k r
bindIO (CradleFail err) _ = return $ CradleFail err
bindIO CradleNone _ = return CradleNone


data CradleError = CradleError
Expand Down

0 comments on commit 84d4c37

Please sign in to comment.