开发者

omnicppcomplete not supporting all forms of const

开发者 https://www.devze.com 2023-03-01 22:43 出处:网络
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 omnicp

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 omnicppcomple开发者_运维技巧te; 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消