nvim-cmp
nvim-cmp copied to clipboard
Missing items in autocomplete for clangd
FAQ
- [X] I have checked the FAQ and it didn't resolve my problem.
Announcement
- [X] I have checked Breaking change announcement.
Minimal reproducible full config
if has('vim_starting')
set encoding=utf-8
endif
scriptencoding utf-8
if &compatible
set nocompatible
endif
let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end
execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/vim-vsnip'
Plug 'neovim/nvim-lspconfig'
call plug#end()
PlugInstall | quit
" Setup global configuration. More on configuration below.
lua << EOF
local cmp = require "cmp"
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<CR>'] = cmp.mapping.confirm({ select = true }),
['<C-Space>'] = cmp.mapping.complete(),
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "buffer" },
}),
}
EOF
lua << EOF
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
require'lspconfig'.clangd.setup {
capabilities = capabilities,
}
EOF
Description
Not all items that should appear in autocompletion actually appear.
Steps to reproduce
I noticed this when using the GLEW library in C++, so I'm going to include steps for that, but the problem may happen on other circumstances or with other language servers as well.
- Paste this into a test cpp file:
#include <GL/glew.h>
int main() {
}
- Inside the main function, start typing
glGetShader
. You should get the following result: - Press
<C-Space>
to manually trigger completions. Now the results are correct:
Expected behavior
Completion items should be updated while typing so that it becomes unnecessary to press <C-Space>
to manually update.
Actual behavior
Completion items don't seem to be updated while typing, only filtered after completion is triggered for the first time. As a result, some items are missing in autocomplete.
Additional context
I tried tinkering with nvim-cmp's performance options, with no success, it didn't change anything in the behavior. I also tried changing the trigger settings, but couldn't figure out exactly what I was doing.
Likewise, I also tested the example in VSCode, and it behaves as expected.
edit: formatting, add screenshots, context
It is the problem of nvim-cmp? I think it is clangd's feature. I think to gather candidates is very slow. And it does not provide all candidates quickly.
In my experience, clangd is very fast, especially when compared to python and typescript servers. I'm almost certain this issue also happens on those servers as well.
I found a workaround which is to put
trigger_characters = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '_'}
in the source config, so that it updates on every keystroke, but I'd rather have a better solution if possible
OK. The result seems cached.
Does increasing fetching_timeout help?
The clangd returns full items when user requested manual completion.
Oh. Sorry. I miss the VSCode example. I'll check it.
Hm... @kakig Could you check your clangd's version? (both of VSCode's one and nvim's one)
After some of the investiagation, I think the vscode-clangd
and clangd
does not have the client specific implementation.
So it may be a bug in nvim-cmp
Hm... @kakig Could you check your clangd's version? (both of VSCode's one and nvim's one)
They are using the same clangd binary.
clangd --version
clangd version 14.0.6
Features: linux
Platform: x86_64-pc-linux-gnu
@kakig Could you provide the reproduction steps that does not needed to use GL
lib?
I'll disable the workaround and see if I can find any issues that are more easy to reproduce
I've got some updates. It seems that the problem is really related to clangd, as it started crashing a lot while I was using it, and switching to ccls fixed my problems. You can close the issue if you think that this isn't a bug in nvim-cmp.
In case this information is useful, I was able to reproduce the issue with just the C++ standard library. It seems to happen more often when using backspace after the completion popup appears. Start with the following code:
#include <memory>
int main() {
return 0;
}
and insert std::pointer.
note that the penultimate item in the completion is
is_pointer
. Now, if you backspace pointer
, but leave std::
, and start typing is_pointer
, it should appear in the completion items, but instead, nothing appears.