Open TeofilC opened 1 year ago
cc @wz1000 ? I think it sounds like there may be a stack bug here, but possibly also we should try and be more robust somehow? not sure.
@michaelpj We have identified this issue before: https://github.com/haskell/haskell-language-server/issues/366#issuecomment-1025706363 and https://github.com/haskell/haskell-language-server/issues/1822#issuecomment-895063073
However, maybe @wz1000 has an idea for fixing this. Or we try to fix it upstream.
Nice! Feel free to close this as a duplicate if this is being tracked elsewhere
I have the same issue. My package.yaml
looks something like this
name: foo
version: 0.0.1
dependencies:
- base
library:
source-dirs: src
dependencies:
- megaparsec
- parser-combinators
- text
executable:
source-dirs: app
main: Main.hs
tests:
foo-test:
main: Spec.hs
source-dirs: test
dependencies:
- foo
- megaparsec
- tasty
- tasty-hunit
- text
and I was getting the missing package for tasty in my test files.
A workaround I’m using is to add these missing dependencies to the top-level dependencies
property:
dependencies:
- base
- tasty
- tasty-hunit
While this isn’t ideal as it adds those dependencies to all components, at least HLS works correctly with this config.
After upgrading to GHC-9.4.5, we've been noticing a lot more of the
-package ... is hidden
errors in HLS with a stack multi-cradle. Initially I thought this was merely #366. But after further testing it's clear that this is caused by something else. #366 is caused bystack repl
failing to pass the correct arguments when components aren't already built. But this error also happens when they have successfully built.I then compared the dynflags that
cabal
andstack
produce for the same project. I noticed thatcabal
passed-this-unit-id
whilestack
did not. Adding-this-unit-id <package-name>
to ghc-options for each package made the new problem go away.So, my theory is that because
stack repl
doesn't pass-this-unit-id
to GHC, something with GHC's new MHU breaks, causing only the dependencies of one package to be exposed in HLS's GHC API session.My impression is that this issue will occur when using HLS, with stack, GHC 9.4, and any session with multiple components loaded.
I've created a somewhat minimal reproducer below.
Your environment
Which OS do you use? NixOS
Which version of GHC do you use and how did you install it? GHC 9.4.5 using nix
How is your project built (alternative: link to the project)? stack
Which LSP client (editor/plugin) do you use? emacs+lsp-mode
Which version of HLS do you use and how did you install it? 1.10.0 and 2.0.0 (built with nix)
Have you configured HLS in any way (especially: a
hie.yaml
file)? yes, hie.yaml generated bygen-hie
Steps to reproduce
I've created a somewhat minimal reproducer: https://github.com/TeofilC/hls-repro-1 It features two packages that have different dependencies. When opening both in a single HLS session with stack, HLS fails with a
-package is hidden
error.git clone https://github.com/TeofilC/hls-repro-1.git
cd hls-repro-1
nix develop
(if you use nix or get stack/hls some other way)stack build
haskell-language-server -d pack-a/src/Lib1.hs pack-b/src/Lib2.hs
If using nix make sure you have the following in your .stack/config:
Expected behaviour
HLS should be able to load these modules and can do if we use cabal instead.
Actual behaviour
It fails:
Debug information