neoclide / coc.nvim

Nodejs extension host for vim & neovim, load extensions like VSCode and host language servers.
Other
24.15k stars 953 forks source link

Add global argument to disable autocommands on CursorMove #4976

Closed TaylorTrz closed 2 months ago

TaylorTrz commented 2 months ago

Is your feature request related to a problem? Please describe. I was happy with coc.nvim until recently. After a few plugins installed, the cursor movement action (Enter j or k ) sometimes seems slow. So I tried to find all autocmd, it seems CursorMove autocmd in coc.nvim quite slow.

Test result was given below, in milliseconds:

397de0fb33cb944da2ed365052d9a59f_MD5

CursorMove can be a significant element to neovim plugin, Can it been disabled or imporved?

Describe the solution you'd like Disable the "CursorMove" inplugin/coc.nvim can fasten all cursor movement:

 " autocmd CursorMoved         * call s:Autocmd('CursorMoved', +expand('<abuf>'), [line('.'), col('.')])

Describe alternatives you've considered After I tried to search "CursorMove" in source code, it seems all the important object (treeview, ui, ...) related to this. I wonder if any global argument can be added to disable this auto command.

Additional context My coc.nvim configuration:

""" Set for coc.nvim
let g:coc_global_extensions = [
      \ 'coc-yank',
      \ 'coc-vimlsp',
      \ 'coc-syntax',
      \ 'coc-symbol-line',
      \ 'coc-snippets',
      \ 'coc-prettier',
      \ 'coc-marketplace',
      \ 'coc-highlight',
      \ 'coc-yaml',
      \ 'coc-sh',
      \ 'coc-pyright',
      \ 'coc-lua',
      \ 'coc-json',
      \ 'coc-clangd',
      \ 'coc-pairs' ]
" Having long updatetime (default is 4000 ms = 4s) can leads to noticeable delays and poor user experience
set updatetime=1000
" Always show the signcolumn, otherwise it would shift the text each time diagnostics appear/become resolved
set signcolumn=yes
" Set popup menu transparency
set pumblend=15
" Limit the popup menu to 10 items
set pumheight=10
" Go-To code navigation
nnoremap <silent> gd          <Plug>(coc-definition)
nnoremap <silent> gD          <Plug>(coc-declaration)
nnoremap <silent> gI          <Plug>(coc-implementation)
nnoremap <silent> gr          <Plug>(coc-references)
nnoremap <silent> gt          <Plug>(coc-type-definition)
" Symbol renaming
nnoremap <silent> <Leader>rn  <Plug>(coc-rename)
" Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>
" Map function and class text objects
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Remap to scroll float windows/popups
" nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
" nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
" inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"
" inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"
" vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"
" vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
" Use tab for trigger completion with characters ahead and **jump to next completion item**
function! CheckBackspace() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction
inoremap <silent><expr> <TAB>
      \ coc#pum#visible() ? coc#pum#next(1) :
      \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
      \ CheckBackspace() ? "\<Tab>" :
      \ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
inoremap <silent><expr> <cr> coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
" List all symbols depends on lsp server, or only with tags
noremap <silent> <Space>l :CocOutline<CR>
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Lazy load 300ms after startup
let g:coc_lazy_start=1
function! CocTimerStart(timer)
  exec "CocStart"
endfunction
call timer_start(300, 'CocTimerStart', {'repeat': 1})
" Disable auto complete in 1M or upper hugefile
let g:trigger_size = 1 * 1024 * 1024
augroup hugefile
  autocmd!
  autocmd BufReadPre *
        \ let size = getfsize(expand('<afile>')) |
        \ if (size > g:trigger_size) || (size == -2) |
        \   echohl WarningMsg | echomsg 'Disable auto-complete for huge file' | echohl None |
        \   exec 'CocDisable' |
        \ else |
        \   exec 'CocEnable' |
        \ endif |
        \ unlet size
augroup END
" coc-highlight enabled
autocmd CursorHold * silent call CocActionAsync('highlight')

And the test vim script:

function! s:localtime_milli()
    let s:lt = reltime()
    return s:lt[0] * 1000 + s:lt[1] / 1000
endfunction

function! s:Autocmd(...) abort
  if !get(g:, 'coc_workspace_initialized', 0)
    return
  endif
  call coc#rpc#notify('CocAutocmd', a:000)
endfunction

function s:lua_execute(cmd)
  vim.cmd(string.format('autocmd %s %s %s %s', group or 'lualine', event, pattern, cmd))
endfunction

" -------------------------------------------------------------------------------------------------
for x in range(1000)
    let s:start = s:localtime_milli()

    call s:Autocmd('CursorMoved', +expand('<abuf>'), [line('.'), col('.')])
    " lua local config = { kind='window', place={'statusline'}, trigger='autocmd' };  require('lualine').refresh(config)

    " let abuf = expand('%')
    " lua require('ibl').debounced_refresh(abuf)

    let s:elapsed = s:localtime_milli() -  s:start
    echomsg s:elapsed
endfor
" -------------------------------------------------------------------------------------------------
fannheyward commented 2 months ago

any global argument can be added to disable this auto command

No such configuration and there's no plan to add this. coc.nvim needs CursorMoved to refresh diagnostic/highlight/codeLens etc.

I'm using coc.nvim with lualine, didn't find any noticeable slowdown, what's your nvim version?

TaylorTrz commented 2 months ago

any global argument can be added to disable this auto command

No such configuration and there's no plan to add this. coc.nvim needs CursorMoved to refresh diagnostic/highlight/codeLens etc.

I'm using coc.nvim with lualine, didn't find any noticeable slowdown, what's your nvim version?

Version info:

$ nvim --version
NVIM v0.9.5
Build type: Release
LuaJIT 2.1.1692716794

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info

Can you show me your test result to execute this vim script?

function! s:localtime_milli()
    let s:lt = reltime()
    return s:lt[0] * 1000 + s:lt[1] / 1000
endfunction

function! s:Autocmd(...) abort
  if !get(g:, 'coc_workspace_initialized', 0)
    return
  endif
  call coc#rpc#notify('CocAutocmd', a:000)
endfunction

" -------------------------------------------------------------------------------------------------
for x in range(1000)
    let s:start = s:localtime_milli()

    call s:Autocmd('CursorMoved', +expand('<abuf>'), [line('.'), col('.')])

    let s:elapsed = s:localtime_milli() -  s:start
    echomsg s:elapsed
endfor
" -------------------------------------------------------------------------------------------------
fannheyward commented 2 months ago

Similar with your result:

image
TaylorTrz commented 2 months ago

Similar with your result:

image

Thanks for you reply.

fannheyward commented 2 months ago

Do you use nvim-treesitter with ibl? I don't use ibl and treesitter but I knew ibl + nvim-treesitter may cause some slowness, disable treesitter and try again.

TaylorTrz commented 2 months ago

Do you use nvim-treesitter with ibl? I don't use ibl and treesitter but I knew ibl + nvim-treesitter may cause some slowness, disable treesitter and try again.

Yes, after disable treesitter, I noticed an improvement in test results. About 20% time was reduced.