6

I have omnicppcomplete working fine except once in a while it won't complete some of the variables methods/members. I finally got annoyed enough to dig into why and I believe the reason is that omnicppcomplete does support the syntax "Foo const & foo" in function arguments.

For example, if I have a function defined as:

int foo( Bar const & b ){
}

I won't be able to get completion information when I later type "b.". However if I change the signature to:

int foo( const Bar & b ){
}

I will be able to get completion information when I type "b.". It seems to only be in function argument lists because I tried simply defining a variable within the function with the signature "Bar const & bref" and I was able to get completion information for bref.

I would be surprised if this is an actual limitation of omnicppcomplete; anyone have any thoughts on whether or not this is a bug and/or if there is a workaround for it? Changing the coding style does not seem like a reasonable solution.

Neg_EV
  • 1,930
  • 1
  • 15
  • 23

2 Answers2

4

Seems like a limitation in omnicppcomplete, but I pulled up the vim debugger and found it.

Open up autoload/omni/cpp/utils.vim, go to line 518, should look like this:

  for token in tokens
        if state==0
            if token.value=='>'
                let parenGroup = token.group
                let state=1
            elseif token.kind == 'cppWord'
                let szResult = token.value.szResult
                let state=2
            elseif index(['*', '&'], token.value)<0 "This is line 518
                break
            endif

And change that line to:

 elseif token.value != 'const' && index(['*', '&'], token.value)<0

Or, here's the vim commands to do it =):

/index(\['\*', '&'],<CR>itoken.value != 'const' &&<ESC>:w

I'll try submitting this to the maintainer of omnicppcomplete, but it's kind of hackish, dunno if it'll get in. Might've been able to check if token.kind == 'cppKeyword', but I figured I'd err on the side of changing the least.

Xepo
  • 616
  • 5
  • 7
  • Thank you very much, I had given up hope on anyone answering. On an unrelated note, did the bounty entice you to look in some way. I never thought the bounty thing was useful; this is the first time it worked. Just more for my curiosity. – Neg_EV Jun 24 '11 at 20:42
  • I don't think the bounty really mattered that much to me directly, but it did make the question show up on the featured questions list for C++, which is where I saw it. It's a nice perk, though. =) Thanks! – Xepo Jun 24 '11 at 20:44
2

Having experienced issues with omnicppcomplete, I searched for an alternative and found clang complete which uses clang's metadata output (that is intended for such purposes). I works extremely well and provided your code compiles, it will understand everything.

Tamás Szelei
  • 23,169
  • 18
  • 105
  • 180
  • Yeah I saw clang complete but unfortunately I don't have access to clang on all of my development servers... – Neg_EV May 24 '11 at 17:22