neoclide / coc.nvim

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

`go to reference` causes high cpu usage and vim gets stuck #3914

Closed sify21 closed 2 years ago

sify21 commented 2 years ago

Result from CocInfo

vim version: VIM - Vi IMproved 9.0 9000000 node version: v16.9.1 coc.nvim version: 0.0.81-2522eee5 2022-06-14 19:03:29 +0800 coc.nvim directory: /Users/sifangyuan/.vim/plugged/coc.nvim term: Apple_Terminal platform: darwin

Describe the bug

I use coc-go and coc-rust-analyzer. Recently I upgraded vim and all its plugins and coc plugins to latest version. After the upgrade, iterating through the location list of go to reference becomes very slow, vim consumes more cpu and gets stuck.

If I close the list preview (by pressing p), iterating through the location list is smooth as before.

I don't know if this is a bug related to vim 9 on mac.

Reproduce the bug

We will close your issue when you don't provide minimal vimrc and we can't reproduce it

if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
Plug 'dracula/vim', { 'as': 'dracula' }
Plug 'majutsushi/tagbar'
Plug 'scrooloose/nerdcommenter'
Plug 'mkitt/tabline.vim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'tpope/vim-vinegar'
call plug#end()

color dracula
" disable sqlcomplete
let g:omni_sql_no_default_maps = 1
syntax on

" coc.nvim
source ~/.vim/coc.nvim

" netrw
" let g:netrw_liststyle = 3

" tabline
set showtabline=2

" statusline
set laststatus=2
set statusline=%F%m%r\ %h%w%y\ col:%c\ lin:%l\,%L\ buf:%n\ win:%{tabpagewinnr(tabpagenr())}\ reg:%{v:register}
hi StatusLine cterm=bold ctermbg=Brown
hi StatusLineNC cterm=NONE ctermbg=DarkBlue

" transparent
hi Normal guibg=NONE ctermbg=NONE

set noexpandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
set nu rnu
set fileencodings=utf-8,chinese,latin-1
set termencoding=utf-8
set encoding=utf-8
set cursorline
set nobackup
set ignorecase
set completeopt-=preview
set splitright
set splitbelow

" folding
set foldmethod=syntax
set foldlevelstart=99

