ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.43k stars 2.81k forks source link

CompilationDatabase.GetCompilationInfoForFile does not match C++ signature #653

Closed martong closed 10 years ago

martong commented 10 years ago

Hi,

I am trying to set up my .ycm_extra_conf.py to use the compilation database. The database directory is correctly set in the file.

During executing vim I get the following error message:

ArgumentError: Python argument types in^@    CompilationDatabase.GetCompilationInfoForFile(CompilationDatabase, unicode)
^@did not match C++ signature:^@    GetCompilationInfoForFile(YouCompleteMe::CompilationDatabase {lvalue}, std::string)
Press ENTER or type command to continue

python --version Python 2.7.5

uname -a Linux esekilxxen1814 2.6.32.45-0.3-xen #1 SMP 2011-08-22 10:12:58 +0200 x86_64 x86_64 x86_64 GNU/Linux

gvim DEBUG info:

 2013-11-08 11:39:35,085 - DEBUG - Global extra conf not loaded or no function YcmCorePreload
serving on http://127.0.0.1:58952
2013-11-08 11:39:35,403 - INFO - Received event notification
2013-11-08 11:39:35,402 - INFO - Received event notification
2013-11-08 11:39:35,404 - DEBUG - Event name: BufferVisit
2013-11-08 11:39:35,403 - DEBUG - Event name: FileReadyToParse
2013-11-08 11:39:35,409 - INFO - Adding buffer identifiers for file: /home/egbomrt/phD/reflection/llvm/tools/clang/lib/AST/ASTConsumer.cpp
Traceback (most recent call last):
  File "/home/egbomrt/.vim/bundle/YouCompleteMe/third_party/bottle/bottle.py", line 861, in _handle
    return route.call(**args)
  File "/home/egbomrt/.vim/bundle/YouCompleteMe/third_party/bottle/bottle.py", line 1725, in wrapper
    rv = callback(*a, **ka)
  File "/home/egbomrt/.vim/bundle/YouCompleteMe/python/ycm/server/../../ycm/server/watchdog_plugin.py", line 76, in wrapper
    return callback( *args, **kwargs )
  File "/home/egbomrt/.vim/bundle/YouCompleteMe/python/ycm/server/../../ycm/server/handlers.py", line 68, in EventNotification
    event_handler )( request_data )
  File "/home/egbomrt/.vim/bundle/YouCompleteMe/python/ycm/server/../../ycm/completers/cpp/clang_completer.py", line 190, in OnFileReadyToParse
    flags = self._FlagsForRequest( request_data )
  File "/home/egbomrt/.vim/bundle/YouCompleteMe/python/ycm/server/../../ycm/completers/cpp/clang_completer.py", line 251, in _FlagsForRequest
    return self._flags.FlagsForFile( filename, client_data = client_data )
  File "/home/egbomrt/.vim/bundle/YouCompleteMe/python/ycm/server/../../ycm/completers/cpp/flags.py", line 60, in FlagsForFile
    client_data )
  File "/home/egbomrt/.vim/bundle/YouCompleteMe/python/ycm/server/../../ycm/completers/cpp/flags.py", line 108, in _CallExtraConfFlagsForFile
    return module.FlagsForFile( filename, client_data = client_data )
  File "/home/egbomrt/phD/reflection/llvm/.ycm_extra_conf.py", line 137, in FlagsForFile
    compilation_info = database.GetCompilationInfoForFile( filename )
ArgumentError: Python argument types in
    CompilationDatabase.GetCompilationInfoForFile(CompilationDatabase, unicode)
did not match C++ signature:
    GetCompilationInfoForFile(YouCompleteMe::CompilationDatabase {lvalue}, std::string)

gvim --version

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Nov  6 2013 20:48:17)
Included patches: 1-73
Compiled by egbomrt@esekilxxen1814
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
+balloon_eval    +float           +mouse_urxvt     -tag_any_white
+browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
+clientserver    -hangul_input    +netbeans_intg   +title
+clipboard       +iconv           +path_extra      +toolbar
+cmdline_compl   +insert_expand   +perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con_gui  +lua             +rightleft       +windows
+diff            +menu            +ruby            +writebackup
+digraphs        +mksession       +scrollbind      +X11
+dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     +xim
+emacs_tags      +mouseshape      -sniff           +xsmp_interact
+eval            +mouse_dec       +startuptime     +xterm_clipboard
+ex_extra        +mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    +xpm
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/home/egbomrt/local/share/vim"
 f-b for $VIMRUNTIME: "/home/egbomrt/local/share/vim/vim74"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng12     -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -L.  -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/CORE   -L/usr/local/lib -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lz -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lglib-2.0   -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -lncurses -lelf -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua -Wl,-E -Wl,-rpath,/usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/CORE  -L/usr/local/lib64  -L/usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/CORE -lperl -lm -ldl -lcrypt -lpthread -L/app/python/2.7.5/LMWP3/lib/ -lpython2.7   -Wl,-R -Wl,/usr/lib64 -L/usr/lib64 -lruby -ldl -lcrypt -lm  -L/usr/lib64

cat .ycm_extra_conf.py

# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
#
# Here's the license text for this file:
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>

import os
import ycm_core

# These are the compilation flags that will be used in case there's no
# compilation database set (by default, one is not set).
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
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=c++11',
# ...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',
'./tests/gmock/gtest',
'-isystem',
'./tests/gmock/gtest/include',
'-isystem',
'./tests/gmock',
'-isystem',
'./tests/gmock/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 = '/home/egbomrt/phD/reflection/build/llvmb/'

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, **kwargs ):
  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
  }

Gabor

Valloric commented 10 years ago

Sync to latest YCM.