HLS: Could not find module

Hi, I am very new to Haskell and am trying to import a custom module from one file to another but am running into some issues with VSCode/HLS.

Running ‘cabal build’ works fine, but the module imports are highlighted with the message, “Could not find module ‘(my module name)’ It is not a module in the current program, or in any known package.”

Please let me know if this is a common issue and if I can provide any more context.

Additional info:
The module is in my cabal file under ‘other-modules’ and ‘autogen-modules’

Thank you for reading my question!

Hi!

You can follow the steps here to provide more logs: GitHub - haskell/vscode-haskell: VS Code extension for Haskell, powered by haskell-language-server

Also, you should make sure you open the root of your project in HLS (e.g., the directory that contains the .cabal file).

1 Like

Do you have hie.yaml file?

cradle:
  multi:
    - path: "./src"
      config:
        cradle:
          cabal:
1 Like

PSA that you usually shouldn’t have to write a hie.yaml for cabal projects any more.

If you need a hie.yaml,

cradle:
  cabal:

is sufficient for 95% of use-cases.

3 Likes

@Blake I strongly suspect this is it.

@fendor I’m surprised not to see this gotcha mentioned in the docs. I’m sure I’ve seen a few people on here before with the same problem. I’d make a PR to add it, but I don’t quite have the full picture. Is it VSCode-specific, or are there equivalents for other editors?

1 Like

Good point!

The issue is not vscode specific, but other editors handle it differently. For example, see Configuration — haskell-language-server 2.11.0.0 documentation, the rootPatterns field.

Documentation would be great, I am just not sure where it would be discoverable :thinking:

2 Likes

I have faced this many times.
The sad thing is HLS doesn’t work well with Cabal lol.
Though on the website they say it’s world class tooling, changing Cabal file, freezes HLS or sum
I usually restart the HLS server

Please try that

1 Like

I’ve used many versions of HLS with neovim and haskell-tools.nvim without a problem. I compile using ghcup and it works how I’d expect with Cabal. I doubt this is being caused because of an incompatibility with those tools

2 Likes

I think HLS has some bugs detecting changes in Cabal file
For me atleast I have to always re-start.
I use all the default version installed by GHCUP

HLS is known to have trouble sometimes keeping up with Cabal file changes unfortunately. It doesn’t always happen for me, but it’s very possible

A fix is being worked on

2 Likes

That’s nice to hear!