I have a project that looks like this:
- my-project
- backend
- stack.yaml
- src
- ... a bunch of haskell files
- ... exe & test folders here too
- frontend
- ... an Elm frontend app
- flake.nix
- ... other files
When I open this in vscode (cd my-project && codium .) and go to one of the haskell files I get some errors it cannot find packages.
However, when I first cd into the backend folder and then open code (cd my-project/backend && codium .) then everything works perfectly.
So I think the HLS is just being started at the root and then not able to pick up the haskell project properly.
I tried adding "haskell.serverExtraArgs": "--cwd /home/theoddler/Dev/my-project/backend" to my .vscode/.settings.json file, but I get the same errors.
How do I fix this? Can I change the directory where the vscode plugin starts the HLS?
I ran into a similar problem, but I am using Cabal instead of Stack. I wasn't quite happy with the solution of moving the files to the root directory just to make a VS Code Plugin work, as this would break my code structure.
I found the following workaround, where my
.cabal(and hopefully yourstack.yaml) file can stay in the./backend/directory:my-project.code-workspaceto your projects root directory:File -> Open Workspace from File...and selectmy-project.code-workspace./backend/settings.jsonto hide the redundant./backend/directory from the Explorer sidebar.Note: whenever you edit a file in
./backend/, the Explorer will highlight this file insidebackendfolder instead of themy-workspace/backendfolder - but at least it will disappear again, once you switch to another file.