haskell / haskell-language-server

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

Jump to definition for src not working if defined as library #1286

Closed andys8 closed 3 years ago

andys8 commented 3 years ago

Your environment

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

haskell-language-server version: 0.9.0.0 (GHC: 8.8.3) (PATH: /home/andreas/.local/bin/haskell-language-server-wrapper) (GIT hash: 6b6c405d14a29ab3d2e7dbb4e2f79229758d26ba)
Tool versions found on the $PATH
cabal:          3.2.0.0
stack:          2.5.1
ghc:            8.8.3

Which lsp-client do you use: coc.nvim version: 0.0.80-6e5a2aaeb5 Describe your project (alternative: link to the project): https://github.com/andys8/demo-haskell-language-server-jump-to-def-issue Contents of hie.yaml:

cradle:
  stack:
    - path: "./app"
      component: "demo-hls-jump-to-definition:exe:demo-hls-jump-to-definition-exe"
    - path: "./test"
      component: "demo-hls-jump-to-definition:test:demo-hls-jump-to-definition-test"
    - path: "./src"
      component: "demo-hls-jump-to-definition:lib"

Steps to reproduce

I created a demo project: https://github.com/andys8/demo-haskell-language-server-jump-to-def-issue The project setup is done with stack new and only slightly modified.

The workaround is to add src dir to source-dirs, but this has the downside of duplication and higher compile times.

Expected behaviour

Jump to definition is working for libraryFunction / dependencies.

Actual behaviour

Jump to definition works only for source-dirs.

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)Ghcide setup tester in /home/andreas/dev/repository/demo-haskell-language-server-jump-to-defintionion-issue. Report bugs at https://github.com/haskell/haskell-language-server/issues Tool versions found on the $PATH cabal: 3.2.0.0 stack: 2.5.1 ghc: 8.8.3 Step 1/4: Finding files to test in /home/andreas/dev/repository/demo-haskell-language-server-jump-to-defintionion-issue Found 4 files Step 2/4: Looking for hie.yaml files that control setup Found 1 cradle Step 3/4: Initializing the IDE Step 4/4: Type checking the files [INFO] Consulting the cradle for "src/Lib.hs" [INFO] Using interface files cache dir: ghcide [INFO] Making new HscEnv[main] [INFO] Consulting the cradle for "test/SpecHelper.hs" [INFO] Using interface files cache dir: ghcide [INFO] Using interface files cache dir: ghcide [INFO] Making new HscEnv[main,main] [INFO] Consulting the cradle for "app/Main.hs" [INFO] Using interface files cache dir: ghcide [INFO] Using interface files cache dir: ghcide [INFO] Using interface files cache dir: ghcide [INFO] Making new HscEnv[main,main,main] File: /home/andreas/dev/repository/demo-haskell-language-server-jump-to-defintionion-issue/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/demo-hls-jump-to-definition-test/autogen/Paths_demo_hls_jump_to_definition.hs Hidden: no Range: 1:1-2:1 Source: compiler Severity: DsError Message: user error (Failed to get the immediate reverse dependencies of NormalizedFilePath "/home/andreas/dev/repository/demo-haskell-language-server-jump-to-defintionion-issue/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/demo-hls-jump-to-definition-test/autogen/Paths_demo_hls_jump_to_definition.hs") File: /home/andreas/dev/repository/demo-haskell-language-server-jump-to-defintionion-issue/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/demo-hls-jump-to-definition-exe/autogen/Paths_demo_hls_jump_to_definition.hs Hidden: no Range: 1:1-2:1 Source: compiler Severity: DsError Message: user error (Failed to get the immediate reverse dependencies of NormalizedFilePath "/home/andreas/dev/repository/demo-haskell-language-server-jump-to-defintionion-issue/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/demo-hls-jump-to-definition-exe/autogen/Paths_demo_hls_jump_to_definition.hs") [INFO] finish: User TypeCheck (took 0.04s) Completed (4 files worked, 0 files failed) ```

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

LSP logs: ``` ## versions vim version: VIM - Vi IMproved 8.2 8022347 node version: v14.9.0 coc.nvim version: 0.0.80-6e5a2aaeb5 coc.nvim directory: /home/andreas/.vim/plugged/coc.nvim term: dumb platform: linux ## Log of coc.nvim 2021-02-01T19:57:24.934 INFO (pid:3024769) [services] - registered service "languageserver.elmLS" 2021-02-01T19:57:24.936 INFO (pid:3024769) [services] - registered service "languageserver.haskell-language-server" 2021-02-01T19:57:24.936 INFO (pid:3024769) [services] - registered service "languageserver.bash" 2021-02-01T19:57:24.936 INFO (pid:3024769) [services] - registered service "languageserver.dockerfile" 2021-02-01T19:57:24.936 INFO (pid:3024769) [services] - registered service "languageserver.purescript" 2021-02-01T19:57:24.977 INFO (pid:3024769) [services] - registered service "diagnostic-languageserver" 2021-02-01T19:57:25.137 INFO (pid:3024769) [plugin] - coc.nvim 0.0.80-6e5a2aaeb5 initialized with node: v14.9.0 after 267ms 2021-02-01T19:57:25.143 INFO (pid:3024769) [language-client-index] - cSpell started with 3024780 2021-02-01T19:57:26.447 INFO (pid:3024769) [attach] - receive notification: doAutocmd [ 1 ] 2021-02-01T19:57:26.492 INFO (pid:3024769) [attach] - receive notification: doAutocmd [ 1 ] 2021-02-01T19:57:26.553 INFO (pid:3024769) [services] - haskell-language-server state change: stopped => starting 2021-02-01T19:57:26.554 INFO (pid:3024769) [services] - diagnostic language service state change: stopped => starting 2021-02-01T19:57:26.562 INFO (pid:3024769) [language-client-index] - Language server "languageserver.haskell-language-server" started with 3024838 2021-02-01T19:57:26.568 INFO (pid:3024769) [language-client-index] - diagnostic-languageserver started with 3024843 2021-02-01T19:57:26.685 INFO (pid:3024769) [services] - diagnostic language service state change: starting => running 2021-02-01T19:57:26.685 INFO (pid:3024769) [services] - service diagnostic-languageserver started 2021-02-01T19:57:27.427 INFO (pid:3024769) [services] - haskell-language-server state change: starting => running 2021-02-01T19:57:27.430 INFO (pid:3024769) [services] - service languageserver.haskell-language-server started 2021-02-01T19:57:27.863 INFO (pid:3024769) [attach] - receive notification: jumpDefinition [] 2021-02-01T19:57:27.894 INFO (pid:3024769) [attach] - receive notification: doAutocmd [ 1 ] 2021-02-01T19:57:28.565 INFO (pid:3024769) [attach] - receive notification: doAutocmd [ 1 ] 2021-02-01T19:57:29.180 INFO (pid:3024769) [attach] - receive notification: jumpDefinition [] 2021-02-01T19:57:34.132 INFO (pid:3024769) [attach] - receive notification: showInfo [] ```
fendor commented 3 years ago

Well hidden, we have that documented: https://github.com/haskell/haskell-language-server/tree/master/ghcide#limitations-to-multi-component-support

Essentially, if you want goto definition to work, you need to open a file from each component, e.g. open something from src/ in your editor as well, and it should start working!

jneira commented 3 years ago

Similar (or duplicate) of #799 and #486

andys8 commented 3 years ago

It doesn't work for me, even if there is a file from src open. See screenshot. image

As I mentioned I'm currently also testing with the 6b6c405d14a29ab3d2e7dbb4e2f79229758d26ba which contains hiedb. I can also test with different versions.

Is it working for you @fendor / @jneira with the example I posted and the same or a different hls version or different editor / environment?

andys8 commented 3 years ago

I tested with a nearly vanilla setup of vscode with the hls extension. The behavior is the same, even though the target file is open.

image

I'm noticing this error. Any chance it has something to do with the issue or is it independent? (see Update)

image

 {
    "resource": "/home/andreas/dev/repository/demo-haskell-language-server-jump-to-defintionion-issue/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/autogen/Paths_demo_hls_jump_to_definition.hs",
    "owner": "Haskell (demo-haskell-language-server-jump-to-defintionion-issue)",
    "severity": 8,
    "message": "user error (Failed to get the immediate reverse dependencies of NormalizedFilePath \"/home/andreas/dev/repository/demo-haskell-language-server-jump-to-defintionion-issue/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/autogen/Paths_demo_hls_jump_to_definition.hs\")",
    "source": "compiler",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 2,
    "endColumn": 1
}

Update

I doubt the Paths_ error is the cause. With this workaround it can be removed/resolved, but the issue (not being able to jump to definition) is still the case.

fendor commented 3 years ago

With cabal everything is fine (sorry for that pretty much useless info), e.g. goto definition works, etc...

With stack I can reproduce the issue.

andys8 commented 3 years ago

I'm glad the issue can be reproduced. Thanks @fendor for confirmation.

Now looking towards solving the issue: is the cause of the behavior known (looking at related issues @jneira linked)? Which component in the tool chain is the one to look at (hls, ghcide, hie-bios, stack)?

andys8 commented 3 years ago

Wohoo. I think recent changes fixed the behavior. It is working with current master (e2bf01bf4a3df67a2ada5544e4532c2f7f2f32a4).

It might be fixed by #1357 (fbb96e83e91e970e9c567fe51cbee306d3d66e4e) or #1358 (d87a5dbacdf8e11998f3f648d6beb57ae47736df) or another change. Thanks @wz1000

Will re-test this issue once a new version is released, too.

andys8 commented 3 years ago

Closing this, because it looks very good.