Files in app/ directory of stack projects fail to build w/o taking special steps
Your environment
Which OS do you use? Ubuntu Which version of GHC do you use and how did you install it? 9.4.4 / ghcup. Note that issue repros with other supported versions How is your project built (alternative: link to the project)? stack defaults. See repro instructions on new stack project below
Which LSP client (editor/plugin) do you use?
neovim + coc.nvim. Repros in VSCode as well
Which version of HLS do you use and how did you install it?
1.9.0.0. As above, other versions repro
Have you configured HLS in any way (especially: a hie.yaml file)? No, but see note below
Steps to reproduce
-
stack new --resolver nightly-2023-01-28 test - Ensure
ghc-9.4.4andHLS-1.9.0.0are installed - Navigate to
./test - Open
app/Main.hs. Note that an error is issued:cannot satisfy -package test-0.1.0.0. If other dependencies are specified inpackage.yaml, it may complain of being unable to satisfy one of those instead.
Some observations that are hopefully clues:
- If
app/Main.hsis opened first and thensrc/Lib.hs, the same error is displayed at the top of both files. In reverse order,HLSworks fine on any files insrcbut still fails on files inapp. - I've stumbled across several ways to fix the problem. I suspect they're all achieving the same effective result. Make sure to close your editor and run
stack purgebefore trying them:- Run
stack build. Openapp/Main.hsup in an editor. It works! (Sidenote: I do this /stack runregularly during development, so I've been seeing this problem disappear "magically" for a while. It was only upon starting a new project today and deciding to dig in and file a bug that I made the connection.) - Run
haskell-language-server-wrapper. This will fail onSetup.hsfor a default stack project, but we can just ignore that. This seems like a clue thathaskell-language-server-wrapperis doing something different build-wise when run with--lspvs. without. - Make a simple
hie.yaml, i.e.cradle:\n stack:. Same result. This could be a clue that implicit-hie is being used strangely (or itself has a bug).
- Run
Expected behaviour
Everything works without taking any of the steps detailed above.
Actual behaviour
(Covered in Steps to reproduce)
Debug information
N/A
Unfortunately, these are long-standing bugs with the stack/HLS interaction. I dont recall the exact issue, but there are plenty of them.
Fixing this requires closer work with stack maintainers and working out our requirements.
It sounds like this is unlikely to be fixed in the near future, so I'll emphasize for others that there are workarounds. Among them, the simplest is to close your editor, run stack purge && stack build, and then continue coding.