What's the current status of HLS cradle discovery?

Back in the past I used to have to write a hie.yaml to get HLS (through lsp in emacs) to work correctly. It always just contained

cradle:
  cabal:

More recently it seemed that I didn’t have to do that. Somehow it just worked out itself that the cradle should be cabal. I don’t think I’ve written a hie.yaml file by hand in at least a year. However, even more recently, HLS stopped being able to see modules from external packages (i.e. from non-boot packages). The first hit on Kagi is an HLS Github issues that explains that you have to write a hie.yaml file, but it’s from 2020.

What is the current status of this? Should I expect HLS to set up a cabal cradle for me by default? Last time I looked into this, cradle discovery had some heuristics about detecting .cabal or stack.yaml files to work out which cradle to choose automatically, but it was often flaky. Have I got the configuration wrong somewhere else?

The user experience around this is rather sad. There’s no indication at all what’s wrong. HLS just says it can’t find the modules in question, even though cabal build works without problems. I wouldn’t expect a new user to have the patience to resolve this issue. I’d expect them to just stop using HLS (or even stop using Haskell).

3 Likes

There’s an open issue about the bad error message:

And last time I asked @fendor wrote:

We aim to migrate away from implicit-hie, or at least generate smarter cradles in the future.

1 Like

Ah, that explains it. It’s because I have a common stanza!

And sadly cabal now generates a file with a common stanza if you run cabal init, so a lot of beginners will run into this.

1 Like

Yes, that’s exactly how that stanza got there in my case too.

It is kind of ironic that I am one of the people that pushed cabal init to use a common section but HLS can’t handle it by default…

It is currently the plan to fix this issue until the next HLS release.

7 Likes

Good to hear, thanks!

A nice integration test would be to generate a project with cabal init and check that everything works.

5 Likes