dramforever/vscode-ghc-simple

Cabal fails to find project on windows

edmundnoble opened this issue · 9 comments

Status

  • A workaround is available
    The following workaround might help with some cases of this issue:

    OK. Dig more. I found a workaround. Just pick 'bare' type for the workspace and ghci will pick the dependencies from the .ghc.environment.-- file under your project and load your modules successfully.

  • A fix is written
  • A fix is released
  • The fixed verison is on the marketplace.

  • Version of vscode-ghc-simple: 0.1.7
  • Version of VSCode: 1.32.3
  • Version of Haskell-related tools:
    • GHC: 8.6.4
    • Stack:
    • Cabal: 2.4.10

Steps to reproduce

Open a Haskell file in VS code, where the workspace is cabal new.

The cabal instance started by vscode-ghc-simple reports:

    -> :set prompt ""
ghci | cabal.exe: No targets given and there is no package in the current directory.
ghci | Use the target 'all' for all packages in the project or specify packages or
ghci | components by name or location. See 'cabal build --help' for more details on
ghci | target options.
ghci | 

Hinting that cabal is being run in the wrong folder. However, running cd (which prints out the current working directory) using the same options as cabal is run with shows the exact same path that I get when I run cd myself from cmd inside of the project folder, and running cabal new-repl from there works fine.

Workspace

Create a project using cabal init, use the cabal 2.4 style init when prompted. Use the src/ source directoy.

This is a weird problem.

I cannot reproduce this on Linux: everything works fine. It seems to be Windows specific and cabal new-build specific.

Hinting that cabal is being run in the wrong folder. However, running cd (which prints out the current working directory) using the same options as cabal is run with shows the exact same path that I get when I run cd myself from cmd inside of the project folder, and running cabal new-repl from there works fine.

I remember wondering about this exact weirdness back when I first tried to add cabal new-build support, and I was on Windows back then. I guess this problem didn't magically fix itself.

Wait, when outside of a project cabal new-repl actually builts a 'fake-package' and launches GHCi from it. So how is this error message even possible?

I met the same problem on MacOS. ghc-simple output hints that it's running outside of the current project folder and trying to build a fake-package. No modules from my project loaded.

OK. I did some tests:

  1. cabal new-repl under my project folder works fine
  2. start vscode from my project directory, open a haskell source file, ghc-simple outputs that it's trying to build a fake-package and success. But when it tried to load my module, it complains it can't find dependencies packages of my module and failed to load my module
  3. I cabal init a hello-world project, and ghc-simple load the source file successfully because the module has no extra dependencies except base

based on above 3 points, I guess ghc-simple start 'cabel new-reple' under the fake-package folder, not my project folder. So questions are:

  1. why do we need to try to build a fake-package before start ghci?
  2. will building the fake-package change the working directory for this extension?
  3. how can we track the working directory before start ghci and after building the fake-package?
  4. any thing else do we need to identify this problem?

OK. Dig more. I found a workaround. Just pick 'bare' type for the workspace and ghci will pick the dependencies from the .ghc.environment.-- file under your project and load your modules successfully.

why do we need to try to build a fake-package before start ghci?

This is the behavior of cabal new-repl outside of a project directory and is not implemented in vscode-ghc-simple.

Which is weird, since I do set cwd of the subprocess to the workspace folder. I'll have to investigate why it's not working as intended.

OK. So the problem is when ghc-simple trying to start a session, the working directory is not my project directory where the active source file of the workspace located.
Wait, the active source file of the workspace is located at /src, not . Maybe cwd is /src , not . But how comes ghci working under the ? Can't figure out that.

AFAICT the problem is that vscode launches cabal with a cwd that has a lowercase drive letter.
For example, in cmd.exe:

G:\cabaltest>cabal new-build --dry-run
Resolving dependencies...
Build profile: -w ghc-8.4.3 -O1
In order, the following would be built (use -v for more details):
 - cabaltest-0.1.0.0 (exe:cabaltest) (first run)

G:\cabaltest>cd .. && cd g:\cabaltest

g:\cabaltest>cabal new-build --dry-run
cabal: No targets given and there is no package in the current directory. Use
the target 'all' for all packages in the project or specify packages or
components by name or location. See 'cabal build --help' for more details on
target options.

But I'm on MacOS and also had this problem.