vim clang complete doesn't see some functions

2019-04-14 06:11发布

问题:

I have vim and clang_complete installed but for some reason when I try to auto complete it doesn't see some of OpenGL's functions, such as glBindBuffer, or glEnableVertexAttribArray. I press CTRL + X and CTRL + U to force the auto complete and it shows the function names and parameters, but it's just missing some of the functions.

Even with glfw, I try auto completing GLFW_KEY_ESC but it's not there, I don't know why, it just says User defined completion (^U^N^P) Pattern not found

Does anyone have a solution to this problem? It's very annoying because I use these functions a lot and need the auto complete.

Thanks.

EDIT: Also my include header files are this:

#include <iostream>
#include <string>
#include <GL/glew.h>
#include <GL/glfw.h>
#include <glm/glm.hpp>

I'm on Arch Linux x64 by the way.

回答1:

All right I found the answer. Because of clang_complete not being able to complete the arguments created by GLEW (because the functions are defined as #define FOO somefunction, and not defined as: #define FOO(arg1, arg2, arg3) someFunction(arg1, arg2, arg3))

To fix this, you have to add this option to your ~/.vimrc file.

let g:clang_complete_macros = 1

Now, you'll get function completion, but still no argument completion. So, you'll have to replace GLEW (sadly) with

#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
#include <GL/glext.h>

This will finally complete the arguments, although, if there's an alternative to doing fixing this problem, I'd like to hear.



回答2:

To expand on zero57's answer.

You could add a clang_complete specific compile flag to define a macro for clang_complete

let g:clang_user_options = ' -DCLANG_COMPLETE_ONLY'

Then in your code you could use

#ifdef CLANG_COMPLETE_ONLY
    #define GL_GLEXT_PROTOTYPES
    #include <GL/gl.h>
    #include <GL/glext.h>
#else
    #include <GL/glew.h>
#endif

This isn't a perfect solution but clang_complete should now complete your parameters and when compiling you will be using glew. This worked for me with the YouCompleteMe (YCM) plugin so I assume it works with clang_complete.