Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My YouCompleteMe Vim plugin doesn't support STL

I just compiled and installed Vim, Vundle and YouCompleteMe plugin according to the introduction on Github. But the YouCompleteMe plugin doesn't work well in my Vim. It can auto complete the variable's name but it doesn't auto complete the operation of STL objects (vector, map). It can't even auto complete the "this->" in a class. It always tells me "(^U^N^P) Pattern not found." Have you guys seen this before? I use Ubuntu 12.04. What should I do?

like image 352
Jintao Guan Avatar asked Mar 07 '13 08:03

Jintao Guan


2 Answers

The readme on the github repo for the plugin now addresses the issue.

This is caused by an issue with libclang. Compiling from clang the binary uses the correct default header search paths but compiling from libclang.so does not. The issue seems to impact some OS's more than others. It appears that OS X Mavericks in particular has problems with this.

The current workaround is to call echo | clang -v -E -x c++ - and look at the paths under the #include <...> search starts here: heading. You should take those paths, prepend -isystem to each individual path and append them all to the list of flags you return from your FlagsForFile function in your .ycm_extra_conf.py file.

You might also want to take a look at the corresponding issue

like image 163
gkb0986 Avatar answered Nov 15 '22 09:11

gkb0986


I came here looking for the answer as well, I don't know python and have never hacked on something else before. So here is how I went about it.

  1. Find the error message. I went to ~/.vim/bundle/YouCompleteMe and grepped for "builtin includes" . Why? because that is part of the error message

    • a. I did not find it there so went to a higher level (cd ..) and repeat.
    • b. Found it see below ./vundle/plugin/libclang.py: print "WARNING: NxD libclang can not find the builtin includes."
  2. Modified Error message to ensure that this file was being run (my initials NxD) - worked.

  3. The message is printed by initClangComplete
  4. The message is printed after this invocation builtinHeaderPath = getBuiltinHeaderPath(library_path) hence we delve deeper into builtinHeaderPath
  5. getBuiltinHeaderPath runs a loop on known directories. I have 2 clang installations

    • a. ~/Downloads directory - where all software in the world is dumped
    • b. /usr/local because I wanted the latest clang which I cloned, compiled and built

    I added both the paths to this array : knownPaths

      "/usr/local/include",
      "/usr/local/lib/clang/3.3",
      "/home/nxd/Downloads/clang+llvm-3.2-x86_64-linux-ubuntu-12.04/clang/3.2"
    

    I noted that "," is the separator of array elements in python. I also earlier noted that print -> puts a message out in python and arguments are c-style %s, %d etc work - (that's how the "builtin include" message came on the screen in the first place)

  6. I also dumped some print statements into the loop so see what it was seeing and what it was doing.

    part code modified function "getBuiltinHeaderPath"

      print "active path from knownPaths is |%s|" %path
      files = os.listdir(path)
      print " files in path is |%s|" % files
      print " len (files) is |%d|" % len(files)
      if len(files) >= 1:
        files = sorted(files)
        subDir = files[-1]
      else:
        subDir = '.'
      # nxd -
      subDir = '.'
      path = path + "/" + subDir + "/include/"
      print " len (files) is |%d|" % len(files)
      print " files[-1] is |%s|" % files[-1]
      print "searching in path : |%s| " % path
    
  7. I realised that the expected behaviour of files[-1] was not what the author intended and modified it after the if condition to stay unchanged.

  8. Restart vim with a new cpp file and looked at :messages - It worked.

    Hope that helps.

like image 41
Neil Avatar answered Nov 15 '22 10:11

Neil