2

I use neovim and coc-clangd for C/C++ programming. Every thing is ok and i can jump through definitions and search references of a symbol in all of my project files by holding the cursor on the symbol and use the gr keybinding for calling the jumpReferences action.

i want to know that is there any option to search a symbol by simply typing it and not with gr key binding in coc-clangd?

actually i can do this job using cscope by bellow command:

:cs find global <symbol-name>

but it would be much better using coc-clangd, because the indexing procedure is more simple. so i searched and found this link and in there i found jumpReferences coc action. i played so much with this action. for example i have run bellow command:

:call CocAction('jumpReferences', <symbol-name>)

this does not cause any error but ignores <symbol-name> and just gives the list of references to the symbol under the cursor.

fannheyward
  • 18,599
  • 12
  • 71
  • 109
AMIR REZA SADEQI
  • 409
  • 2
  • 5
  • 13

1 Answers1

4

I found the answer after more searching. Actually I have seen the answer to my question in the coc.nvim repository but to figure it out I had to read it more carefully.

based on the feature list of clangd, searching symbols in the scope of the whole project is available since clangd-10. (after understanding this fact) I found bellow lines in the vim sample configuration for coc.nvim plugin:

" Search workspace symbols.
nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>

so by we can search a symbol in a project just by hitting <space>s and type the symbol name in the openning interactive buffer.

Note: the list of symbols that coc-clangd finds is less than that of cscope. I actually think that this is not meaning that coc-clangd is not complete. Actually, coc-clangd works well. for example, consider the case of symbol io_delay in the linux kernel. this symbol is a function and coc.nvim/coc-clangd finds all of its references in the projct but there are some places where it is used like bellow:

.io_delay = xen_io_delay,

and clangd does not see these usages but cscope finds them. In this situation as i know the io_delay is not a function and the fact that clangd does not see it is not a drawback for it and actually I think it works well. I think(I don't know exactly) cscope indexing sometimes works like the searching in vim and because the word io_delay is used in this situation cscope sees this usage of io_delay.(this was what i thought about the reason of this situation so i would be happy if someone expert explains it more and clarify it for everyone.)

AMIR REZA SADEQI
  • 409
  • 2
  • 5
  • 13