haskell / haskell-ide-engine

The engine for haskell ide-integration. Not an IDE
BSD 3-Clause "New" or "Revised" License
2.38k stars 213 forks source link

coc, hie, ghci stack ... ghci cannot find the modules defined by the project #1711

Closed EdmundsEcho closed 4 years ago

EdmundsEcho commented 4 years ago

Hello -

I moved from a prior config using ALE and others to the new hie. I'm excited about what you all have accomplished. I'm getting the following error:

Could not find module ‘DB.API’ Use -v (or `:set -v` in ghci) to see a list of the files searched for. |22 | import qualified DB.API as Lib
etc... for all of the modules defined in my project

Despite my best judgment, I have hie installed globally. However, I have package.yaml and hie.yaml in my project root folder.

cradle:
  stack:
    component: "haskell-ide-engine:lib"

dependencies:
  - package.yaml

Also, when I run hie from my root folder, it echoes/prints the project file names.

A. Am I "barking up the right tree" reaching out to the hie team? B. If A, then what am I missing to get ghci to see my project modules?

Thank you in advance!

- E

fendor commented 4 years ago

Yes, you have barked up the right tree :) The hie.yaml looks like it has been copied from some other example. It should reflect a map from filepaths to components. Components in haskell are things like library, executable, test or benchmark. For example, a simplified hie.yaml for HIE codebase:

cradle:
  stack:
    - path: "./hie-plugin-api/"
      component: "hie-plugin-api:lib"

    - path: "./app/MainHie.hs"
      component: "haskell-ide-engine:exe:hie"

    - path: "./app/HieWrapper.hs"
      component: "haskell-ide-engine:exe:hie-wrapper"

    - path: "./"
      component: "haskell-ide-engine:lib"

Here we say, any FilePath that starts with hie-plugin-api should be loaded by hie-plugin-api:lib. It resembles the invocation stack repl hie-plugin-api:lib which we use to obtain the compilation flags for the component hie-plugin-api:lib. When we have those we can compile the component and provide diagnostics.

We can also provide a File, not only directories, as seen with ./app/MainHie.hs. This is the path to the executable haskell-ide-engine:exe:hie which needs to be loaded by HIE to actually typecheck the modules.

You need to provide something equivalent for your codebase. The components in your project can be obtained with stack ide targets.

EdmundsEcho commented 4 years ago

Thank you for your help. The information was useful. I used the stack repl xxx command to test each entry into the configuration. It seems to work. However, in nvim I'm getting errors for all of my imports... It seems like I have to package.yaml -> hie.yaml..?

I installed hie using the default script; this uses the latest supported ghc version. That seems to be 8.8.2 based on what I can see in the list of hie-xxx links in my ~/.local/bin directory.

However, I get these warning messages when installing hie:

# stack (for hie-8.8.2)
Stack has not been tested with GHC versions above 8.6, and using 8.8.2, this may fail
Stack has not been tested with Cabal versions above 2.4, but version 3.0.1.0 was found, this may fail

