Question

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?

Was it helpful?

Solution

I think my project structure is really lame, as said by pepper_chico, but no choice, I can't change it. In the passed few days, I did some hacking to both YouCompleteMe and libclang by change the API call of libclang to pass input_filename in additional to complte_filename.

This is a dirty hacking, but it works for me now. In case anyone might interesting, I have write a post to briefly record down my analysis and hacking process.

Update 2015-02-03

1 Year later, when I look back at this problem, I finally figured out a better way to hack YouCompleteMe for my need. Details look here

My modification on GitHub here, take note the branch name is lamely for now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top