Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

omnicppcomplete not supporting all forms of const

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.

like image 298
Neg_EV Avatar asked Apr 28 '11 18:04

Neg_EV


2 Answers

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.

like image 53
Xepo Avatar answered Oct 07 '22 17:10

Xepo


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.

like image 32
Tamás Szelei Avatar answered Oct 07 '22 17:10

Tamás Szelei