nvim-lua / completion-nvim

A async completion framework aims to provide completion to neovim's built in LSP written in Lua
Apache License 2.0
975 stars 79 forks source link

completion-nvim breaks omnicomplete #54

Closed clason closed 4 years ago

clason commented 4 years ago

I have a setup where I use autocompletion for lsp suggestions (latex-lsp/texlab), but also rely on omnicompletion from a filetype plugin (lervag/vimtex), which has better (but slower) substring matching on menu strings as well.

However, this no longer works when completion-nvim is active; if I press <c-x c-o>, the omnicomplete suggestions pop up briefly, but then vanish again. This only happens if the typed string does not match any autocomplete candidates; if it does (because some candidates start with the string), the auto-complete suggestions are correctly replaced with the omnicomplete ones.

(This doesn't happen with other autocomplete plugins like ncm2 or asyncomplete.)

haorenW1025 commented 4 years ago

Can you check if you can reproduce this issue with the minimal config? Cause I can't reproduce it on my side. My testing init.vim

call plug#begin('~/.vim/plugged') 
    Plug 'neovim/nvim-lsp'
    Plug 'haorenW1025/completion-nvim'
    Plug 'lervag/vimtex'
call plug#end()
lua require'nvim_lsp'.texlab.setup{on_attach=require'completion'.on_attach}
" Use <Tab> and <S-Tab> to navigate through popup menu
inoremap <expr> <Tab>   pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"

" Set completeopt to have a better completion experience
set completeopt=menuone,noinsert,noselect

Kapture 2020-05-05 at 1 35 56

clason commented 4 years ago

Yes, it also happens with the minimal init.vim. But to reproduce, you should autocomplete inside the \ref{ or \cite{ with a string that is a substring, but not an initial, match. (Sorry, the issue should have been much more explicit.)

clason commented 4 years ago

Oh, and is it on purpose that the suggestions are sorted by length rather than alphabetically? It's a bit weird ;)

haorenW1025 commented 4 years ago

Yes, it also happens with the minimal init.vim. But to reproduce, you should autocomplete inside the \ref{ or \cite{ with a string that is a substring, but not an initial, match. (Sorry, the issue should have been much more explicit.)

Sorry but I still can't reproduce :( Can you give me a example tex file to help me reproduce this?

Oh, and is it on purpose that the suggestions are sorted by length rather than alphabetically? It's a bit weird ;)

I think this is the default behavior, I can make an option to change it though.

clason commented 4 years ago

Sure:

\documentclass{article}

\begin{document}

\cite

\bibliography{test}
\end{document}

test.bib

@article{test,
        title = {An article},
        author = {Ann Author},
}

Put the cursor after the cite and type {Aut<c-x c-o>

(It's an unusual default, that's all ;) But, yes, I personally would prefer it to be alphabetical.)

haorenW1025 commented 4 years ago

Okay I can reproduce the issue now, thanks for the detailed example.

clason commented 4 years ago

Thanks for the fast feedback, and sorry for not putting in the details from the start!

haorenW1025 commented 4 years ago

Can you please update and see if it works now? Thanks!

clason commented 4 years ago

Yes, now it works -- thank you for the quick fix!

haorenW1025 commented 4 years ago

@clason Can you try this option and see if the completion items is sorted alphabetically?

let g:completion_sorted_alphabetically = v:true
clason commented 4 years ago

Indeed, that does the trick, thanks!

Actually, it seems that the server already performs reasonable sorting. Is there any way to just disable sorting altogether? (Maybe make this an enum g:completion_sorting = 'none', 'length', 'alphabet'? with none just skipping the sorting?)

haorenW1025 commented 4 years ago

Hmm but we still have other completion sources(snippets for example, more sources are expected in the future), so it's probably not a good idea to make it without sorting. The option suggestion is nice though, I can definitely change that.

clason commented 4 years ago

Sure, that makes sense. (I'm not planning on mixing sources -- in fact, completion-nvim being fast, lean, and specifically tailored for the builtin LSP was what drew me to it in the first place! So having the option to disable sorting altogether would be useful for me. Doesn't mean it should be the default, of course! And I could just locally remove the sort call in completion.lua.)

haorenW1025 commented 4 years ago

Actually you're right, there maybe a lot of users like you only uses LSP source cause they want a more minimal solution compare to coc.nvim. I'll have the none option and put a warning in document saying you shouldn't use it with multiple sources.

haorenW1025 commented 4 years ago

@clason I follow your suggestion and add an option g:completion_sorting. Default value is "length", change that to "none" to disable that.

clason commented 4 years ago

Thank you! Just two questions, for my understanding:

  1. Wouldn't it be better for performance to have the if g:completion_sorting = 'none' outside the sort_items function (i.e., skip calling it entirely)? (Honest question, I don't know how well LuaJIT optimizes.)
  2. Wouldn't alphabet be a better -- or at least less surprising -- default? (Again, honest question, I'm sure there's a reason items are sorted by length currently.)
haorenW1025 commented 4 years ago

Wouldn't it be better for performance to have the if g:completion_sorting = 'none' outside the sort_items function (i.e., skip calling it entirely)? (Honest question, I don't know how well LuaJIT optimizes.)

I don't think that can make a noticeable difference, but it does make sense to prevent calling it. I'll make a change:)

Wouldn't alphabet be a better -- or at least less surprising -- default? (Again, honest question, I'm sure there's a reason items are sorted by length currently.)

I make the "length" as default mainly because my personal preference...Having alphabet as default may actually be better.

clason commented 4 years ago

"Personal preference" is sufficient reason for your own plugin ;)

haorenW1025 commented 4 years ago

That's true but I still change it ha ha. Oh also feel free to join us on gitter if you have other suggestion! Thanks a lot:)