haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Use stack/cabal cradle if no project config + ghc not in PATH + stack/cabal in PATH

Open jneira opened this issue 4 years ago • 13 comments

  • Opening a single file require to have ghc in path
  • However stack users can do a stack repl to load those files (stack uses the global project configuration)
  • So if we have stack in PATH but no GHC we could use stack to load those files as well
  • Not sure if it can be done in hie-bios or implicit-hie-cradle

//cc @Avi-D-coder @fendor

jneira avatar Dec 21 '20 21:12 jneira

I can take a look on Christmas.

Avi-D-coder avatar Dec 21 '20 21:12 Avi-D-coder

Thinking in it twice, there exists the possibility of use cabal, as you can set in cabal global config the path to ghc without having it in the global PATH. Not sure if that is a common setup though. Maybe we should check if cabal exec ghc -- --version works (and in a similar way stack exec ghc -- --version, maybe with --skip-ghc-check to avoid its download?) and proceed to use cabal or stack if ghc is set.

jneira avatar Dec 22 '20 07:12 jneira

Awesome, this is exactly what I have hoped for a few weeks, but couldn't come up with some specification. Thank you for raising this issue!

Ailrun avatar Dec 22 '20 07:12 Ailrun

I have to say that it arose in a conversation with a haskell beginner (@hieung1401 in the fp discord channel), who was using directly stack for fire a repl. He had to create a stack project only to make hls work. But even experienced haskell developers work with standalone files so it can be handy for everybody.

jneira avatar Dec 22 '20 08:12 jneira

Yes, true. I installed system GHC only to make HLS work for small scripts that I need to use from time to time. If HLS supports such a stack detection mechanism, it would allow much compact setting for Haskell dev.

Ailrun avatar Dec 22 '20 08:12 Ailrun

I would say that cabal could not be as useful as stack cause you can configure the stack global project as you want, including dependencies, but afaik you cant do the same in the global cabal config, only set the path to ghc. So in this case i would choose stack first if both tools are available.

jneira avatar Dec 22 '20 10:12 jneira

@Avi-D-coder has you the opportunity to make some progress on this?

jneira avatar Jan 19 '21 07:01 jneira

I took a look, but I have not had time to finish.

Avi-D-coder avatar Jan 19 '21 13:01 Avi-D-coder

it is a common issue among beginners so probably we should add it as known issue in troubleshooting section

jneira avatar Apr 08 '21 14:04 jneira

it is a common issue among beginners so probably we should add it as konwn issue in troubleshooting section

I did really met some students with this problem, especially some of them following the instruction from the class but not installed correctly(they thought they had made it), which cause HLS unable to work.

July541 avatar Apr 08 '21 15:04 July541

Is there an end-user solution for this? I'm trying to setup Haskell on a new machine and running into this problem again

RedTachyon avatar Oct 08 '21 09:10 RedTachyon

I am afraid that no other than set ghc in path (f.e. with PATH=$(stack path --compiler-exe):PATH && code .) Or if you are using ghcup: https://ghcup.readthedocs.io/en/latest/guide/#with_ghc-wrapper-eg-for-hls

jneira avatar Oct 08 '21 10:10 jneira

It seems using the following explicit cradle works:

cradle:
  stack:

Save this as hie.yaml into the directory, and just use open VSCode without custom PATH. I assumed this configuration should be able to force hls to call stack, and it works pretty well.

ruifengx avatar Feb 03 '22 13:02 ruifengx