hrsh7th / nvim-cmp

A completion plugin for neovim coded in Lua.
MIT License
7.91k stars 395 forks source link

debounce_text_changes flag is ignored when nvim-cmp is installed #435

Closed jhossbach closed 2 years ago

jhossbach commented 2 years ago

Describe the bug The debounce_text_changes flag is ignored when nvim-lsp is added as source for cmp.

Minimal config based on this:

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 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
call plug#end()
PlugInstall | quit

lua << EOF
local cmp = require "cmp"
cmp.setup {
    mapping = {
        ['<CR>'] = cmp.mapping.confirm({ select = true })
        },
    sources = {
        { name = "nvim_lsp" }, -- comment this out and the debounce_text_changes flag is not ignored
        },
    }
EOF

lua << EOF
require'lspconfig'.jedi_language_server.setup {
  flags = {
      debounce_text_changes = 5000, -- Wait 5 seconds before sending didChange
      }
}
EOF

To Reproduce

  1. Open a test file that starts the LSP (.py in this case, but I observed this with clangd as well)
  2. Type something that triggers LSP to show an error (for python add an additional space before creating a variable for example)

Expected behavior The error is shown after the 5 second period given as the debounce_text_changes flag. However, this is not the case if nvim-lsp is commented out as source.

Additional context I am using NVIM v0.6.0-dev+518-g1dbbaf89b

hrsh7th commented 2 years ago

The debounce text changes doesn't work as your expectation. It's debouncing textDocument/didChange request but nvim-cmp will send textDocument/completion for each key press (if the language server specifies isIncomplete=true).

The textDocument/didChange should be requested before the other LSP requests because the server needs to know the latest text content before the processing other LSP requests.

So it isn't a bug.

jhossbach commented 2 years ago

Thank you for the answer. Is there any way do debounce the textDocument/completion event as well?

hrsh7th commented 2 years ago

No. Currently, debouncing completion wasn't provided and I have no plan adding it.