I have a project set up in VS-code with the HLS extenion.
For functions that are imported I can hoover over it or click "Peek" in order to see it's type. But when I click "Go to definition" It says that there is no definition (for X).
How can I set up the project so that "Go to definition" works? (It seems like I should be close in a sense as HSL is detecting the type of the definition.)
From the comments, it sounds like HLS can show you definitions from the current package, or perhaps from what cabal calls "local" packages, but not from nonlocal dependency packages. To me this seems sort of sensible; it is after all possible to install package binaries, so the original source may not be available at all. In your case it probably is, but the connection between where to look for the package binary and where to look for the package source is... quite opaque. (N.B. typing information is included in package binaries, which helps explain why peeking works okay even for nonlocal dependencies.)
Here's a sketch of something you could try if you really want to be able to jump to as many sources as possible.
cabal freeze to produce a list of all the packages you depend on, even transitively, along with version information.cabal unpack in a loop to create directories with sources for each package in the list.packages: list in your cabal.project.You will probably need to do some manual fixups of various kinds for this process to work well. For example, you definitely aren't going to be able to build base from source this way; it's possible there are other packages that ship with GHC that have a similar property. You should probably also try this with just one or two dependencies to begin with to make sure that it's going to actually make definitions available to HLS, as I'm not super confident on that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With