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

stack run works, everything else does not #6371

Closed
Fabus1184 opened this issue Dec 10, 2023 · 4 comments
Closed

stack run works, everything else does not #6371

Fabus1184 opened this issue Dec 10, 2023 · 4 comments

Comments

@Fabus1184
Copy link

In my project stack run works fine, but stack repl does not, and neither does the VS Code extension, I'm guessing it's the same error, probably something about the internal-libraries, but I can't figure it out.

Output of stack repl:

Details
Using main module:
1.  Package advent-of-code, component advent-of-code:exe:advent-of-code, with main-is file:
    /home/fabian/git/advent-of-code/app/Main.hs.


Warning: The following GHC options are incompatible with GHCi and have not been passed to it: -threaded and
         -O2.
         
Configuring GHCi with the following packages: advent-of-code.

Warning: Multiple files use the same module name:
         * Paths_advent_of_code found at the following paths
           * /home/fabian/git/advent-of-code/.stack-work/dist/x86_64-linux-tinfo6/ghc-9.2.8/build/TH/autogen/Paths_advent_of_code.hs
             (advent-of-code:internal-lib:TH)
           * /home/fabian/git/advent-of-code/.stack-work/dist/x86_64-linux-tinfo6/ghc-9.2.8/build/Y2023/autogen/Paths_advent_of_code.hs
             (advent-of-code:internal-lib:Y2023)
           * /home/fabian/git/advent-of-code/.stack-work/dist/x86_64-linux-tinfo6/ghc-9.2.8/build/advent-of-code/autogen/Paths_advent_of_code.hs
             (advent-of-code:exe:advent-of-code)
         
GHCi, version 9.2.8: https://www.haskell.org/ghc/  :? for help
<command line>: cannot satisfy -package z-advent-of-code-z-TH
    (use -v for more information)

Output of haskell-language-server:

Details
Failed to parse result of calling stack

  Error: [S-6948]
  Stack failed to parse the target(s).

  While parsing, Stack encountered the error:

  Directory not found: advent-of-code:lib:Y2023.

  Stack expects a target to be a package name (e.g. my-package), a package identifier (e.g.
  my-package-0.1.2.3), a package component (e.g. my-package:test:my-test-suite), or, failing
  that, a relative path to a directory that is a local package directory or a parent directory
  of one or more local package directories.

  Note that to specify options to be passed to GHCi, use the --ghci-options option.

link to repo: https://github.com/Fabus1184/advent-of-code

Stack version

stack --version
Version 2.13.1, Git revision 8102bb8afce90fc954f48efae38b87f37cabc988 x86_64 hpack-0.36.0

Method of installation

  • Via GHCup
@mpilgrem
Copy link
Member

I think your problem is indeed related to sub-libraries. However, I think if you switch to the master branch version of Stack things may work.

On Windows 11, I cloned your repository, changed into its root directory and commanded stack repl.

With Stack 2.13.1, it fails with:

❯ stack repl
Using main module:
1.  Package advent-of-code, component advent-of-code:exe:advent-of-code, with main-is file: C:\Users\mike\advent-of-code\app\Main.hs.


Warning: The following GHC options are incompatible with GHCi and have not been passed to it: -threaded and -O2.

Configuring GHCi with the following packages: advent-of-code.

Warning: Multiple files use the same module name:
         * Paths_advent_of_code found at the following paths
           * C:\Users\mike\advent-of-code\.stack-work\dist\6f82b39a\build\TH\autogen\Paths_advent_of_code.hs (advent-of-code:internal-lib:TH)
           * C:\Users\mike\advent-of-code\.stack-work\dist\6f82b39a\build\Y2023\autogen\Paths_advent_of_code.hs (advent-of-code:internal-lib:Y2023)
           * C:\Users\mike\advent-of-code\.stack-work\dist\6f82b39a\build\advent-of-code\autogen\Paths_advent_of_code.hs (advent-of-code:exe:advent-of-code)

GHCi, version 9.2.8: https://www.haskell.org/ghc/  :? for help
<command line>: cannot satisfy -package z-advent-of-code-z-TH
    (use -v for more information)

However, with the master branch version of Stack, I got:

Using main module:
1.  Package advent-of-code, component advent-of-code:exe:advent-of-code, with main-is file: C:\Users\mike\advent-of-code\app\Main.hs.

Building all executables for advent-of-code once. After a successful build of all of them, only specified executables will be rebuilt.
advent-of-code> initial-build-steps (sub-lib + exe)

Warning: The following GHC options are incompatible with GHCi and have not been passed to it: -threaded and -O2.

Configuring GHCi with the following packages: advent-of-code.

Warning: Multiple files use the same module name:
         * Paths_advent_of_code found at the following paths
           * C:\Users\mike\advent-of-code\.stack-work\dist\6f82b39a\build\TH\autogen\Paths_advent_of_code.hs (advent-of-code:sub-lib:TH)
           * C:\Users\mike\advent-of-code\.stack-work\dist\6f82b39a\build\Y2023\autogen\Paths_advent_of_code.hs (advent-of-code:sub-lib:Y2023)
           * C:\Users\mike\advent-of-code\.stack-work\dist\6f82b39a\build\advent-of-code\autogen\Paths_advent_of_code.hs (advent-of-code:exe:advent-of-code)

GHCi, version 9.2.8: https://www.haskell.org/ghc/  :? for help
... Building of modules
Ok, 14 modules loaded.
Loaded GHCi configuration from C:\Users\mike\AppData\Local\stack\ghci-script\d24c17a1\ghci-script
ghci>

@Fabus1184
Copy link
Author

Yes, with the latest git revision stack repl works, although the VS Code extension (actually it's the haskell-language-server) still throws the same error. Is this still an error with stack or the HLS?

@mpilgrem
Copy link
Member

mpilgrem commented Dec 16, 2023

@Fabus1184, the short answer to your question is Yes. HLS support of Stack is a two-way street. The basic problem is described here #6154. Stack supports internal libraries and (a recent development) dependencies on public sub-libraries, but HLS does not fully support Stack supporting them.

EDIT: One thing you might try is: (a) expanding your hie.yaml definition to record the relationship between directories and project components; and (b) building your project once before expecting HLS to work. For example, for the pantry package, which has modules for an internal library in ./int, I have been trying:

cradle:
  stack:
  - path: "./src"
    component: "pantry:lib"
  - path: "./int"
    component: "pantry:lib"
  - path: "./app"
    component: "pantry:exe:test-pretty-exceptions"
  - path: "./test"
    component: "pantry:test:spec"

with partial success; HLS works with the modules other than those that import modules from the internal library of the same package.

@mpilgrem
Copy link
Member

I am closing this, as Stack 2.15.1, with public sublibrary support, has now been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants