neovim clangd show document when hover & go to definition (not declaration)

244 views Asked by At

I'm using some linux APIs for my study recently and had to read comments on kernel code. But some of my vim actions doesn't work as expected.

For example, I would like to read docstring of device_create which is written on drivers/base/core.c above device_create definition

but Neovim hover shows comment in the corresponding header file (which is include/linux/device.h) where the function is declared.

Also gd (go to definition) would not go to definition but goes to declaration.

Maybe vscode behaviors can give some hints for resolving.

In VSCode, in the beginning, it shows just like the neovim does.

but gd takes me to correct definition

and once I go to the definition, the hover results as expected.

Summary

  • How can I make neovim show comments on definition when I hover (K) ?
  • How can I make neovim go to the definition not the declaration when I gd?

Environments

  • neovim 0.9
  • LSP: clangd
  • compile_commands.json is created
1

There are 1 answers

0
parkjbdev On

I was inspecting for this issue for a while and founded out that it was an issue in clangd parsing the linux source file.

  1. move the entire project somewhere in the linux kernel source tree. (ex. under tools folder) - which resolves gd(goto definition) problem

  2. if hover still shows the comment in wrong place, go to the declaration of the function (ex. device_create in my case) and remove the comment above temporarily.

  3. remove .cache and let clangd re-index

and finally! clangd shows me the comment I wanted in the c file.

So, it turns out that clangd takes precedence in showing comments above the declaration part.

Of course, I don't think this is the best solution yet.

Maybe configuring clangd to take higher precedence on comments starting with /** (not /*) might fix this issue properly.

Please tell me if there is a way to do so.