Hover not working in coc.nvim
Closed this issue · 12 comments
I installed and set up nimlangserver
for coc.nvim like explained in the readme. The Completions and everything works fine but for some reason the Hover is not working. Below is a log I got by doing :CocOpenLog
in neovim after trying to Hover (by pressing K
in normal mode) in a .nim
file:
2023-09-08T17:57:08.075 INFO (pid:4571) [plugin] - coc.nvim initialized with node: v20.5.1 after �[33m675�[39m
2023-09-08T17:57:08.093 INFO (pid:4571) [services] - LanguageClient nim state change: stopped => starting
2023-09-08T17:57:08.133 INFO (pid:4571) [language-client-index] - Language server "languageserver.nim" started with 4595
2023-09-08T17:57:08.179 INFO (pid:4571) [services] - LanguageClient nim state change: starting => running
2023-09-08T17:57:08.204 INFO (pid:4571) [services] - service languageserver.nim started
2023-09-08T17:57:16.011 INFO (pid:4571) [attach] - Request action: hasProvider [ �[32m'hover'�[39m ]
2023-09-08T17:57:16.028 INFO (pid:4571) [attach] - receive notification: doHover []
2023-09-08T17:57:18.931 INFO (pid:4571) [attach] - receive notification: openLog []
Hover in coc.nvim works fine for other languages like Bash or C, so this is less likely to be an issue with coc.nvim itself. When I try to Hover on nim files it says [coc.nvim] hover not found
at the bottom, but if I go on insert mode and try to use the Completion popup on the same word then there is a lot of useful information there - I wish I could access it directly via the Hover on normal mode.
Below is a log I got by doing
:CocOpenLog
We need the client-server log, this is the log for the client actions only.
I got this log by following the instructions explained here:
DBG Sending result(s) length=1 command="known \"/home/rokosun/programming/Nim/practise/tables.nim\":0:0"
DBG CPU Time benchmark="known \"/home/rokosun/programming/Nim/practise/tables.nim\":0:0" time=0.249 command="known \"/home/rokosun/programming/Nim/practise/tables.nim\":0:0"
[Trace - 16:32:24.579] Sending request 'textDocument/hover - (1)'.
Params: {
"textDocument": {
"uri": "file:///home/rokosun/programming/Nim/practise/tables.nim"
},
"position": {
"line": 10,
"character": 0
}
}
DBG Router: dispatching method=textDocument/hover id=1
DBG processQueue size=1
DBG Started... benchmark="def \"/home/rokosun/programming/Nim/practise/tables.nim\":11:0" command="def \"/home/rokosun/programming/Nim/practise/tables.nim\":11:0"
DBG timeoutCallback is set timeout=120000 command="def \"/home/rokosun/programming/Nim/practise/tables.nim\":11:0"
DBG Sending result(s) length=1 command="def \"/home/rokosun/programming/Nim/practise/tables.nim\":11:0"
DBG CPU Time benchmark="def \"/home/rokosun/programming/Nim/practise/tables.nim\":11:0" time=0.110 command="def \"/home/rokosun/programming/Nim/practise/tables.nim\":11:0"
DBG Router: sending response method=textDocument/hover id=1
[Trace - 16:32:24.692] Received response 'textDocument/hover - (1)' in 112ms.
Result: {
"contents": [
{
"language": "nim",
"value": "system.echo: proc (x: varargs[typed]){.gcsafe.}"
},
{
"language": "markdown",
"value": "Writes and flushes the parameters to the standard output.\n\nSpecial built-in that takes a variable number of arguments. Each argument\nis converted to a string via `$`, so it works for user-defined\ntypes that have an overloaded `$` operator.\nIt is roughly equivalent to `writeLine(stdout, x); flushFile(stdout)`, but\navailable for the JavaScript target too.\n\nUnlike other IO operations this is guaranteed to be thread-safe as\n`echo` is very often used for debugging convenience. If you want to use\n`echo` inside a `proc without side effects\n<manual.html#pragmas-nosideeffect-pragma>`_ you can use `debugEcho\n<#debugEcho,varargs[typed,]>`_ instead."
}
],
"range": null
}
The full log was actually more than 700 lines long so I'm only sharing the last bit here which I think is the relevant one for Hover. When I tried to do this neovim still just showed me [coc.nvim] hover not found
at the bottom, I'm wondering if there are any compatibility issues that needs to be sorted out, I'm happy to open an issue on coc.nvim repo if needed.
AFAICS the server is returning the proper result. Can you check with coc.nvim guys about what is causing trouble on their side?
I've created an issue here - neoclide/coc.nvim#4755
Let's see what they say.....
"range": null
is the issue, nimlangserver returns null
as range, but this should be undefined
.
https://github.com/microsoft/vscode-languageserver-node/blob/main/types/src/main.ts#L2443-L2457
Okay that explains it, thank you. And does the link you shared mean that this bug affects VSCode users too?!
this bug affects VSCode users too
Maybe not, checked VSCode source code, it didn't use Hover.is()
to valid response. Will check coc.nvim side whether this is must.
coc.nvim has improved this.
@fannheyward Thank you for the quick response 🙏 I can test the changes on coc.nvim when it'll be pushed to the release branch, hopefully that solves the issue. BTW, would you still recommend changing the response from null
to undefined
or was this a specific issue with coc.nvim ?
changing the response from null to undefined
coc.nvim can handle both now. From the LSP Spec and https://github.com/microsoft/vscode-languageserver-node/blob/c880c618b131484a756b2ffe074d7af4d14a2782/types/src/main.ts#L2443-L2457, the range
is optional, that I still think undefined
is better.
I'm marking this issue as closed since Hover now works with coc.nvim. Thank you everyone for your help 🙏