Skip to content

same hs-source-dirs for multiple components causes confusion #3606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andreabedini opened this issue May 25, 2023 · 4 comments
Closed

same hs-source-dirs for multiple components causes confusion #3606

andreabedini opened this issue May 25, 2023 · 4 comments
Labels
can-workaround component: implicit-hie type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@andreabedini
Copy link

I am troubleshooting haskell-language-server doing something wrong on the cabal repository. If I do:

$ haskell-language-server-wrapper cabal-install/tests/IntegrationTests2.hs
...
File:     /home/andrea/code/cabal/cabal-install/tests/IntegrationTests2.hs
Hidden:   no
Range:    77:8-77:19
Source:   not found
Severity: DsError
Message: 
  Could not load module ‘Data.Tagged’
  It is a member of the hidden package ‘tagged-0.8.7’.
  Perhaps you need to add ‘tagged’ to the build-depends in your .cabal file.

which is wrong because IntegrationTests2 is part of the test-suite integration-tests2 which has indeed tagged among its build-depens.

test-suite integration-tests2
  import: warnings, base-dep, cabal-dep, cabal-syntax-dep, cabal-install-solver-dep
  ghc-options: -rtsopts -threaded
  type: exitcode-stdio-1.0
  main-is: IntegrationTests2.hs
  hs-source-dirs: tests
  default-language: Haskell2010

  build-depends:
        bytestring,
        cabal-install,
        containers,
        directory,
        filepath,
        tasty >= 1.2.3 && <1.5,
        tasty-hunit >= 0.10,
        tagged

to confirm I can do

cabal repl cabal-install/tests/IntegrationTests2.hs

which works ok.

I suspect that this happens because multiple components hs-source-dirs: tests and indeed adding --debug to hls shows

2023-05-25T03:26:53.728418Z | Debug | executing command: cabal --builddir=/home/andrea/.cache/hie-bios/dist-cabal-2d99de0514754dc7a0fdd74187917280 v2-repl --with-compiler /home/andrea/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /home/andrea/.cache/hie-bios/ghc-pkg-5fcb2ba7874e41991c2aef3124b07071 cabal-install:test:unit-tests

which is indeed the wrong component.

I checked directly with hie-bios (version 0.12.0) and it gets the component right

$ hie-bios flags cabal-install/tests/IntegrationTests2.hs
...
[Debug] executing command: cabal --builddir=/home/andrea/.cache/hie-bios/dist-cabal-2d99de0514754dc7a0fdd74187917280 v2-repl --with-compiler /home/andrea/.cache/hie-bios/wrapper-b54f81dea4c0e6d1626911c526bc4e36 --with-hc-pkg /home/andrea/.cache/hie-bios/ghc-pkg-5fcb2ba7874e41991c2aef3124b07071 cabal-install/tests/IntegrationTests2.hs
[Debug] Build profile: -w ghc-9.4.5 -O1
[Debug] In order, the following will be built (use -v for more details):
[Debug]  - cabal-install-3.11.0.0 (test:integration-tests2) (first run)
[Debug] Configuring test suite 'integration-tests2' for cabal-install-3.11.0.0..
...

Your environment

Which OS do you use? Linux
Which version of GHC do you use and how did you install it? 9.4.5, via ghcup
How is your project built (alternative: link to the project)? https://github.com/haskell/cabal/
Which LSP client (editor/plugin) do you use? N/A
Which version of HLS do you use and how did you install it? 2.0.0.0 from ghcup
Have you configured HLS in any way (especially: a hie.yaml file)? No

@andreabedini andreabedini added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels May 25, 2023
@fendor
Copy link
Collaborator

fendor commented May 25, 2023

Thank you for the bug report! This is a bug in implicit-hie.

You can work around it by adding an explicit hie.yaml:

cradle:
  cabal:

I can confirm from my personal experience on cabal, that this works much better.

@fendor fendor closed this as completed May 25, 2023
@fendor fendor reopened this May 25, 2023
@andreabedini
Copy link
Author

andreabedini commented May 26, 2023

Thanks @fendor, your workaround does the trick! I did endup using a hie.yaml file but I didn't realise a simple one like that would be enough!

Edit: indeed this is what implict-hie spits out

cradle:
  cabal:
...
    - path: "cabal-install/tests"
      component: "cabal-install:test:unit-tests"

    - path: "cabal-install/tests"
      component: "cabal-install:test:mem-use-tests"

    - path: "cabal-install/tests"
      component: "cabal-install:test:integration-tests2"

    - path: "cabal-install/tests"
      component: "cabal-install:test:long-tests"
...

@fendor
Copy link
Collaborator

fendor commented May 26, 2023

I did endup using a hie.yaml file but I didn't realise a simple one like that would be enough!

The simple cabal cradle uses cabal repl <file>, and cabal almost always figures it out correctly. There is rarely a situation where it doesn't, that's why the simple cradle is virtually always the best choice, imo.

@michaelpj
Copy link
Collaborator

Should be fixed now we're not using implicit-hie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can-workaround component: implicit-hie type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

3 participants