Haskell language server doesn't recognise installed modules

Hello community.

I have installed Pandoc module through cabal using:

cabal install pandoc.

I can successfully load it in GHCI using:

:set -package pandoc

and importing with:

import Text.Pandoc

However, HLS doesn’t recognise the modules in VSC:

80800e32936c77675e3359e9c452e8b44a3b4248

In my .cabal file, I added:

-- Other library packages from which modules are imported.
    build-depends:    pandoc, pandoc-types, base ^>=4.17.0.0

but the problem persists. How can I solve this ?

1 Like

Does cabal build works??. Also notice that cabal install pandoc does not make it available in the context of a project. I think cabal install pandoc will install the pandoc tool in your system.

3 Likes

Thank you for the reply.

Yes, it does work.

Is it possible to make it available ?

EDIT:

I added package split to build-depends, and I experience the same issue when I do:

import Data.List.Split

Could not load module ‘Data.List.Split’
It is a member of the hidden package ‘split-0.2.3.5’.
You can run ‘:set -package split’ to expose it.

1 Like

Hi!

Please provide VSCode logs GitHub - haskell/vscode-haskell: VS Code extension for Haskell, powered by haskell-language-server.

Judging from the shown view, it seems like you might not have opened to root of your project in VSCode. Please make sure you have openend the directory that contains the .cabal file in VSCode, via “Open Folder… [Ctrl + k Ctrk + o]”.

4 Likes

Impressive. That was the problem. Thank you so much.

I didn’t know I had to do that so HLS can pickup dependencies in my .cabal file.

2 Likes

I know the problem has been solved but just to clarify. In general cabal install <package> is a bad idea if you just want a dependency. Maybe you are thinking about python’s pip install which makes dependencies available for your python interpreter.

cabal install is used to install software in your system. That is building a binary executable an put it in your PATH. Think about it as apt-get install in debian/ubuntu or executing a program.exe file in windows.

In order to make dependencies available, you have to create a .cabal and add dependencies to it. These dependencies will be visible only within the project!. That means if you try to use the dependencies out of the project you’ll get an error like "Could not load … ".

Because you are out of the project folder, dependencies can’t be used. HLS makes its best effort to find a .cabal file or a package.yaml, ut of course, you have to cd into the right folder :smile:

Hope it makes clearer how cabal works. (BTW most of it applies to stack)

6 Likes

Thank you for the clarification !

What’s the preferred way ?

1 Like

See:

I’d also recommend the GHCup first steps, which is a good introduction to Haskell tooling.

5 Likes