Is this something I need to consider when troubleshooting? (my app lts is set to a value that uses the same, 8.8.2 version of ghc. I could imagine that it's mostly not something to worry about given my use of the default script and what it promises: "using the latest supported ghc".

Despite this logic, the "more I can do" is to install hie with 8.6.5 and ditto for my app... I'm not getting the warning but still have the same problem.

Here is my updated hie.yam where each entry is the output of stack ide targests:

cradle:
  stack:
    - path: "./app/Main.hs"
      component: "mms:exe:mms-exe"

    - path: "./src"
      component: "mms:lib"

    - path: "./tests/Spec.hs"
      component: "mms:test:mms-test"

Screen Shot 2020-03-26 at 1 16 42 PM

Here is the output of the hie-wrapper when run form the project root directory:

[I] etl/mms comp-reduce  > stack ide targets                                                                                                                                                         2.471633m28.298s[c063db4] 13.2.0 2.4.3
mms:lib
mms:exe:mms-exe
mms:test:mms-test
[I] etl/mms comp-reduce  > hie-wrapper                                                                                                                                                                         0.268s[c063db4] 13.2.0 2.4.3
2020-03-26 13:18:53.617993 [ThreadId 4] - run entered for hie-wrapper(hie-wrapper) Version 1.2, Git revision 35f62cffb6bae6c3f86113cb0c55f52b7192689d (3841 commits) x86_64 ghc-8.6.5
2020-03-26 13:18:53.618894 [ThreadId 4] - Current directory:/Volumes/EC_Active/Programming/etl/mms
2020-03-26 13:18:53.618958 [ThreadId 4] - Operating system:darwin
2020-03-26 13:18:53.619071 [ThreadId 4] - args:[]
2020-03-26 13:18:53.619921 [ThreadId 4] - Module "/Volumes/EC_Active/Programming/etl/mms/File.hs" is loaded by Cradle: Cradle {cradleRootDir = "/Volumes/EC_Active/Programming/etl/mms", cradleOptsProg = CradleAction: Stack}
2020-03-26 13:18:53.620041 [ThreadId 4] - Cradle directory:/Volumes/EC_Active/Programming/etl/mms
2020-03-26 13:18:53.620563 [ThreadId 4] - Executing Stack GHC with args: --numeric-version
2020-03-26 13:18:54.018125 [ThreadId 4] - Project GHC version:8.6.5
2020-03-26 13:18:54.018212 [ThreadId 4] - hie exe candidates :["hie-8.6.5","hie-8.6","hie"]
2020-03-26 13:18:54.018874 [ThreadId 4] - found hie exe at:/Users/edmund/.local/bin/hie-8.6.5
2020-03-26 13:18:54.018918 [ThreadId 4] - args:[]
2020-03-26 13:18:54.018956 [ThreadId 4] - launching ....

Running HIE(hie-8.6.5)
  Version 1.2, Git revision 35f62cffb6bae6c3f86113cb0c55f52b7192689d (3841 commits) x86_64 ghc-8.6.5
To run as a LSP server on stdio, provide the '--lsp' argument
Current directory:/Volumes/EC_Active/Programming/etl/mms

args:[]

Looking for project config cradle...

2020-03-26 13:18:54.040123 [ThreadId 4] - Module "/Volumes/EC_Active/Programming/etl/mms/File.hs" is loaded by Cradle: Cradle {cradleRootDir = "/Volumes/EC_Active/Programming/etl/mms", cradleOptsProg = CradleAction: Stack}
2020-03-26 13:18:54.041231 [ThreadId 4] - Executing Stack GHC with args: --numeric-version
2020-03-26 13:18:54.442268 [ThreadId 4] - Executing Stack GHC with args: --print-libdir

###################################################

Cradle: Stack project
Project Ghc version: 8.6.5
Libdir: Just "/Users/edmund/.stack/programs/x86_64-osx/ghc-8.6.5/lib/ghc-8.6.5"
Searching for Haskell source files...
Found 98 Haskell source files.

###################################################

Found the following files:

/Volumes/EC_Active/Programming/etl/mms/app/Main.hs
/Volumes/EC_Active/Programming/etl/mms/Setup.hs
/Volumes/EC_Active/Programming/etl/mms/src/DB/API.hs
etc...
...
###################################################
###################################################

Dumping diagnostics:

/Volumes/EC_Active/Programming/etl/mms/app/Main.hs: FAILED
        "cannot satisfy -package mms-0.1.1.0\n    (use -v for more information)"
/Volumes/EC_Active/Programming/etl/mms/Setup.hs: FAILED
        Fail on initialisation for "/Volumes/EC_Active/Programming/etl/mms/Setup.hs". Multi Cradle: No prefixes matched
/Volumes/EC_Active/Programming/etl/mms/src/DB/API.hs: OK
/Volumes/EC_Active/Programming/etl/mms/src/DB/ObsInstance.hs: OK
/Volumes/EC_Active/Programming/etl/mms/src/DB/ReqInstance.hs: OK
/Volumes/EC_Active/Programming/etl/mms/src/ExternalQueries/ComponentMix.hs: OK
/Volumes/EC_Active/Programming/etl/mms/src/Lib/CliParser.hs: OK
/Volumes/EC_Active/Programming/etl/mms/src/Lib/Decode.hs: OK
/Volumes/EC_Active/Programming/etl/mms/src/Lib/GraphQL/Wai.hs: OK
/Volumes/EC_Active/Programming/etl/mms/src/Lib/NodeExample.hs: OK
/Volumes/EC_Active/Programming/etl/mms/src/Lib/NodeManager.hs: OK
etc...

Final note: I subsequently hid the Setup.hs file but still get the same error.

fendor commented 4 years ago
Running HIE(hie-8.6.5)
 Version 1.2, Git revision 35f62cffb6bae6c3f86113cb0c55f52b7192689d (3841 commits) x86_64 ghc-8.6.5

this hints that hie version 8.6.5 is used for some reason. Is your resolver updated to use the same ghc version?

Could you paste the full output of hie-wrapper --debug? the rest seems pretty reasonable and seems like the executable can not be loaded? BTW, the error about "Setup.hs" is fine.

EdmundsEcho commented 4 years ago

Unbelievable -- hie seems to be behaving as expected. The funny thing was, when I sent the commands from the root project, it seemed to know where the files were. But, I was getting errors in nvim.

The issue: I still had ale loading up and had only partially disabled it Solution: remove or otherwise completely disable ale

Also, there were several prior fixes to help the prior haskell stack of tools find the root directory among others e.g., haskell_stack_bin. I commented them out "to be safe".

For the next person, what was helpful were the following; once I could confirm the configuration, I was finally able to expand my imagination for what else could be going on.

Thank you for your help.

- E

EdmundsEcho commented 4 years ago

... FYI: In my statement regarding stack ghci --ghci-options --version I thought that the ghc version would always align with what we would expect given the lts setting in stack.yaml. However, I'm getting ghc version 8.8.3 with lts-15.3. I would have expected 8.8.2 (see https://www.stackage.org/lts-15.3)

It's turning out to be an issue as I try to coordinate my hie build version with the app I'm working on with hie.