randomphrase / company-c-headers

Auto-completion for C/C++ headers using Company
GNU General Public License v2.0
76 stars 9 forks source link

Can not include sub-directories #11

Closed cuonglm closed 8 years ago

cuonglm commented 8 years ago

A Simple header file like:

/usr/include/x86_64-linux-gnu/sys/types.h

can not be completed with:

#include <[TAB]>

I have to use:

#include <x86_64-linux-gnu/[TAB]>

Adding /usr/include/x86_64-linux-gnu/ to company-c-headers-path-system can fixed the issue. But there're many sub-directories inside /usr/include. Manually adding those directories cause a lot of works.

Is there anyway for company-c-headers automatically look in sub-directories?

randomphrase commented 8 years ago

Hi, thanks for the issue report, sorry it's taken a while to get back to you.

I have to say I'm not exactly clear on what the problem is. Completion does not (by default anyway) use the TAB key. So when you type #include < you should not expect completion to start, at least not with the default company settings.

I just tried to replicate the problem using the default setting for company-c-headers-path-system, which as you note includes /usr/include. In a new c++-mode buffer I typed #include <x86, and it instantly filled in the remaining x86_64-linux-gnu. This is because I am using the default company settings which will start the completion after typing 3 characters.

I also tried it by just typing #include <, and it successfully found all of the files and subdirectories within /usr/include after invoking M-x company-complete.

So I guess in summary I'm having trouble replicating your problem. Please let me know if there's something I'm missing.

cuonglm commented 8 years ago

@randomphrase Thanks for response.

I mean at this time, there is no way to complete:

#include <sys/types.h>

by typing:

#include <sys/[call company completion here]>

You have to:

#include <x86_64-linux-gnu/[call company completion here]>

or:

#include <x86_64-linux-gnu/sys/[call company completion here]>

I use gcc and clang and both compilers accept explicit include x86_64-linux-gnu/sys/types.h or implicit sys/types.h. Is there any way for company-c-headers act like that?

randomphrase commented 8 years ago

OK so in this case the sys/types.h path relies on the compiler's built-in system include paths. In other words, you don't have to specify /usr/include/x86_64-linux-gnu to the compiler because it knows about that path already. If you do gcc -v -E - you will see all of the built-in include paths for gcc. Other compilers will have other built-in include paths.

From the perspective of company-c-headers there's no way to know which compiler you are using, let alone the built-in include paths for that compiler. This is exactly why this is a customizable variable - so that it can be customized for your specific application.

Personally I rely on EDE to get this information - as described in the doco. If you aren't using EDE then you'll have to find another way to do it.

cuonglm commented 8 years ago

@randomphrase Well, that's exactly what I said in the question:

Adding `/usr/include/x86_64-linux-gnu/` to company-c-headers-path-system can fixed the issue. But there're many sub-directories inside `/usr/include`. Manually adding those directories cause a lot of works.

Is there anyway for `company-c-headers` automatically look in sub-directories?

The keyword is automatically.

It's better if I described this problem as a feature request.

Thanks for your information.