haskell / haskell-ide-engine

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

HIE seems to be able to typechek only one module #680

Open maksbotan opened 6 years ago

maksbotan commented 6 years ago

I use HIE with LanguageClient_neovim. Versions:

$ ~/.local/bin/hie --version
Version 0.2.0.0, Git revision e159e35a5471bcfa8576d663cb82180dc9fe53ab (dirty) (1555 commits) x86_64 ghc-8.2.2
$ stack --version
Version 1.7.1, Git revision 681c800873816c022739ca7ed14755e85a579565 (5807 commits) x86_64 hpack-0.28.2

I build HIE with $ stack --resolver=lts-11.2 --stack-yaml=stack-8.2.2.yaml install, since we have LTS-11.2 in the project I develop.

The project consists of a library and an executable in separate Cabal files. The executable is built with -dynamic, so I also have to add -fexternal-interpreter to its Cabal file.

However, it seems that HIE can typecheck only the first file I open in nvim. All subsequent files result in didn't get typechecked module. Here's a part of log with --debug --vomit:

2018-07-12 23:45:52.549029635 [ThreadId 4] - ---> {"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"languageId":"haskell","text":" ...
2018-07-12 23:45:52.550559802 [ThreadId 10] - ****** reactor: got message number:3
2018-07-12 23:45:52.55069708 [ThreadId 10] - ****** reactor: processing NotDidOpenTextDocument
2018-07-12 23:45:52.5508884 [ThreadId 9] - ghcDispatcher:got request 3 with id: Nothing
2018-07-12 23:45:52.749975698 [ThreadId 9] - file mapping state is: fromList [("/../MainWindow.hs",FileMapping {fmPath = "/tmp/ghc-mod24974/MainWindow24973-0.hs", fmTemp = True}),("/.../WalletTree.hs",FileMapping {fmPath = "/tmp/ghc-mod24975/WalletTree24973-1.hs", fmTemp = True})]
2018-07-12 23:45:52.750217547 [ThreadId 9] - ghcDispatcher: top of loop
2018-07-12 23:45:52.750346578 [ThreadId 9] - ghcDispatcher:got request 3 with id: Nothing
2018-07-12 23:45:52.750479733 [ThreadId 9] - ghcDispatcher:Processing request as version matches
2018-07-12 23:45:52.806597695 [ThreadId 9] - ghcDispatcher: top of loop
2018-07-12 23:45:52.806739459 [ThreadId 9] - ghcDispatcher:got request 3 with id: Nothing
2018-07-12 23:45:52.806801621 [ThreadId 9] - ghcDispatcher:Processing request as version matches
2018-07-12 23:45:52.827888132 [ThreadId 9] - setTypecheckedModule: file mapping state is: fromList [("/home/maks/Projects/SRK/ariadne/ui/qt/src/Ariadne/UI/Qt/MainWindow.hs",FileMapping {fmPath = "/tmp/ghc-mod24974/MainWindow24973-0.hs", fmTemp = True}),("/home/maks/Projects/SRK/ariadne/ui/qt/src/Ariadne/UI/Qt/Widgets/WalletTree.hs",FileMapping {fmPath = "/tmp/ghc-mod24975/WalletTree24973-1.hs", fmTemp = True})]
2018-07-12 23:45:52.828050778 [ThreadId 9] - setTypecheckedModule: before ghc-mod
2018-07-12 23:45:52.85245996 [ThreadId 6] - <--2--{"jsonrpc":"2.0","params":{"uri":"...","diagnostics":[...
2018-07-12 23:45:54.599552113 [ThreadId 9] - setTypecheckedModule: after ghc-mod
2018-07-12 23:45:54.600437366 [ThreadId 9] - setTypecheckedModule: Didn't get typechecked module for: "/home/maks/Projects/SRK/ariadne/ui/qt/src/Ariadne/UI/Qt/Widgets/WalletTree.hs"
2018-07-12 23:45:54.600668187 [ThreadId 9] - ghcDispatcher: top of loop
2018-07-12 23:45:54.600838194 [ThreadId 6] - <--2--{"jsonrpc":"2.0","params":{"type":1,"message":"Got error while processing diagnostics: {handle: <file descriptor: 14>}: GHCi.Message.remoteCall: end of file"},"method":"window/showMessage"}

Also, ps indicates that ghc-iserv-dyn process dies after this. How can I debug this further?

maksbotan commented 6 years ago

I started to get this error as well:

[Error] Got error while processing diagnostics: readCreateProcess: /home/maks/work/haskell-ide-engine/.stack-work/install/x86_64-linux-ncurses6/lts-11.13/8.2.2/libexec/x86_64-linux-ghc-8.2.2/

How can I debug this?

Bump :)

lukel97 commented 6 years ago

Does nuking .stack-work resolve anything?

maksbotan commented 6 years ago

I've recently moved to a new laptop, so I had clean .stack-work, but it did not help. In fact, now I'm seeing the new error described in my second comment. This can be due to some changes in HIE or due to the fact that we switched from ghc 8.2 to ghc 8.4. So I'm sure cleaning .stack-work won't help now and it's a rather long rebuild.

lorenzo commented 6 years ago

You said you switched to 8.4 but the error message implies that it is using 8.2, could that be a reason?

maksbotan commented 6 years ago

Sorry, that was actually 8.0 to 8.2, not 8.2 to 8.4 :) Specifically, we use LTS-11.13. I've build HIE with stack --resolver=lts-11.13 --stack-yaml=stack-8.2.2.yaml.

lorenzo commented 6 years ago

Does that happen with any project you use or just with this one specifically? Is there any way we can reproduce this problem?

maksbotan commented 6 years ago

Hm... I crafted a simple project with two modules and -dynamic, hie seems to work fine. I tried adding dependency to qtah (dynamic-only bindings to Qt), but still could not reproduce the error. Can you suggest something I can try on the actual project?

maksbotan commented 6 years ago

Tried it once again in our project, here's complete HIE log with --vomit: https://gist.github.com/maksbotan/412ea588248d05b52a5f399227c59e92 We have three packages, let's call them A, B and C. B and C depend on A, B is ordinary and C is built with -dynamic. HIE works fine on modules from A and B, but fails on C. I have added -fexternal-interpreter to -dynamic packages as earlier errors recommended.

maksbotan commented 6 years ago

Hmm... After some experimenting I found that HIE should call ghc-mod with -Wwarn, since it will fail entirely when I have -Werror in my cabal file, but I'd like to see the exact warning in my editor.

I reverder https://github.com/haskell/haskell-ide-engine/pull/374/files changing Wall to Wwarn and it seems to work now.

Also I had to run that long cabal-helper command with stack exec --, seems like HIE runs it with some wrong path. How should it be handled properly?

maksbotan commented 6 years ago

Thanks for -Werror fix! However, I'm still getting this in log:

[Error] Got error while processing diagnostics: {handle: <file descriptor: 14>}: GHCi.Message.remoteCall: end of file                                                                          
[Error] Got error while processing diagnostics: ghc-iserv terminated (-11)                                                                                                                     
[Error] Got error while processing diagnostics: ghc-iserv terminated (-11)                                                                                                                     
[Error] Got error while processing diagnostics: ghc-iserv terminated (-11) 

Overall, hie seems to work rather unstably.

maksbotan commented 6 years ago

I also sometimes get this:

[Error] Got error while processing diagnostics: ghc-iserv terminated (-11)                                                                                                                     
[Error] Got error while processing diagnostics: ghc-iserv terminated (-11)                                                                                                                     
[Error] Got error while processing diagnostics: <no location info>: error:^@    module ‘ariadne-qt-lib-0.2.0.0-JINOphg75A62yePpU5wDS:Ariadne.UI.Qt.Widgets.Dialogs.Send’ is defined in multiple
 files: /tmp/ghc-mod15201/Send15200-2.hs^@                                                                                                                           /tmp/ghc-mod15202/WalletIn
fo15200-8.hs      

Bump! :)

lorenzo commented 6 years ago

It seems like this issue has to do with the -dynamic flag, right? Have you experienced the same problem when working in other condebases at all?

maksbotan commented 6 years ago

Yes. I enabled -fexternal-interpreter as suggested by error from ghc-mod and then this happens. Tried right now with killing .stack-work in the relevant package.

I open one file -- everything is OK. I open another -- ghc-iserv-dyn dies. Is there a way to make it output some logs to see what's going on?

lorenzo commented 6 years ago

@DanielG Do you know anything about this?

Vigilans commented 5 years ago

When I rename a .hs file, for example: First.hs --> Program.hs

vscode keep receiving complaints from the lower right corner:

Got error while processing diagnostics: <no location info>: error:
    module ‘main:CT’ is defined in multiple files: /tmp/ghc-mod15792/First15791-364.hs
                                                   /tmp/ghc-mod15792/Program15791-459.hs
jneira commented 4 years ago

@maksbotan there had been big changes in hie internal architecture, and it doesn't suppot ghc-8.2.2, could you try again to check if the error still stands?