haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.65k stars 354 forks source link

Packages containing C files which include stubs don't work #2056

Open akshaymankar opened 3 years ago

akshaymankar commented 3 years ago

Your environment

Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

$ haskell-language-server --probe-tools
haskell-language-server version: 1.2.0.0 (GHC: 8.10.4) (PATH: /nix/store/byk240318725g8idscwi89y1cmx4yj5p-haskell-language-server-1.2.0.0/bin/haskell-language-server)
Tool versions found on the $PATH
cabal:          3.4.0.0
stack:          Not found
ghc:            8.10.4

Which OS do you use: NixOS Which lsp-client do you use: emacs

Describe your project (alternative: link to the project): https://git.coop/akshay/gi-gio-hs-list-model

Contents of hie.yaml: No hie.yaml

Steps to reproduce

  1. Create C file which includes a GHC generated _stub.h
  2. Add the file to c-sources section of the library description in the cabal file
  3. Compile with cabal, make sure it works
  4. Run haskell-language-server

Expected behaviour

Compilation using HLS also works.

Actual behaviour

HLS fails with an error like this:

Output from setting up the cradle Cradle {cradleRootDir = "/home/axeman/workspace/gi-gio-hs-list-model", cradleOptsProg = CradleAction: Cabal}
> Build profile: -w ghc-8.10.4 -O1
> In order, the following will be built (use -v for more details):
>  - gi-gio-hs-list-model-0.1.0.0 (lib) (first run)
> Preprocessing library for gi-gio-hs-list-model-0.1.0.0..
>
> In file included from cbits/GiGioHsListStore.c:1:0: error:
>
> cbits/GiGioHsListStore.h:6:10: error:
>      fatal error: Data/GI/Gio/ListModel/CustomStore_stub.h: No such file or directory
>         6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h"
>           |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>   |
> 6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h"
>   |          ^
> compilation terminated.
> `cc' failed in phase `C Compiler'. (Exit code: 1)
> cabal: repl failed for gi-gio-hs-list-model-0.1.0.0.
>

Workaround

In the repo linked above, I have also have a workaround, which is basically to also add the place where cabal puts the generated stub in the include-dirs. This is not a good solution as hackage is currently refusing to accept this cabal file as that path obviously doesn't exist in the repository, even if I have hidden it behind a flag.

Include debug information

Execute in the root of your project the command haskell-language-server --debug . and paste the logs here:

Debug output: ``` haskell-language-server version: 1.2.0.0 (GHC: 8.10.4) (PATH: /nix/store/byk240318725g8idscwi89y1cmx4yj5p-haskell-language-server-1.2.0.0/bin/haskell-language-server) ghcide setup tester in /home/axeman/workspace/gi-gio-hs-list-model. Report bugs at https://github.com/haskell/haskell-language-server/issues Step 1/4: Finding files to test in /home/axeman/workspace/gi-gio-hs-list-model Found 2 files Step 2/4: Looking for hie.yaml files that control setup Found 1 cradle () Step 3/4: Initializing the IDE 2021-08-01 00:01:08.946168697 [ThreadId 7] DEBUG hls: Initializing exports map from hiedb 2021-08-01 00:01:08.980932413 [ThreadId 7] DEBUG hls: Done initializing exports map from hiedb (25) Step 4/4: Type checking the files 2021-08-01 00:01:08.984458079 [ThreadId 58] DEBUG hls: hlint:getIdeas:file:NormalizedFilePath "/home/axeman/workspace/gi-gio-hs-list-model/src/Data/GI/Gio/ListModel/CustomStore.hs" 2021-08-01 00:01:08.98447051 [ThreadId 59] DEBUG hls: hlint:getIdeas:file:NormalizedFilePath "/home/axeman/workspace/gi-gio-hs-list-model/src/Data/GI/Gio/ListModel/SeqStore.hs" 2021-08-01 00:01:08.985136728 [ThreadId 64] INFO hls: Consulting the cradle for "src/Data/GI/Gio/ListModel/CustomStore.hs" 2021-08-01 00:01:08.985234995 [ThreadId 64] WARNING hls: No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for src/Data/GI/Gio/ListModel/CustomStore.hs. Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie). You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error. Output from setting up the cradle Cradle {cradleRootDir = "/home/axeman/workspace/gi-gio-hs-list-model", cradleOptsProg = CradleAction: Cabal} > Build profile: -w ghc-8.10.4 -O1 > In order, the following will be built (use -v for more details): > - gi-gio-hs-list-model-0.1.0.0 (lib) (first run) > Preprocessing library for gi-gio-hs-list-model-0.1.0.0.. > > In file included from cbits/GiGioHsListStore.c:1:0: error: > > cbits/GiGioHsListStore.h:6:10: error: > fatal error: Data/GI/Gio/ListModel/CustomStore_stub.h: No such file or directory > 6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h" > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > | > 6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h" > | ^ > compilation terminated. > `cc' failed in phase `C Compiler'. (Exit code: 1) > cabal: repl failed for gi-gio-hs-list-model-0.1.0.0. > 2021-08-01 00:01:09.544682105 [ThreadId 64] DEBUG hls: Session loading result: Left [CradleError {cradleErrorDependencies = ["gi-gio-hs-list-model.cabal","cabal.project","cabal.project.local"], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Failed to parse result of calling cabal","Build profile: -w ghc-8.10.4 -O1\nIn order, the following will be built (use -v for more details):\n - gi-gio-hs-list-model-0.1.0.0 (lib) (first run)\nPreprocessing library for gi-gio-hs-list-model-0.1.0.0..\n","\nIn file included from cbits/GiGioHsListStore.c:1:0: error: \n\ncbits/GiGioHsListStore.h:6:10: error:\n fatal error: Data/GI/Gio/ListModel/CustomStore_stub.h: No such file or directory\n 6 | #include \"Data/GI/Gio/ListModel/CustomStore_stub.h\"\n | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n |\n6 | #include \"Data/GI/Gio/ListModel/CustomStore_stub.h\"\n | ^\ncompilation terminated.\n`cc' failed in phase `C Compiler'. (Exit code: 1)\ncabal: repl failed for gi-gio-hs-list-model-0.1.0.0.\n\n",""]}] 2021-08-01 00:01:09.546014889 [ThreadId 77] INFO hls: Consulting the cradle for "src/Data/GI/Gio/ListModel/SeqStore.hs" 2021-08-01 00:01:09.54612461 [ThreadId 77] WARNING hls: No [cradle](https://github.com/mpickering/hie-bios#hie-bios) found for src/Data/GI/Gio/ListModel/SeqStore.hs. Proceeding with [implicit cradle](https://hackage.haskell.org/package/implicit-hie). You should ignore this message, unless you see a 'Multi Cradle: No prefixes matched' error. 2021-08-01 00:01:09.546096184 [ThreadId 94] INFO hls: File: /home/axeman/workspace/gi-gio-hs-list-model/src/Data/GI/Gio/ListModel/CustomStore.hs Hidden: no Range: 1:1-2:1 Source: cradle Severity: DsError Message: Failed to parse result of calling cabal Build profile: -w ghc-8.10.4 -O1 In order, the following will be built (use -v for more details): - gi-gio-hs-list-model-0.1.0.0 (lib) (first run) Preprocessing library for gi-gio-hs-list-model-0.1.0.0.. In file included from cbits/GiGioHsListStore.c:1:0: error: cbits/GiGioHsListStore.h:6:10: error: fatal error: Data/GI/Gio/ListModel/CustomStore_stub.h: No such file or directory 6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h" | ^ compilation terminated. `cc' failed in phase `C Compiler'. (Exit code: 1) cabal: repl failed for gi-gio-hs-list-model-0.1.0.0. Output from setting up the cradle Cradle {cradleRootDir = "/home/axeman/workspace/gi-gio-hs-list-model", cradleOptsProg = CradleAction: Cabal} > Build profile: -w ghc-8.10.4 -O1 > In order, the following will be built (use -v for more details): > - gi-gio-hs-list-model-0.1.0.0 (lib) (first run) > Preprocessing library for gi-gio-hs-list-model-0.1.0.0.. > > In file included from cbits/GiGioHsListStore.c:1:0: error: > > cbits/GiGioHsListStore.h:6:10: error: > fatal error: Data/GI/Gio/ListModel/CustomStore_stub.h: No such file or directory > 6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h" > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > | > 6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h" > | ^ > compilation terminated. > `cc' failed in phase `C Compiler'. (Exit code: 1) > cabal: repl failed for gi-gio-hs-list-model-0.1.0.0. > 2021-08-01 00:01:10.065399483 [ThreadId 77] DEBUG hls: Session loading result: Left [CradleError {cradleErrorDependencies = ["gi-gio-hs-list-model.cabal","cabal.project","cabal.project.local"], cradleErrorExitCode = ExitFailure 1, cradleErrorStderr = ["Failed to parse result of calling cabal","Build profile: -w ghc-8.10.4 -O1\nIn order, the following will be built (use -v for more details):\n - gi-gio-hs-list-model-0.1.0.0 (lib) (first run)\nPreprocessing library for gi-gio-hs-list-model-0.1.0.0..\n","\nIn file included from cbits/GiGioHsListStore.c:1:0: error: \n\ncbits/GiGioHsListStore.h:6:10: error:\n fatal error: Data/GI/Gio/ListModel/CustomStore_stub.h: No such file or directory\n 6 | #include \"Data/GI/Gio/ListModel/CustomStore_stub.h\"\n | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n |\n6 | #include \"Data/GI/Gio/ListModel/CustomStore_stub.h\"\n | ^\ncompilation terminated.\n`cc' failed in phase `C Compiler'. (Exit code: 1)\ncabal: repl failed for gi-gio-hs-list-model-0.1.0.0.\n\n",""]}] 2021-08-01 00:01:10.065846677 [ThreadId 62] INFO hls: File: /home/axeman/workspace/gi-gio-hs-list-model/src/Data/GI/Gio/ListModel/SeqStore.hs Hidden: no Range: 1:1-2:1 Source: cradle Severity: DsError Message: Failed to parse result of calling cabal Build profile: -w ghc-8.10.4 -O1 In order, the following will be built (use -v for more details): - gi-gio-hs-list-model-0.1.0.0 (lib) (first run) Preprocessing library for gi-gio-hs-list-model-0.1.0.0.. In file included from cbits/GiGioHsListStore.c:1:0: error: cbits/GiGioHsListStore.h:6:10: error: fatal error: Data/GI/Gio/ListModel/CustomStore_stub.h: No such file or directory 6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h" | ^ compilation terminated. `cc' failed in phase `C Compiler'. (Exit code: 1) cabal: repl failed for gi-gio-hs-list-model-0.1.0.0. 2021-08-01 00:01:10.066495784 [ThreadId 114] INFO hls: finish: User TypeCheck (took 1.08s) 2021-08-01 00:01:10.066734292 [ThreadId 117] INFO hls: finish: GetHie (took 0.00s) Files that failed: * /home/axeman/workspace/gi-gio-hs-list-model/src/Data/GI/Gio/ListModel/CustomStore.hs * /home/axeman/workspace/gi-gio-hs-list-model/src/Data/GI/Gio/ListModel/SeqStore.hs Completed (0 files worked, 2 files failed) 2021-08-01 00:01:10.066901702 [ThreadId 119] INFO hls: finish: GenerateCore (took 0.00s) ```

Paste the logs from the lsp-client, e.g. for VS Code

LSP logs: ``` No 'hie.yaml' found. Try to discover the project type! Run entered for haskell-language-server-wrapper(haskell-language-server-wrapper) Version 1.2.0.0 x86_64 ghc-8.10.4 Current directory: /home/axeman/workspace/gi-gio-hs-list-model Operating system: linux Arguments: ["--lsp","-d","-l","/tmp/hls.log"] Cradle directory: /home/axeman/workspace/gi-gio-hs-list-model Cradle type: Cabal Tool versions found on the $PATH cabal: 3.4.0.0 stack: Not found ghc: 8.10.4 Consulting the cradle to get project GHC version... Project GHC version: 8.10.4 haskell-language-server exe candidates: ["haskell-language-server-8.10.4","haskell-language-server"] Launching haskell-language-server exe at:/nix/store/ksbshrf4jaq5qdlyjs27xsn4sl5677w8-gi-gio-hs-list-model/bin/haskell-language-server-8.10.4 haskell-language-server version: 1.2.0.0 (GHC: 8.10.4) (PATH: /nix/store/byk240318725g8idscwi89y1cmx4yj5p-haskell-language-server-1.2.0.0/bin/haskell-language-server) Starting (haskell-language-server)LSP server... with arguments: GhcideArguments {argsCommand = LSP, argsCwd = Nothing, argsShakeProfiling = Nothing, argsTesting = False, argsExamplePlugin = False, argsDebugOn = True, argsLogFile = Just "/tmp/hls.log", argsThreads = 0, argsProjectGhcVersion = False} with plugins: [PluginId "pragmas",PluginId "floskell",PluginId "fourmolu",PluginId "tactics",PluginId "ormolu",PluginId "stylish-haskell",PluginId "retrie",PluginId "brittany",PluginId "class",PluginId "haddockComments",PluginId "eval",PluginId "importLens",PluginId "refineImports",PluginId "moduleName",PluginId "hlint",PluginId "splice",PluginId "ghcide-hover-and-symbols",PluginId "ghcide-code-actions-imports-exports",PluginId "ghcide-code-actions-type-signatures",PluginId "ghcide-code-actions-bindings",PluginId "ghcide-code-actions-fill-holes",PluginId "ghcide-completions",PluginId "ghcide-type-lenses",PluginId "ghcide-core"] in directory: /home/axeman/workspace/gi-gio-hs-list-model Starting LSP server... If you are seeing this in a terminal, you probably should have run WITHOUT the --lsp option! Started LSP server in 0.00s setInitialDynFlags cradle: Cradle {cradleRootDir = "/home/axeman/workspace/gi-gio-hs-list-model", cradleOptsProg = CradleAction: Cabal} Output from setting up the cradle Cradle {cradleRootDir = "/home/axeman/workspace/gi-gio-hs-list-model", cradleOptsProg = CradleAction: Cabal} > Build profile: -w ghc-8.10.4 -O1 > In order, the following will be built (use -v for more details): > - gi-gio-hs-list-model-0.1.0.0 (lib) (first run) > Preprocessing library for gi-gio-hs-list-model-0.1.0.0.. > > In file included from cbits/GiGioHsListStore.c:1:0: error: > > cbits/GiGioHsListStore.h:6:10: error: > fatal error: Data/GI/Gio/ListModel/CustomStore_stub.h: No such file or directory > 6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h" > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > | > 6 | #include "Data/GI/Gio/ListModel/CustomStore_stub.h" > | ^ > compilation terminated. > `cc' failed in phase `C Compiler'. (Exit code: 1) > cabal: repl failed for gi-gio-hs-list-model-0.1.0.0. > ```
fendor commented 3 years ago

Hi, thank you for the bug report!

This looks like a cabal bug, as cabal repl fails for me for your project.

Unfortunately, not much we can do at the moment for that :(

However, we are currently working to improve the project loading for cabal projects (some details here: https://github.com/haskell/cabal/issues/7489 although not applicable or helpful to you at the moment) and on my WIP branch, I can successfully load the project without the hack you added.