emacs-ycmd icon indicating copy to clipboard operation
emacs-ycmd copied to clipboard

#include path completion doesn't work

Open r4nt opened this issue 10 years ago • 14 comments

Do I need to do some special configuration here? It seems like I only get identifier completion, not semantic completion. @Valloric - anything a ycmd frontend has to be careful about here?

r4nt avatar Jan 20 '15 14:01 r4nt

I can't think of any special configuration you should need. That feature certainly works well for me. Does semantic completion seem to work well everywhere else in the file?

abingham avatar Jan 20 '15 15:01 abingham

#include path completion is actually a part of the general completion engine... which is technically composed of the trio of identifier completer engine, ultisnips completer engine and filepath completer engine. The general completion engine is turned on for every filetype.

Querying ycmd for completions after #include " or #include < will produce include-completion through the filename completion engine... it will query the ycm_extra_conf.py file for compilation flags and will extract the ones that point to header include directories. These folders will be queried for header names (or subfolders).

Valloric avatar Jan 20 '15 18:01 Valloric

Yes, header completion works, but only after #include <. When using #include " company-ycmd--prefix returns nil because of the condition (not (company-in-string-or-comment))

See #141

ptrv avatar Jan 20 '15 21:01 ptrv

@prtv is absolutely right, and his patch plugs that hole. Does that fix things up for you, @r4nt?

abingham avatar Jan 21 '15 05:01 abingham

Works in general now, but doesn't seem to list all possible completions after / #include "dir1/a (works, shows all completions starting with "a" in "dir1") #include "dir1/ (doesn't work, not giving any completions)

r4nt avatar Jan 29 '15 11:01 r4nt

I use ycmd with compile_commands.json and just I discover that ycmd should complete include statements. I always thought that it was not supported and I used company-c-headers within a "company group backend" to have this feature. I give a try and I am not able to make it working because when trying to complete "#include <vec" ycmd gives: "RuntimeError: No completions found; errors in the file?" Is this feature working? Do I need some special configuration?

damienrg avatar Feb 14 '17 23:02 damienrg

Include completion should work. #include <vec should give you results.

Also #include "dir/ should complete correctly.

Both cases work for me.

@r4nt Are you still encountering this issue?

ptrv avatar Feb 15 '17 07:02 ptrv

@damienrg As @ptrv says, this should work. Can you post your *ycmd-server* buffer contents (or at least any parts that might be relevant to this issue)?

abingham avatar Feb 15 '17 08:02 abingham

I created a repository to ease testing. With this configuration I only have the following messages when trying to complete on #include <vec :

2017-02-15 22:44:18,590 - INFO - Received completion request
2017-02-15 22:44:18,591 - DEBUG - Using filetype completion: False

damienrg avatar Feb 15 '17 21:02 damienrg

@damienrg I checked out your test repository and indeed I couldn't complete the vector include. I got the same error from the server: RuntimeError: No completions found; errors in the file?

Looking at the debug-info with M-x ycmd-show-debug-info RET I could see that I had no other compile flags than ycmd/ycmd/clang_includes.

It looks like ycmd doesn't see the standard includes paths. There is a section about this in the documentation: https://github.com/Valloric/YouCompleteMe/#completion-doesnt-work-with-the-c-standard-library-headers

There is a workaround in that section which describes how to get the system include path and to add them to the compile flags.
After adding the system include paths to the flags, completion on #include <vec works.

Hope this helps

ptrv avatar Feb 15 '17 22:02 ptrv

I will try it but I do not understand why do I need to add includes while completion is working here:

std::vector<int> v;
v. // completion work here

To complete ycmd must know where vector is.

You reported that completion works in https://github.com/abingham/emacs-ycmd/issues/140#issuecomment-279936063. Are you using a compilation database? If not, have you set include path in your ycm_extra_conf.py?

damienrg avatar Feb 16 '17 11:02 damienrg

@d0k apropos, can we enable clang-include-fixer for YCM nowadays without too much hassle?

r4nt avatar Feb 16 '17 12:02 r4nt

@damienrg My default .ycm_extra_conf.py also adds the system includes to the ones found in a compilation database. So yes, I am using both like in this conf: https://github.com/abingham/emacs-ycmd/blob/master/test/resources/.ycm_extra_conf.py

ptrv avatar Feb 16 '17 12:02 ptrv

@ptrv Indeed it works if I do the workaround mentioned in the ycmd documentation (I just used your function as it does the job). Anyhow, it is annoying that we still have to use a workaround for a 4 years old bug.

damienrg avatar Feb 16 '17 22:02 damienrg