" autoclose
inoremap (<cr> (<cr>)<C-[>O
inoremap (, ()<C-[>i
inoremap {<cr> {<cr>}<C-[>O
inoremap {, {}<C-[>i
inoremap [, []<C-[>i
inoremap ", ""<C-[>i
inoremap ', ''<C-[>i

" ctags yaml
let g:tagbar_type_yaml = {
    \ 'ctagstype' : 'yaml',
    \ 'kinds' : [
        \ 'a:anchors',
        \ 's:section',
        \ 'e:entry'
    \ ],
  \ 'sro' : '.',
    \ 'scope2kind': {
      \ 'section': 's',
      \ 'entry': 'e'
    \ },
    \ 'kind2scope': {
      \ 's': 'section',
      \ 'e': 'entry'
    \ },
    \ 'sort' : 0
    \ }
" ctags xml support
let g:tagbar_type_xsd = {
    \ 'ctagstype' : 'XSD',
    \ 'kinds'     : [
        \ 'e:elements',
        \ 'c:complexTypes',
        \ 's:simpleTypes'
    \ ]
\ }
" ctags mapping
nmap <F8> :TagbarToggle<CR>

Screenshots (optional)

If applicable, add screenshots to help explain your problem.

fannheyward commented 2 years ago
vim version: VIM - Vi IMproved 9.0 9000000¬
node version: v16.15.1¬
coc.nvim version: 0.0.82-9efd466e 2022-06-14 23:35:12 +0800¬
coc.nvim directory: /Users/fannheyward/.local/share/nvim/plugged/coc.nvim¬
term: iTerm.app¬
platform: darwin

nmap <silent> gr <Plug>(coc-references) with list preview, tested with coc-rust-analyzer on rust-analyzer code, can't reproduce this.

sify21 commented 2 years ago

I don't know how to debug this. This is a backtrace of vim in lldb

(lldb) bt all
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGSTOP
  * frame #0: 0x0000000108ede682 vim`nfa_regmatch + 8422
    frame #1: 0x0000000108edbedc vim`nfa_regexec_both + 1168
    frame #2: 0x0000000108ec53b8 vim`vim_regexec_multi + 175
    frame #3: 0x0000000108f2a8e9 vim`syn_regexec + 116
    frame #4: 0x0000000108f289ef vim`syn_current_attr + 1454
    frame #5: 0x0000000108f2799b vim`syn_finish_line + 39
    frame #6: 0x0000000108f2774d vim`syntax_start + 3717
    frame #7: 0x0000000108f29b85 vim`syn_get_foldlevel + 89
    frame #8: 0x0000000108e44a0c vim`foldlevelSyntax + 29
    frame #9: 0x0000000108e4504c vim`foldUpdateIEMSRecurse + 1310
    frame #10: 0x0000000108e44fc4 vim`foldUpdateIEMSRecurse + 1174
    frame #11: 0x0000000108e44fc4 vim`foldUpdateIEMSRecurse + 1174
    frame #12: 0x0000000108e42508 vim`foldUpdate + 1974
    frame #13: 0x0000000108dc7106 vim`changed_common + 993
    frame #14: 0x0000000108dc6c5a vim`changed_bytes + 125
    frame #15: 0x0000000108dfeb34 vim`set_buffer_lines + 641
    frame #16: 0x0000000108dffe58 vim`call_internal_func + 98
    frame #17: 0x0000000108f5d7db vim`call_func + 1370
    frame #18: 0x0000000108f5d17c vim`get_func_tv + 647
    frame #19: 0x0000000108f63edd vim`ex_call + 729
    frame #20: 0x0000000108e1d904 vim`do_cmdline + 10496
    frame #21: 0x0000000108f5ed71 vim`call_user_func_check + 2596
    frame #22: 0x0000000108f5d8ab vim`call_func + 1578
    frame #23: 0x0000000108f5d17c vim`get_func_tv + 647
    frame #24: 0x0000000108dfd43e vim`eval_func + 289
    frame #25: 0x0000000108dfcf54 vim`eval9 + 1072
    frame #26: 0x0000000108dfe517 vim`eval8 + 238
    frame #27: 0x0000000108dfe152 vim`eval7 + 32
    frame #28: 0x0000000108dfdbcd vim`eval6 + 56
    frame #29: 0x0000000108dfd9bf vim`eval5 + 32
    frame #30: 0x0000000108dfd79b vim`eval4 + 45
    frame #31: 0x0000000108dfd4ca vim`eval3 + 34
    frame #32: 0x0000000108df5dac vim`eval1 + 40
    frame #33: 0x0000000108df907f vim`eval0_retarg + 98
    frame #34: 0x0000000108e0b694 vim`ex_let + 1270
    frame #35: 0x0000000108e1d904 vim`do_cmdline + 10496
    frame #36: 0x0000000108f5ed71 vim`call_user_func_check + 2596
    frame #37: 0x0000000108f5d8ab vim`call_func + 1578
    frame #38: 0x0000000108f5f6a8 vim`func_call + 273
    frame #39: 0x0000000108e014df vim`f_call + 367
    frame #40: 0x0000000108dffe58 vim`call_internal_func + 98
    frame #41: 0x0000000108f5d7db vim`call_func + 1370
    frame #42: 0x0000000108f5d17c vim`get_func_tv + 647
    frame #43: 0x0000000108dfd43e vim`eval_func + 289
    frame #44: 0x0000000108dfcf54 vim`eval9 + 1072
    frame #45: 0x0000000108dfe517 vim`eval8 + 238
    frame #46: 0x0000000108dfe152 vim`eval7 + 32
    frame #47: 0x0000000108dfdbcd vim`eval6 + 56
    frame #48: 0x0000000108dfd9bf vim`eval5 + 32
    frame #49: 0x0000000108dfd79b vim`eval4 + 45
    frame #50: 0x0000000108dfd4ca vim`eval3 + 34
    frame #51: 0x0000000108df5dac vim`eval1 + 40
    frame #52: 0x0000000108df907f vim`eval0_retarg + 98
    frame #53: 0x0000000108f639ee vim`ex_return + 120
    frame #54: 0x0000000108e1d904 vim`do_cmdline + 10496
    frame #55: 0x0000000108f5ed71 vim`call_user_func_check + 2596
    frame #56: 0x0000000108f5d8ab vim`call_func + 1578
    frame #57: 0x0000000108f5f6a8 vim`func_call + 273
    frame #58: 0x0000000108e014df vim`f_call + 367
    frame #59: 0x0000000108dffe58 vim`call_internal_func + 98
    frame #60: 0x0000000108f5d7db vim`call_func + 1370
    frame #61: 0x0000000108f5d17c vim`get_func_tv + 647
    frame #62: 0x0000000108dfd43e vim`eval_func + 289
    frame #63: 0x0000000108dfcf54 vim`eval9 + 1072
    frame #64: 0x0000000108dfe517 vim`eval8 + 238
    frame #65: 0x0000000108dfe152 vim`eval7 + 32
    frame #66: 0x0000000108dfdbcd vim`eval6 + 56
    frame #67: 0x0000000108dfd9bf vim`eval5 + 32
    frame #68: 0x0000000108dfd79b vim`eval4 + 45
    frame #69: 0x0000000108dfd4ca vim`eval3 + 34
    frame #70: 0x0000000108df5dac vim`eval1 + 40
    frame #71: 0x0000000108df907f vim`eval0_retarg + 98
    frame #72: 0x0000000108e0b694 vim`ex_let + 1270
    frame #73: 0x0000000108e1d904 vim`do_cmdline + 10496
    frame #74: 0x0000000108f5ed71 vim`call_user_func_check + 2596
    frame #75: 0x0000000108f5d8ab vim`call_func + 1578
    frame #76: 0x0000000108f5f6a8 vim`func_call + 273
    frame #77: 0x0000000108fbc838 vim`may_invoke_callback + 3114
    frame #78: 0x0000000108fbd7ee vim`channel_parse_messages + 401
    frame #79: 0x0000000108e49989 vim`parse_queued_messages + 142
    frame #80: 0x0000000108f53694 vim`inchar_loop + 113
    frame #81: 0x0000000108f535e1 vim`ui_inchar + 161
    frame #82: 0x0000000108e45e71 vim`inchar + 485
    frame #83: 0x0000000108e48c4a vim`vgetorpeek + 3883
    frame #84: 0x0000000108e478ab vim`vgetc + 283
    frame #85: 0x0000000108e494ca vim`plain_vgetc + 9
    frame #86: 0x0000000108e49644 vim`getchar_common + 173
    frame #87: 0x0000000108dffe58 vim`call_internal_func + 98
    frame #88: 0x0000000108f5d7db vim`call_func + 1370
    frame #89: 0x0000000108f5d17c vim`get_func_tv + 647
    frame #90: 0x0000000108dfd43e vim`eval_func + 289
    frame #91: 0x0000000108dfcf54 vim`eval9 + 1072
    frame #92: 0x0000000108dfe517 vim`eval8 + 238
    frame #93: 0x0000000108dfe152 vim`eval7 + 32
    frame #94: 0x0000000108dfdbcd vim`eval6 + 56
    frame #95: 0x0000000108dfd9bf vim`eval5 + 32
    frame #96: 0x0000000108dfd79b vim`eval4 + 45
    frame #97: 0x0000000108dfd4ca vim`eval3 + 34
    frame #98: 0x0000000108df5dac vim`eval1 + 40
    frame #99: 0x0000000108df907f vim`eval0_retarg + 98
    frame #100: 0x0000000108e0b694 vim`ex_let + 1270
    frame #101: 0x0000000108e1d904 vim`do_cmdline + 10496
    frame #102: 0x0000000108f5ed71 vim`call_user_func_check + 2596
    frame #103: 0x0000000108f5d8ab vim`call_func + 1578
    frame #104: 0x0000000108f5d17c vim`get_func_tv + 647
    frame #105: 0x0000000108dfd43e vim`eval_func + 289
    frame #106: 0x0000000108dfcf54 vim`eval9 + 1072
    frame #107: 0x0000000108dfe517 vim`eval8 + 238
    frame #108: 0x0000000108dfe152 vim`eval7 + 32
    frame #109: 0x0000000108dfdbcd vim`eval6 + 56
    frame #110: 0x0000000108dfd9bf vim`eval5 + 32
    frame #111: 0x0000000108dfd79b vim`eval4 + 45
    frame #112: 0x0000000108dfd4ca vim`eval3 + 34
    frame #113: 0x0000000108df5dac vim`eval1 + 40
    frame #114: 0x0000000108df907f vim`eval0_retarg + 98
    frame #115: 0x0000000108e0b694 vim`ex_let + 1270
    frame #116: 0x0000000108e1d904 vim`do_cmdline + 10496
    frame #117: 0x0000000108f5ed71 vim`call_user_func_check + 2596
    frame #118: 0x0000000108f5d8ab vim`call_func + 1578
    frame #119: 0x0000000108f5d17c vim`get_func_tv + 647
    frame #120: 0x0000000108dfd43e vim`eval_func + 289
    frame #121: 0x0000000108dfcf54 vim`eval9 + 1072
    frame #122: 0x0000000108dfe517 vim`eval8 + 238
    frame #123: 0x0000000108dfe152 vim`eval7 + 32
    frame #124: 0x0000000108dfdbcd vim`eval6 + 56
    frame #125: 0x0000000108dfd9bf vim`eval5 + 32
    frame #126: 0x0000000108dfd79b vim`eval4 + 45
    frame #127: 0x0000000108dfd4ca vim`eval3 + 34
    frame #128: 0x0000000108df5dac vim`eval1 + 40
    frame #129: 0x0000000108df907f vim`eval0_retarg + 98
    frame #130: 0x0000000108e0b694 vim`ex_let + 1270
    frame #131: 0x0000000108e1d904 vim`do_cmdline + 10496
    frame #132: 0x0000000108f5ed71 vim`call_user_func_check + 2596
    frame #133: 0x0000000108f5d8ab vim`call_func + 1578
    frame #134: 0x0000000108f5d17c vim`get_func_tv + 647
    frame #135: 0x0000000108dfd43e vim`eval_func + 289
    frame #136: 0x0000000108dfcf54 vim`eval9 + 1072
    frame #137: 0x0000000108dfe517 vim`eval8 + 238
    frame #138: 0x0000000108dfe152 vim`eval7 + 32
    frame #139: 0x0000000108dfdbcd vim`eval6 + 56
    frame #140: 0x0000000108dfd9bf vim`eval5 + 32
    frame #141: 0x0000000108dfd79b vim`eval4 + 45
    frame #142: 0x0000000108dfd4ca vim`eval3 + 34
    frame #143: 0x0000000108df5dac vim`eval1 + 40
    frame #144: 0x0000000108f5eda3 vim`call_user_func_check + 2646
    frame #145: 0x0000000108f5d8ab vim`call_func + 1578
    frame #146: 0x0000000108f5f77d vim`call_callback + 85
    frame #147: 0x0000000108f4fbe5 vim`check_due_timer + 632
    frame #148: 0x0000000108f53931 vim`ui_wait_for_chars_or_timer + 88
    frame #149: 0x0000000108eaa27d vim`WaitForChar + 21
    frame #150: 0x0000000108f53714 vim`inchar_loop + 241
    frame #151: 0x0000000108f535e1 vim`ui_inchar + 161
    frame #152: 0x0000000108e45e71 vim`inchar + 485
    frame #153: 0x0000000108e48c4a vim`vgetorpeek + 3883
    frame #154: 0x0000000108e478ab vim`vgetc + 283
    frame #155: 0x0000000108e494b5 vim`safe_vgetc + 9
    frame #156: 0x0000000108e89f54 vim`normal_cmd + 320
    frame #157: 0x0000000108fcba5b vim`main_loop + 571
    frame #158: 0x0000000108fcb4fa vim`vim_main2 + 3263
    frame #159: 0x0000000108fca4f1 vim`main + 5853
    frame #160: 0x000000011722351e dyld`start + 462
  thread #2
    frame #0: 0x00007ff80d1ab05a libsystem_kernel.dylib`__workq_kernreturn + 10
    frame #1: 0x00007ff80d1e3034 libsystem_pthread.dylib`_pthread_wqthread + 426
    frame #2: 0x00007ff80d1e1f57 libsystem_pthread.dylib`start_wqthread + 15

high cpu usage of vim in top WechatIMG38

sify21 commented 2 years ago

@fannheyward could you try reqwest source file src/redirect.rs, and go to reference on ActionKind? vim gets stuck every time when I get to location 11.

fannheyward commented 2 years ago
  1. cd /tmp
  2. git clone --depth=1 git@github.com:seanmonstar/reqwest.git
  3. /opt/homebrew/bin/vim src/redirect.rs
  4. :228 to ActionKind
  5. gr
截屏2022-07-07 19 05 10

minimal vimrc:

syntax on

set runtimepath^=~/.local/share/nvim/plugged/coc.nvim
set runtimepath^=~/src/coc-rust-analyzer
nmap <silent> gr <Plug>(coc-references)
vim version: VIM - Vi IMproved 9.0 9000000
node version: v16.15.1
coc.nvim version: 0.0.81-2522eee5 2022-06-14 19:03:29 +0800
coc.nvim directory: /Users/fannheyward/.local/share/nvim/plugged/coc.nvim
term: iTerm.app
platform: darwin
sjx95 commented 2 years ago

I have the same problem both on macOS and Debian (with linuxbrew vim), and my vim config is on https://github.com/sjx95/.vim

When I open any .go files and call go to reference, the vim gets stuck.

BTW I tried to compile vim82 on Debian, and go to reference works as normal with the same vim config.

pfernandez commented 2 years ago

@fannheyward I've been having the same issue with Typescript and Clojure, and finally figured out that it occurs when set foldmethod=syntax is present. The config that @sjx95 shared also has this setting, as does the config in the OP.

sjx95 commented 2 years ago

@fannheyward It really works by removing set foldmethod=syntax, thanks!!

sify21 commented 2 years ago

@fannheyward I also confirm that commenting out set foldmethod=syntax solves the problem. Both vim-8 and vim-9 respond faster without the setting.

pfernandez commented 2 years ago

@fannheyward Are you sure this should be closed? The foldmethod should not cause Vim to freeze up when calling <plug>(coc-references).