My C project has following structures. This is the structure for a large project, I can't change the structure. I want to use YouCompleteMe for semantic code completion for this project.
main/ // folder for C file to be compiled
|- module1.c // module main C file.
|- module2.c
|- .....
module1/
|- mod1_func1.c // function file to be included in main module C file.
|- mod1_func2.c
|- mod2_func3.c
module2/
|- mod2_func1.c
|- mod2_func2.c
|- mod2_func3.c
Content for moduleX.c
, this will include all related header files and module related C files.
#include "header1.h"
#include "header2.h"
...
#include "modX_func1.c"
#include "modX_func2.c"
Content for modX_funcX.c
has one or few function definitions. Doesn't have header included
// no header file included here
int modX_funcX(void) {.....}
Because there is not related header included, clang
must parse moduleX.c
in order to do code completion on modX_funcX.c
, I have tried clang
code completion from command line. Command below works
clang -x c -fsyntax-only -code-completion-at mod1_func1.c:4:11 module1.c
So my question: how to configure YouCompleteMe to do code completion when I edit the modX_funcX.c
file?
I guess modification to YouCompleteMe source might required to do this job. My current idea is to add a file mapping database with format:
path_of_file_to_complete:path_of_file_for_clang_to_parse
So before send the code completion request, get path_of_file_for_clang_to_parse
from database based on current buffer name, pass this file name to libclang
.
Is my idea workable? If Yes, where is exactly place to add this file mapping function?