cachix/ghcide-nix

VS Code, ghcide, nix - could not find module

KristianBalaj opened this issue · 0 comments

Description
I'm trying to use the setup VS Code, ghcide and nix.
I'm using this https://github.com/cachix/ghcide-nix to make it work.
The ghcide works nicely in the VS Code for the base Haskell package but the problem is when trying to use any other package.

Copy of this ghcide issue.

To reproduce
I have a dependency in the .cabal file and the ghcide gives me an error could not find a module.

This is the part of my testproj.cabal file:

executable testproj
  main-is:             Main.hs
  -- other-modules:
  -- other-extensions:
  build-depends:       base >=4.12 && <4.13
                      , scotty
  hs-source-dirs: src
  default-language:    Haskell2010

image

When I run the command nix-shell shell.nix --run 'ghcide' the output is the same:

ghcide version: 0.1.0 (GHC: 8.6.5) (PATH: /nix/store/xhg5lzac77x3y6ww54qjrvi3ygyjxzq9-ghcide-0.1.0-exe-ghcide/bin/ghcide)
Ghcide setup tester in /home/kristian/testproj.
Report bugs at https://github.com/digital-asset/ghcide/issues

Step 1/6: Finding files to test in /home/kristian/testproj
Found 1 files

Step 2/6: Looking for hie.yaml files that control setup
Found 1 cradle

Step 3/6, Cradle 1/1: Implicit cradle for /home/kristian/testproj
Cradle {cradleRootDir = "/home/kristian/testproj", cradleOptsProg = CradleAction: Default}

Step 4/6, Cradle 1/1: Loading GHC Session

Step 5/6: Initializing the IDE

Step 6/6: Type checking the files
File:     /home/kristian/testproj/src/Main.hs
Hidden:   no
Range:    4:7-4:17
Source:   not found
Severity: DsError
Message: 
  Could not find module ‘Web.Scotty’
  It is not a module in the current program, or in any known package.
Files that failed:
 * /home/kristian/testproj/src/Main.hs

Completed (0 files worked, 1 file failed)

My shell.nix file looks like this (./release.nix contains only
(import <nixpkgs> {}).haskellPackages.callPackage ./default.nix {}
and the ./default.nix file is the output of the cabal2nix command)

{ nixpkgs ? import <nixpkgs> {} }:
let
  inherit (nixpkgs) pkgs;
  inherit (pkgs) haskellPackages;

  project = import ./release.nix;
in

pkgs.stdenv.mkDerivation {
  name = "shell";
  buildInputs = project.env.nativeBuildInputs ++ [
    haskellPackages.cabal-install
  ];
}

When building the package with nix-build release.nix it works like a charm.
Also running ghci inside the nix-shell and then calling import Web.Scotty works fine.

Expected behaviour
All the imported packages that are in the .cabal file under the build dependencies should be available for inspection in the project source files in VS Code (imported functions display type and documentation on hover etc.).