0

I use NeoVim with coc-clangd. I have a project in C and I use vendor library SPL for STM8S chips. SPL library is in parent directory out of my project.

This is my compile_flags.txt:

-xc
-std=c99
-Wall
-pedantic
-I.
-I./inc/
-I./src
-I../inc
-I../SPL/inc
-I../SPL/src
-I/usr/local/stow/sdcc-gas/share/sdcc/include
-D_SDCC
-D_SDCC_
-D__SDCC
-D__SDCC__
-DSDCC_VERSION=40000
-D__CLANG
-DSTM8S208 
-DF_CPU=16000000
-Wno-gnu-binary-literal

If I input gd - go to definition - all works right. But if I input gi go to implementation, I get the message [coc.nvim] implementation not found .

My question is: Where is the place for configuration of sources files location (with implementations of functions)?

4
  • For the go to implementation to work with clangd you need a compile_commands.json file. Maybe this answer could help you? Feb 17 at 12:09
  • 1
    Does this answer your question? How to configure Neovim clangd to find my files? Feb 17 at 12:10
  • Unfortunately no. But this answer led me to another exploration and additional attempts. I will have to rephrase my question. Feb 18 at 8:07
  • In this moment I need to launch clangd (inside NVim) so that I can see its stdout. I haven't been able to persuade Nvim to redirect clangd stdout to a file. I need to view log to debug my issue. Feb 18 at 8:44

1 Answer 1

1

In order to be able to find the implementation clangd need to find a compile_commands.json that contains the compilation instruction of the modules (.cpp, .c file) that contains the implementation.

I believe the compile_commands.json must be in the current working directory.

In order to have Vim set the current working directory correctly I'm using the vim-rooter plugin and I put a .gitignore in the root of my project hierarchy to guide vim-rooter.

6
  • "We first check for a compilation database in the directory containing the source file, and then walk up into parent directories until we find one." Out-of-source builds as with CMake can cause problems, though. They are easily fixed with a symlink.
    – Friedrich
    Feb 18 at 12:50
  • 1
    Furthermore, creating a .gitignore file (that's not at all constrained to a repo's root dir) so a plugin can correctly "guess" that dir seems like a very convoluted way to do :cd <project_root>.
    – Friedrich
    Feb 18 at 13:14
  • 1
    Yes, that's correct. When I replace compile_flags.txt with compile_commands.json it works. But it is necessary use 'go to definition' no 'go to implementation'. Feb 19 at 20:31
  • Thanks for the feedback :-) Feb 19 at 20:34
  • 1
    I watch different behavior for similar files. It's mystery for me. I have two files in same directory. This two files is described same rules in compile_commands.json. Firs is in compilation database, second is not. If I use gd over function1 Nvim go to body of function1 in first file. If I use gd over function2 Nvim go to header of function2 in header file. Now I'm opening manually second source file with function2 and suddenly the editor behaves differently: I use gd over function2 Nvim go to body of function2 in second file. Feb 19 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.