Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c Headers autocomplete #1678

Closed
yotamN opened this issue Sep 13, 2015 · 17 comments
Closed

c Headers autocomplete #1678

yotamN opened this issue Sep 13, 2015 · 17 comments

Comments

@yotamN
Copy link

yotamN commented Sep 13, 2015

after I realize what to do with the .ycm_extra_conf I edited the flags to this:

flags = [
'-Wall',
# '-Wextra',
# '-Werror',
# '-Wc++98-compat',
# '-Wno-long-long',
# '-Wno-variadic-macros',
# '-fexceptions',
# '-DNDEBUG',
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.
# '-DUSE_CLANG_COMPLETER',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c99',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x',
'c',
#'-isystem',
#'../BoostParts',
#'-isystem',
# This path will only work on OS X, but extra paths that don't exist are not
# harmful
#'/System/Library/Frameworks/Python.framework/Headers',
# '-isystem',
# '../llvm/include',
# '-isystem',
# '../llvm/tools/clang/include',
'-I',
'.',
#'-I',
#'./ClangCompleter',
'-isystem',
'/usr/include'
#'-isystem',
#'./tests/gmock/gtest',
#'-isystem',
#'./tests/gmock/gtest/include',
#'-isystem',
#'./tests/gmock',
#'-isystem',
#'./tests/gmock/include',
]

But I don't get autocomplete from the headers, only from the code I have in the file I'm in.

I got this error: native filetype completion not supported for current file, What am I doing wrong?

@vheon
Copy link
Contributor

vheon commented Sep 13, 2015

Looks like you didn't compile the semantic engine in.

How did you install YCM?

@yotamN
Copy link
Author

yotamN commented Sep 13, 2015

@vheon IIRC I did it like this:

cd ~/.vim/bundle/YouCompleteMe
./install.py --clang-completer

@puremourning
Copy link
Member

What does :YcmDebugInfo say? Take a look at CONTRIBUTING.md

@yotamN
Copy link
Author

yotamN commented Sep 15, 2015

@puremourning The output is:

Printing YouCompleteMe debug information...
-- Server has Clang support compiled in: True
-- Clang version: clang version 3.6.2 (tags/RELEASE_362/final)
-- Flags for /home/yotam/Documents/c/1.c loaded from /home/yotam/Documents/c/.ycm_extra_conf.py:
-- ['-x', 'c++', '-isystem', '/home/yotam/.vim/bundle/YouCompleteMe/third_party/ycmd/ycmd/../clang_includes']
-- Server running at: http://127.0.0.1:58175
-- Server process ID: 868
-- Server logfiles:
--   /tmp/ycm_temp/server_58175_stdout.log
--   /tmp/ycm_temp/server_58175_stderr.log

@micbou
Copy link
Collaborator

micbou commented Sep 15, 2015

The flags in the :YcmDebugInfo output do not correspond to the flags in your first post. Could you give us the whole content of the .ycm_extra_conf.py file in the ~/Documents/c/ folder?

@micbou
Copy link
Collaborator

micbou commented Sep 30, 2015

No answer, I am closing this.

@micbou micbou closed this as completed Sep 30, 2015
@hanetzer
Copy link

I think I'm having the same issue; I installed with pathogen, git cloned and updated the submodules and ran python2 setup.py --clang-completer, think I have my ycm_extra_conf.py setup right (proper -I directives to where I expect the headers to be), but its not completing from anything other than what's inside the currently edited file (granted that is useful, but not as useful as I'd like); :YcmDebugInfo apparently isn't getting my flags somehow, it shows them as being []
.ycm_conf_extra.py

@micbou
Copy link
Collaborator

micbou commented Oct 31, 2015

What is the full output of :YcmDebugInfo?

@hanetzer
Copy link

Added to the previous gist

@micbou
Copy link
Collaborator

micbou commented Oct 31, 2015

The issue is at the line 89 of your .ycm_extra_conf. If you are not using a compilation database, you need to leave this variable as an empty string:

compilation_database_folder = ''

If you are using one, you need to specify an absolute path (containing the compile_commands.json file), not a relative one.

@hanetzer
Copy link

Ah crap. I take it that the flags [] and compilation_database_folder are mutually exclusive?

@micbou
Copy link
Collaborator

micbou commented Oct 31, 2015

This is how it works in this .ycm_extra_conf.py file but you could change the logic.

@hanetzer
Copy link

Question... with that settled most things seem to work, but some issues still remain. If I define a function in a header, and switch to a source file that includes it, should i be able to complete those functions using ycm? because if so, I'm not seeing this behavior.

@vheon
Copy link
Contributor

vheon commented Oct 31, 2015

So you are in the src file, press <C-Space> and the function don't get suggested?

@hanetzer
Copy link

Just noticed that when googling around. I expected it to be a part of the tab complete, can one remap it?

@micbou
Copy link
Collaborator

micbou commented Nov 1, 2015

See the README.md.

@Grayninja
Copy link

The /usr/include is not enough to get C++ header completion. Try adding additional header location based on compiler version X.Y.Z (e.g. gcc version 6.1.1):

'-isystem',
'/usr/include/c++/X.Y.Z',

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants