ervandew / supertab

Perform all your vim insert mode completions with Tab
3.17k stars 216 forks source link

Setting omni and keyword completion with omnicppcomplete not working. #131

Open unnamedcookie opened 10 years ago

unnamedcookie commented 10 years ago

I'm not able to set supertab to fall back to keyword completion. I'm not sure if it is not the fault of omnicppcomplete.

Suppose I have the following piece of code in C++:

struct A {
  void abc() {};
  // void def() {};
};
int main(int argc, const char *argv[]) {
  A a;
  return 0;
}

now if I build ctags and type a. then I get correct completion for abc(). However, if I uncomment def() and don't rebuild the tags, I get

-- Omni completion (^O^N^P) Pattern not found

instead of falling back to <c-p>.

My current config looks like this

let g:SuperTabDefaultCompletionType = "context"
let g:SuperTabCompletionContexts = ['s:ContextText', 's:ContextDiscover']
let g:SuperTabContextTextOmniPrecedence = ['&omnifunc', '&completefunc']
let g:SuperTabContextDiscoverDiscovery = ["&completefunc:<c-x><c-u>", "&omnifunc:<c-x><c-o>"]
let g:SuperTabContextDefaultCompletionType = "<c-p>"
let g:SuperTabLongestHighlight = 1
let g:SuperTabLongestEnhanced = 1

Also here's my completefunc and omnifunc output:

:verbose set completefunc
  completefunc=SuperTabCodeComplete
        Last set from ~/.vim/bundle/supertab/plugin/supertab.vim
:verbose set omnifunc
  omnifunc=omni#cpp#complete#Main
        Last set from ~/.vim/bundle/omnicppcomplete/autoload/omni/cpp/complete.vim

I've went through the documentation and issues (here, here and here) but I'm still not able to make it work. I've tried adding chaining:

autocmd FileType *
  \ if &omnifunc != '' |
  \   call SuperTabChain(&omnifunc, "<c-p>") |
  \ endif

but it makes no difference.

I've tried different chaining configurations and since I'm completely out of ideas now, I would appreciate any help.

P.S. In case it might be relevant, here are also settings for omnicppcomplete:

let OmniCpp_ShowPrototypeInAbbr = 1
let OmniCpp_ShowAccess = 1
let OmniCpp_DisplayMode = 1
let OmniCpp_MayCompleteScope = 1
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
let OmniCpp_SelectFirstItem = 1
let OmniCpp_LocalSearchDecl = 1
ervandew commented 10 years ago

now if I build ctags and type a. then I get correct completion for abc(). However, if I uncomment def() and don't rebuild the tags, I get

-- Omni completion (^O^N^P) Pattern not found

The above line indicates that omni completion was executed, not user completion. As you can see in your comment below, supertab has bound itself to completefunc, which is user completion, not omni.

My current config looks like this

let g:SuperTabCompletionContexts = ['s:ContextText', 's:ContextDiscover']
let g:SuperTabContextDiscoverDiscovery = ["&completefunc:<c-x><c-u>", "&omnifunc:<c-x><c-o>"]

You can probably remove these 2 lines. I doubt you actually need s:ContextDiscover enabled.

let g:SuperTabContextTextOmniPrecedence = ['&omnifunc', '&completefunc']

I'm guessing this line above is the one causing your problems. That line tells supertab to use omni completion for context completions if it's set, otherwise, if not set, use user completion. If you remove that line supertab will use its default of trying user completion first. I'll update the docs to make this more clear.

Also here's my completefunc and omnifunc output:

:verbose set completefunc
  completefunc=SuperTabCodeComplete
        Last set from ~/.vim/bundle/supertab/plugin/supertab.vim
:verbose set omnifunc
  omnifunc=omni#cpp#complete#Main
        Last set from ~/.vim/bundle/omnicppcomplete/autoload/omni/cpp/complete.vim

Here you can see supertab being bound to completfunc which is user completion, but due to your config, supertab never attempts to use that function.

unnamedcookie commented 10 years ago

First of all, thank you for your help!

I'm guessing this line above is the one causing your problems.

That was a great guess, I've simply changed it to

let g:SuperTabContextTextOmniPrecedence = ['&completefunc', '&omnifunc']

and everything works. Also, everything works after removing two lines you've mentioned and this one altogether.

I'd swear that I've tried it to no avail. Going back to my example (and this is last question, I promise) when I hit tab after typing a.d I get -- User defined completion (^U^N^P) match 1 of 2 and some random completion from C++ ctags, def() not among them, but when I type a.de and hit tab I get -- Keyword Local completion (^N^P) Back at original which actually gives a.def. It would be great if you could share your thoughts on this - is it a behavior specific to supertab?

Also, if I might have a humble suggestion, it's not entirely clear to me why g:SuperTabContextDefaultCompletionType exists when it has no effect without chaining and you actually have to provide second function in a chain anyway - maybe it could be explained slightly clearer in the doc?

ervandew commented 10 years ago

I'd swear that I've tried it to no avail. Going back to my example (and this is last question, I promise) when I hit tab after typing a.d I get -- User defined completion (^U^N^P) match 1 of 2 and some random completion from C++ ctags, def() not among them, but when I type a.de and hit tab I get -- Keyword Local completion (^N^P) Back at original which actually gives a.def. It would be great if you could share your thoughts on this - is it a behavior specific to supertab?

This isn't specific to supertab. You should be able to reproduce the same result using a.d<c-x><c-u> and then a.d<c-p>. All that supertab really does is attempt to send the proper key sequence to vim. All these various supertab configuration settings and hooks are just there to tune supertab's decisions on what the proper key sequence to send to vim is. Once supertab has sent those keys, it's entirely up to the completion implementation (user, omni, keyword, etc) to decide what those completions are.

Also, if I might have a humble suggestion, it's not entirely clear to me why g:SuperTabContextDefaultCompletionType exists when it has no effect without chaining and you actually have to provide second function in a chain anyway - maybe it could be explained slightly clearer in the doc?

That setting is unrelated to completion chaining. Context completion works as follows: