Skip to content
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

Import errors with flat files structure and multiple cabal modules #2777

Closed
KristianBalaj opened this issue Feb 10, 2022 · 2 comments
Closed
Labels
component: implicit-hie multi-component Issues relating to multi-component support type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@KristianBalaj
Copy link

Not sure if this is specifically the plugins issue or just a problem with cabal.

I have the following super simple directory structure:

-src
--Main.hs
--Lib.hs
--Test.hs

and module in my cabal file look like this:

library mylib
    exposed-modules:  Lib
    build-depends: base ^>=4.14.3.0
    hs-source-dirs: src
    default-language: Haskell2010

executable myexe
    main-is: Main.hs
    build-depends:    
        base ^>=4.14.3.0, 
        mylib
    hs-source-dirs:   src
    default-language: Haskell2010

test-suite mytest
    type: exitcode-stdio-1.0
    main-is: Test.hs
    build-depends:
        base ^>=4.14.3.0, 
        mylib,
        hspec,
        tasty,
        tasty-hspec
    hs-source-dirs:   src
    default-language: Haskell2010

When having the following imports in the Test.hs file:

import Test.Hspec
import Test.Tasty
import Test.Tasty.Hspec

The VSCode plugin shows me on these lines the following error:

Could not load module ‘Test.Tasty.Hspec’
It is a member of the hidden package ‘tasty-hspec-1.2’.
Perhaps you need to add ‘tasty-hspec’ to the build-depends in your .cabal file.

When I move the Test file into a separate directory or subdirectory, the problem goes away, but I would like not to create subdirectories for such super simple use cases.
I would however expect that the error would not show since the file is only in the mytest module.

@fendor fendor transferred this issue from haskell/vscode-haskell Mar 13, 2022
@fendor fendor added type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. component: implicit-hie and removed status: needs triage labels Mar 13, 2022
@fendor
Copy link
Collaborator

fendor commented Mar 13, 2022

Hi, thank you for your bug report!

HLS's implicit project discovery is flawed, currently the best work-around is to have a hie.yaml in your workspace root directory:

cradle:
  cabal:

Relevant issue #2342

some documentation about hie.yaml can be found here: https://github.com/haskell/hie-bios

@michaelpj michaelpj added the multi-component Issues relating to multi-component support label Jan 16, 2024
@michaelpj
Copy link
Collaborator

Closing as worked around and an instance of a general problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: implicit-hie multi-component Issues relating to multi-component support 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