0

consider this simple code:

#include <vector>
#include <string>

using namespace std;
vector<string> vec1;
//vec1.  //completion does not work AND break the completion that used to work if left without semicolon.

int main(){

    vector<string> vec2;
    vec2.push_back("sometext"); //completion works
    vec1.push_back("sometext"); //works here too

    return 0;
}

When I type "vec2." or "vec1." I am presented with a drop down list of all methods of the string type right after I type the point. So it works here.

Here is how it gets strange:

1) When I do "vec1." in the global scope right before main I am presented with wrong options in the drop down menu (namespace, using, asm, typedef, using, static_assert, extern, etc...). And it cannot find 'push_back' at all ("User defined completion (^U^P^N) Pattern not found)

2) Now, If I leave this line unfinished and forget to put a semicolon I then can't have proper autocompletion inside main() as I did before!

Only plugins I have running are clang_complete and supertab. I tried without supertab and with various _vimrc and .clang_complete settings to no benefit. I'm on win7, llvm/libclang are from official website. Is it normal that it bugs like that?

Ark.
  • 81
  • 1
  • 4

1 Answers1

0

The plugin relies completely on libclang to do the completion, which in turn only completes code that's more or less valid (I think it can forgive some errors before the cursor from which the parser is able to recover and code after the cursor can contain more serious errors).

Statements at the global scope are not among valid syntactical constructs of C++. This probably confuses clang's parsing enough to make it return some generic completion list that's not tied to the immediate context.

I think such behaviour is expected for any completion system that employs clang, unless it's explicitly worked around in some way.

xaizek
  • 5,098
  • 1
  • 34
  • 60