In C++ it is valid to prefix names in the global namespace with ::, yet YCM doesn't support this. For example: If using the OpenGL C interface the exported functions are available in the global namespace and may be used like so:
glEnable(...) OR ::glEnable(...). YCM offers to complete for the first, but not the (more correct!) second.
In C++ it is valid to prefix names in the global namespace with ::, yet YCM doesn't support this.
It does. You have somehow misconfigured YCM. You're probably using incorrect flags in your ycm_extra_conf.py file.
Sorry for this incorrect issue report then! Is this a suitable place to work out WHY it's not working for me? Here's my ycm_extra_conf.py file:
import os
import ycm_core
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wpedantic',
'-DNDEBUG',
'-DUSE_CLANG_COMPLETER',
'-std=c++11',
'-x',
'c++',
# C++ headers on my Linux machine
'-isystem',
'/usr/include/c++/4.7.3/',
# C++ headers on my Windows machine
'-isystem',
'C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/include',
# Windows external include directories
'-isystem',
'./external/windows/glew-1.10.0/include',
'-isystem',
'./external/windows/glfw-3.0.2.bin.WIN32/include/',
'-isystem',
'./external/windows/glm-0.9.4.6/',
'-isystem',
'./external/windows/libogg-1.3.1/include/',
'-isystem',
'./external/windows/libvorbis-1.3.3/include/',
'-isystem',
'./external/windows/lpng166/',
'-isystem',
'./external/windows/openal-soft-1.15.1-bin/include',
'-isystem',
'./external/windows/zlib-1.2.8/',
# Linux extern include directory
'-isystem',
'./external/linux/include',
# Boost
'-isystem',
'C:/Boost/include/boost-1_55',
'-isystem',
'/usr/local/include/boost/',
# Project libraries
'-I',
'./archive/include',
'-I',
'./event/include',
'-I',
'./gl/include',
'-I',
'./image/include',
'-I',
'./job/include',
'-I',
'./log/include',
'-I',
'./system/include',
'-I',
'./vfs/include'
]
# Set this to the absolute path to the folder (NOT the file!) containing the
# compile_commands.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = ''
if compilation_database_folder:
database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
database = None
def DirectoryOfThisScript():
return os.path.dirname( os.path.abspath( __file__ ) )
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
if not working_directory:
return list( flags )
new_flags = []
make_next_absolute = False
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
for flag in flags:
new_flag = flag
if make_next_absolute:
make_next_absolute = False
if not flag.startswith( '/' ):
new_flag = os.path.join( working_directory, flag )
for path_flag in path_flags:
if flag == path_flag:
make_next_absolute = True
break
if flag.startswith( path_flag ):
path = flag[ len( path_flag ): ]
new_flag = path_flag + os.path.join( working_directory, path )
break
if new_flag:
new_flags.append( new_flag )
return new_flags
def FlagsForFile( filename ):
if database:
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
# python list, but a "list-like" StringVec object
compilation_info = database.GetCompilationInfoForFile( filename )
final_flags = MakeRelativePathsInFlagsAbsolute(
compilation_info.compiler_flags_,
compilation_info.compiler_working_dir_ )
# NOTE: This is just for YouCompleteMe; it's highly likely that your project
# does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
# ycm_extra_conf IF YOU'RE NOT 100% YOU NEED IT.
try:
final_flags.remove( '-stdlib=libc++' )
except ValueError:
pass
else:
relative_to = DirectoryOfThisScript()
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
return {
'flags': final_flags,
'do_cache': True
}
Your flags appear to be fine. You might also have an error in the file you are trying to complete in which is making Clang bork on ::.
I honestly don't know. What I do know is that :: at the top level works (just tried it), so it's not a YCM bug.
I checked my .vimrc and noticed I was still loading tag files for the different libraries my project uses. I commented them out, restarted vim, and the YCM completion works as expected.
Now that is weird. Why would tags files impact how semantic completion works?
@drtwox you can see this add this to your vimrc
let g:ycm_semantic_triggers = {
\ 'c' : ['->', '.','re![_a-zA-z0-9]'],
\ 'objc' : ['->', '.', 're!\[[_a-zA-Z]+\w*\s', 're!^\s*[^\W\d]\w*\s',
\ 're!\[.*\]\s'],
\ 'ocaml' : ['.', '#'],
\ 'cpp,objcpp' : ['->', '.', '::','re![_a-zA-Z0-9]'],
\ 'perl' : ['->'],
\ 'php' : ['->', '::'],
\ 'cs,java,javascript,typescript,d,python,perl6,scala,vb,elixir,go' : ['.'],
\ 'ruby' : ['.', '::'],
\ 'lua' : ['.', ':'],
\ 'erlang' : [':'],
\ }
:point_up: that should be in the docs if it is not. But this completely solved my problem of not having auto-completion in C.
Most helpful comment
@drtwox you can see this add this to your vimrc