dramforever/vscode-ghc-simple

"Could not find module" if there is a module import section in .hs

kirillFedorov1 opened this issue · 9 comments

I'm sorry if my question is stupid, I'm new to Haskell and Vscode. I like the error highlighting feature, but if there is a module import section in my .hs file, every time I get "Could not find module `Module.Name'". I use windows, stack, and .cabal file.
If I need Test.QuickCheck, I add this in project.cabal:

library
  hs-source-dirs:      src
  exposed-modules:     Exercises
  ghc-options:         -Wall -fwarn-tabs
  default-language:    Haskell2010
  build-depends:       base >= 4.7 && < 5
                     , QuickCheck

test-suite tests
  hs-source-dirs:       tests
  main-is:              tests.hs
  ghc-options:          -Wall -fno-warn-orphans
  type:                 exitcode-stdio-1.0
  default-language:     Haskell2010
  build-depends:        base
                      , exercises
                      , hspec
                      , QuickCheck

Thanks for reporting. Does this issue persist after running the VSCode command 'Restart GHCi sessions'? (See https://github.com/dramforever/vscode-ghc-simple/blob/master/README.md#commands)

If so paste the full output log (Output tab, select GHC in the drop down) into a gist or something and link it here, and I'll take a look.

It would also help if you get your setup into a repo and link it here.

I should write vscode-ghc-simple.restart in vscode command palette, right? It says no commands matching.
Here is repo: https://github.com/kirillFedorov1/exercises

Yeah whatever command that looks like it. If that doesn't work I'll have a look after I get home. I only have my mobile with me now.

Here is GHC log:

Starting GHCi with: ["stack","exec","ghci"]
(Under default cwd)
    -> :set prompt ""
ghci | "stty"   ७  譥
ghci | , ᯮ塞 ணࠬ   䠩.
ghci | GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
ghci | Prelude> 
ghci | ===ghci_barrier_0.7830798444859766===
    -> :set prompt-cont ""
ghci | 
ghci | ===ghci_barrier_0.34408724992151685===
    -> :set -fno-diagnostics-show-caret -fdiagnostics-color=never -ferror-spans
    |> :set -fdefer-type-errors -fdefer-typed-holes -fdefer-out-of-scope-variables
    |> :set -fno-hide-source-paths
    |> :set -Wno-error=missing-home-modules
    |> :set -Wall
    |> :seti -Wno-type-defaults
ghci | 
ghci | ===ghci_barrier_0.46417449727160154===
    -> :set -fobject-code
    |> :load "*d:\\ssd-data\\work\\exercises\\src\\Exercises.hs"
ghci | [1 of 1] Compiling Main             ( D:\ssd-data\work\exercises\src\Exercises.hs, D:\ssd-data\work\exercises\src\Exercises.o )
ghci | 
ghci | D:\ssd-data\work\exercises\src\Exercises.hs:2:1-22: error:
ghci |     Could not find module `Test.QuickCheck'
ghci |     Use -v to see a list of the files searched for.
ghci | 
ghci | D:\ssd-data\work\exercises\src\Exercises.hs:3:1-31: error:
ghci |     Could not find module `Test.QuickCheck.Checkers'
ghci |     Use -v to see a list of the files searched for.
ghci | 
ghci | D:\ssd-data\work\exercises\src\Exercises.hs:4:1-30: error:
ghci |     Could not find module `Test.QuickCheck.Classes'
ghci |     Use -v to see a list of the files searched for.
ghci | Failed, no modules loaded.
ghci | 
ghci | ===ghci_barrier_0.8503426273566905===
    -> :set -fbyte-code
    |> :set +c
    |> :load "*d:\\ssd-data\\work\\exercises\\src\\Exercises.hs"
ghci | [1 of 1] Compiling Main             ( D:\ssd-data\work\exercises\src\Exercises.hs, interpreted )
ghci | 
ghci | D:\ssd-data\work\exercises\src\Exercises.hs:2:1-22: error:
ghci |     Could not find module `Test.QuickCheck'
ghci |     Use -v to see a list of the files searched for.
ghci | 
ghci | D:\ssd-data\work\exercises\src\Exercises.hs:3:1-31: error:
ghci |     Could not find module `Test.QuickCheck.Checkers'
ghci |     Use -v to see a list of the files searched for.
ghci | 
ghci | D:\ssd-data\work\exercises\src\Exercises.hs:4:1-30: error:
ghci | Failed, no modules loaded.
ghci |     Could not find module `Test.QuickCheck.Classes'
ghci |     Use -v to see a list of the files searched for.
ghci | 
ghci | ===ghci_barrier_0.8545327734442572===
    -> :show modules
ghci | 
ghci | ===ghci_barrier_0.5270405437886829===
    -> :module
ghci | 
ghci | ===ghci_barrier_0.07095352467994531===

But I didn't get how to restart GHCi sessions, vscode-ghc-simple.restart doesn't work.

Are you developing by opening the directory as a workspace and then opening files in the workspace? If not please do that because that's how we detect project configuration (stack.yaml, *.cabal, etc), and if you just open the file it won't be detected as being in any directory (because we can't really know without searching for files everywhere). If you are already doing that then something is wrong and I'll investigate further.

I'm having a bit of an issue with my setup so sorry for being unable to check these things myself.

I checked your repo and it's working fine. I'm pretty sure it's the issue I mentioned in the comment above (workspace vs single file). Could you confirm if this is the case? If so I think I'll mention it in the readme.

I have a directory called "work" opened in vscode as my workspace, and there are several projects in "work", one of them is "exercises" which I need right now.
I've tried to open the "exercises" directory as a workspace, but then I get "Error while start GHCi" and the log is:

Starting GHCi with: ["stack","repl","--no-load","\u001b[0mexercises:lib","exercises:test:tests\u001b[0m"]
(Under cwd d:\ssd-data\work\exercises)
    -> :set prompt ""
ghci | "stty"   ७  譥
ghci | , ᯮ塞 ணࠬ   䠩.
ghci | �[0mInvalidAbsDir "D:\\ssd-data\\work\\exercises\\\ESC[0mexercises:lib"�[0m
Error starting GHCi: stream closed
    -> :set prompt ""
ghci | "stty"   ७  譥
ghci | , ᯮ塞 ணࠬ   䠩.
ghci | �[0mInvalidAbsDir "D:\\ssd-data\\work\\exercises\\\ESC[0mexercises:lib"�[0m

(Also when the terminal opens in vscode, a default path for it is "D:\ssd-data\work>", and there is that setting "Terminal > Integrated: Cwd", should I leave it empty?)

I've tried to open the "exercises" directory as a workspace

This is the right way to go, because we can find say stack.yaml at workspace root. It's just like when you run stack build you need to be at the directory with stack.yaml

but then I get "Error while start GHCi"

Okay, this is a new problem. It seems like stack tries to do something with the terminal by writing special character sequences (like \u001b[0m) which messes stuff up because we try to parse output from stack. It seems that on windows, stack will output these even when it's not on a terminal, and we need to work around that. I'll create a new issue for this.

and there is that setting "Terminal > Integrated: Cwd"

This is not related to this extension.

Fixed in v0.1.14. If this does not solve this or causes other problems, feel free to reopen this or create a new issue.