Closed clason closed 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
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.)
Oh, and is it on purpose that the suggestions are sorted by length rather than alphabetically? It's a bit weird ;)
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.
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.)
Okay I can reproduce the issue now, thanks for the detailed example.
Thanks for the fast feedback, and sorry for not putting in the details from the start!
Can you please update and see if it works now? Thanks!
Yes, now it works -- thank you for the quick fix!
@clason Can you try this option and see if the completion items is sorted alphabetically?
let g:completion_sorted_alphabetically = v:true
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?)
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.
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.)
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.
@clason I follow your suggestion and add an option g:completion_sorting
. Default value is "length", change that to "none" to disable that.
Thank you! Just two questions, for my understanding:
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.)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.)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.
"Personal preference" is sufficient reason for your own plugin ;)
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:)
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.)