Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
andys8 opened this issue Feb 1, 2021 · 8 comments
Closed

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

andys8 opened this issue Feb 1, 2021 · 8 comments
Labels
component: ghcide type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@andys8
Copy link
Collaborator

andys8 commented Feb 1, 2021

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.

  • Open test/Spec.hs
  • Jump to def with testHelper works
  • Jump to def with libraryFunction doesn't work

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: 
  �[0;91muser 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")�[0m
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: 
  �[0;91muser 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")�[0m

[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
Copy link
Collaborator

fendor commented Feb 1, 2021

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
Copy link
Member

jneira commented Feb 1, 2021

Similar (or duplicate) of #799 and #486

@jneira jneira added component: ghcide type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Feb 1, 2021
@andys8
Copy link
Collaborator Author

andys8 commented Feb 1, 2021

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 6b6c405 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
Copy link
Collaborator Author

andys8 commented Feb 1, 2021

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
Copy link
Collaborator

fendor commented Feb 2, 2021

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
Copy link
Collaborator Author

andys8 commented Feb 2, 2021

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
Copy link
Collaborator Author

andys8 commented Feb 13, 2021

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

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

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

@andys8
Copy link
Collaborator Author

andys8 commented Feb 13, 2021

Closing this, because it looks very good.

@andys8 andys8 closed this as completed Feb 13, 2021
andys8 added a commit to andys8/dotfiles that referenced this issue Feb 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ghcide type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

3 participants