haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.63k stars 696 forks source link

`cabal repl` ignores `.ghci` files #8544

Open Soupstraw opened 2 years ago

Soupstraw commented 2 years ago

Describe the bug cabal repl ignores the .ghci file in the project directory. I also tried to put the .ghci file into my home directory, passing a .ghci file via the -ghci-script option, but the file is never loaded no matter which method I use.

To Reproduce Steps to reproduce the behavior:

After doing the steps above, the .ghci file is ignored by the REPL and it runs as it would without a .ghci file.

Expected behavior The repl starts and runs all the commands in the .ghci file.

System information

Mikolaj commented 2 years ago

Thank you for the report. Does it ever work? I suppose ghci works fine? Does cabal repl do what it should in any circumstance? In older versions of cabal? With special options? Not under Nix? On Windows? With newer GHC?

sorki commented 1 year ago

I've tested (different repository which doesn't use haskell.nix) with

and it works, both ./.ghci and ~/.ghc/ghci.conf are loaded. I think this can be safely closed.

goertzenator commented 2 months ago

I can add some insight here:

For multi-package projects, cabal repl will indeed ignore the project .ghci file when run at the project level. My work around was to push the .ghci file into the package directory I was working with, and then it worked.

I expect cabal repl to check the current directory for a .ghci because that's what the documentation says. This is a valid bug that should be reopened.

geekosaur commented 2 months ago

If I run bare ghci from a project directory, it's also not read. Which makes it ghc's bug that we can't do anything about.

hasufell commented 1 week ago

If I run bare ghci from a project directory, it's also not read. Which makes it ghc's bug that we can't do anything about.

I cannot confirm this.


My use case is that I want to run cabal repl -b foo,bar,baz in an empty directory with just a .ghci file to do some exercises from a book I'm reading. I don't need a project or package. The .ghci file is ignored. ghci does correctly read it.

There are workarounds, but it's bad UX.