haskell/hie-bios

How to use hie with custom-setup?

hanjoosten opened this issue · 2 comments

In a project I use, we have a build-type: Custom. During executing Setup.hs, a new .hs file is being generated.
Currently, I use the HSL setup with VSCode. That works great, except that before it is working, we have to manually build the project, so that the generated file can be found.
Is there support for projects with a Custom build-type?

Project I am talking about: https://github.com/AmpersandTarski/Ampersand
The actual setup is done using .devcontainer

Hi!

This seems to happen because we run stack repl (and cabal repl) to find the compilation options of components, but the hook you supplied is only run upon build, irrc.
It seems to work with the following changes to Setup.hs:

main :: IO ()
main = defaultMainWithHooks (simpleUserHooks {buildHook = generateHook, replHook = generateHook1 })

generateHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> BuildFlags -> IO ()

-- | Generate Haskell modules that are required for the build and start the build
generateHook pd lbi uh bf = do
  generateBuildInfoModule (T.pack . prettyShow . pkgVersion . package $ pd)
  generateStaticFileModule
  buildHook simpleUserHooks pd lbi uh bf -- start the build

generateHook1 :: PackageDescription -> LocalBuildInfo -> UserHooks -> ReplFlags -> [String] -> IO ()

-- | Generate Haskell modules that are required for the build and start the build
generateHook1 pd lbi uh rf args = do
  generateBuildInfoModule (T.pack . prettyShow . pkgVersion . package $ pd)
  generateStaticFileModule
  replHook simpleUserHooks pd lbi uh rf args-- start the build

(I am not checking for validity, or how many times this will rebuild now stuff because it re-touches the generated file).

I also used a cabal cradle:

cradle:
  cabal:

but that was mainly because I am more comfortable understanding cabal shenanigans. However, it might be possible that this doesn't work for stack: commercialhaskell/stack#4315

We overall might have a better experience, if we make use of a proper cabal API as we are implementing here: haskell/cabal#7500. And then, we will have to teach stack about it.

Thank you very much for the suggestion. and also for the links. They give good insight in all the hard work being done for Haskell tooling. Thanks!