Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The first time I need to call CocAction('diagnosticToggle') twice to enable coc-diagnostic if i disable it in coc-settings.json #5231

Closed
0BananaBig0 opened this issue Dec 23, 2024 · 1 comment

Comments

@0BananaBig0
Copy link

0BananaBig0 commented Dec 23, 2024

Result from CocInfo

Start vim

versions

vim version: VIM - Vi IMproved 9.1 9010908
node version: v22.11.0
coc.nvim version: 0.0.82-aacbbcad 2024-11-23 13:34:02 +0800
coc.nvim directory: /home/banana/.vim/plugged/coc.nvim
term: dumb
platform: linux

Log of coc.nvim

2024-12-23T10:39:55.779 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:39:56.118 INFO (pid:315) [plugin] - coc.nvim initialized with node: v22.11.0 after 431
2024-12-23T10:39:56.123 INFO (pid:315) [services] - LanguageClient clangd state change: stopped => starting
2024-12-23T10:39:56.137 INFO (pid:315) [language-client-index] - Language server "languageserver.clangd" started with 327
2024-12-23T10:39:56.162 INFO (pid:315) [services] - LanguageClient clangd state change: starting => running
2024-12-23T10:39:56.169 INFO (pid:315) [services] - service languageserver.clangd started
2024-12-23T10:40:09.518 INFO (pid:315) [attach] - receive notification: showInfo []

First time call CocAction('diagnosticToggle')

versions

vim version: VIM - Vi IMproved 9.1 9010908
node version: v22.11.0
coc.nvim version: 0.0.82-aacbbcad 2024-11-23 13:34:02 +0800
coc.nvim directory: /home/banana/.vim/plugged/coc.nvim
term: dumb
platform: linux

Log of coc.nvim

2024-12-23T10:39:55.779 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:39:56.118 INFO (pid:315) [plugin] - coc.nvim initialized with node: v22.11.0 after 431
2024-12-23T10:39:56.123 INFO (pid:315) [services] - LanguageClient clangd state change: stopped => starting
2024-12-23T10:39:56.137 INFO (pid:315) [language-client-index] - Language server "languageserver.clangd" started with 327
2024-12-23T10:39:56.162 INFO (pid:315) [services] - LanguageClient clangd state change: starting => running
2024-12-23T10:39:56.169 INFO (pid:315) [services] - service languageserver.clangd started
2024-12-23T10:40:09.518 INFO (pid:315) [attach] - receive notification: showInfo []
2024-12-23T10:40:09.608 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:40:10.689 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:40:11.892 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:40:22.225 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:04.460 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:07.205 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:07.629 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:09.288 INFO (pid:315) [attach] - receive notification: diagnosticToggle []
2024-12-23T10:41:09.322 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:13.988 INFO (pid:315) [attach] - receive notification: showInfo []

Second time call CocAction('diagnosticToggle')

versions

vim version: VIM - Vi IMproved 9.1 9010908
node version: v22.11.0
coc.nvim version: 0.0.82-aacbbcad 2024-11-23 13:34:02 +0800
coc.nvim directory: /home/banana/.vim/plugged/coc.nvim
term: dumb
platform: linux

Log of coc.nvim

2024-12-23T10:39:55.779 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:39:56.118 INFO (pid:315) [plugin] - coc.nvim initialized with node: v22.11.0 after 431
2024-12-23T10:39:56.123 INFO (pid:315) [services] - LanguageClient clangd state change: stopped => starting
2024-12-23T10:39:56.137 INFO (pid:315) [language-client-index] - Language server "languageserver.clangd" started with 327
2024-12-23T10:39:56.162 INFO (pid:315) [services] - LanguageClient clangd state change: starting => running
2024-12-23T10:39:56.169 INFO (pid:315) [services] - service languageserver.clangd started
2024-12-23T10:40:09.518 INFO (pid:315) [attach] - receive notification: showInfo []
2024-12-23T10:40:09.608 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:40:10.689 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:40:11.892 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:40:22.225 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:04.460 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:07.205 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:07.629 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:09.288 INFO (pid:315) [attach] - receive notification: diagnosticToggle []
2024-12-23T10:41:09.322 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:13.988 INFO (pid:315) [attach] - receive notification: showInfo []
2024-12-23T10:41:14.072 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:17.473 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:37.723 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:37.821 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:52.294 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:53.235 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:41:59.055 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:42:08.263 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:42:09.510 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:42:09.753 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:42:26.331 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:42:29.658 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:42:30.045 INFO (pid:315) [attach] - receive notification: diagnosticToggle []
2024-12-23T10:42:30.159 INFO (pid:315) [attach] - receive notification: highlight []
2024-12-23T10:42:34.020 INFO (pid:315) [attach] - receive notification: showInfo []

First time call CocAction('diagnosticToggleBuffer')

versions

vim version: VIM - Vi IMproved 9.1 9010908
node version: v22.11.0
coc.nvim version: 0.0.82-aacbbcad 2024-11-23 13:34:02 +0800
coc.nvim directory: /home/banana/.vim/plugged/coc.nvim
term: dumb
platform: linux

Log of coc.nvim

2024-12-23T10:51:37.999 INFO (pid:5152) [plugin] - coc.nvim initialized with node: v22.11.0 after 431
2024-12-23T10:51:38.003 INFO (pid:5152) [services] - LanguageClient clangd state change: stopped => starting
2024-12-23T10:51:38.016 INFO (pid:5152) [language-client-index] - Language server "languageserver.clangd" started with 5170
2024-12-23T10:51:38.040 INFO (pid:5152) [services] - LanguageClient clangd state change: starting => running
2024-12-23T10:51:38.046 INFO (pid:5152) [services] - service languageserver.clangd started
2024-12-23T10:51:38.525 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:38.711 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:38.891 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:39.308 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:40.061 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:48.182 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:52.012 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:52.288 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:53.922 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:55.617 INFO (pid:5152) [attach] - Request action: diagnosticToggleBuffer []
2024-12-23T10:51:55.668 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:57.022 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:57.238 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:51:57.430 INFO (pid:5152) [attach] - receive notification: highlight []
2024-12-23T10:52:00.178 INFO (pid:5152) [attach] - receive notification: showInfo []

Describe the bug

After entering gvim, I need to call CocAction('diagnosticToggle') twice the first time to enable coc-diagnostic if it is disabled in coc-settings.json. But if i call CocAction('diagnosticToggleBuffer'), it only need to be called once.

Reproduce the bug

1, Disable coc-diagnostic in coc-settings.json
2, Lazy load coc.nvim.
3, Open a cpp file.
4, Wait a moment, call CocAction('diagnosticToggle')
5, call CocAction('diagnosticToggle')

  • Create file mini.vim with:
" 去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set nocompatible
" 开启256色支持
set t_Co=256
" 不少插件的信息更新都会需要这个时间
set updatetime=33
" 打开文件时进行解码的猜测列表
set fileencodings=utf-8,utf-16,utf-32,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936,big5,latin1
" 把当前文件转换为当前系统编码进行处理,这里为utf-8
set encoding=utf-8
scriptencoding utf-8
" 禁止生成临时文件
set nobackup
set nowritebackup
set noswapfile
set shortmess+=c
set showcmd
set foldmethod=manual
set statusline=[TYPE=%Y]\ [POS=%l,%v,%L]\ [%{toupper(&fileencoding)}=0x%B]%m%r
set statusline+=%=\ [%{strftime(\"%d/%m/%y-%H:%M\")}]%<
" 当窗口多于一个时显示状态行(1),总是显示状态行(2)
set laststatus=2
" 命令行(在状态行下)的高度,默认为1,这里是2
set cmdheight=2
" 显示行号
set number
" merge signcolumn and number column into one
set signcolumn=number
let g:plug_url_format = 'https://githubfast.com/%s.git'
call plug#begin('~/.vim/plugged')
" 补全插件, 动态检测语法插件, 可鼠标停留显示信息, Layz
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
" After 333ms, call the coc.nvim, markdown-preview and so on
let g:coc_start_at_startup = 0
function! CocTimerStart(timer)
  exec 'CocStart'
  call LazyPluginConfiguration()
  if &filetype==?'vim'
    " Disable automatic word wrapping
    set textwidth=0
  endif
  " call CocActionAsync('diagnosticToggle')
endfunction
call timer_start(333,'CocTimerStart',{'repeat':1})

function! LazyPluginConfiguration()
  " coc setting
  " Use tab for trigger completion with characters ahead and navigate.
  " NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped
  " by other plugin before putting this into your config.
  inoremap <expr> <TAB>
        \ coc#pum#visible() ? coc#pum#next(1):
        \ 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
  " <C-g>u breaks current undo, please make your own choice.
  inoremap <expr> <CR> coc#pum#visible() ? coc#_select_confirm()
                      \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
  function! CheckBackspace() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1]  =~# '\s'
  endfunction
  nmap <Space>c <Plug>(coc-declaration)
  nmap <Space>d <Plug>(coc-definition)
  nmap <Space>f <Plug>(coc-refactor)
  nmap <Space>i <Plug>(coc-implementation)
  nmap <Space>j <Plug>(coc-diagnostic-next-error)
  nmap <Space>k <Plug>(coc-diagnostic-prev-error)
  nmap <Space>n <Plug>(coc-rename)
  nmap <Space>r <Plug>(coc-references)
  nmap [a <Plug>(coc-codeaction)
  nmap [b <Plug>(coc-codeaction-line)
  nnoremap [c <CR>:call CocAction('jumpDeclaration', 'tabe')<CR>
  nnoremap [d <CR>:call CocAction('jumpDefinition', 'tabe')<CR>
  nnoremap [e :call CocAction('diagnosticToggleBuffer')<CR>
  nnoremap [i :call CocAction('jumpImplementation', 'tabe')<CR>
  nmap [j <Plug>(coc-diagnostic-next)
  nmap [k <Plug>(coc-diagnostic-prev)
  nmap [l <Plug>(coc-diagnostic-info)
  nmap [s <Plug>(coc-codeaction-selected)
  vmap [s <Plug>(coc-codeaction-selected)
  nnoremap [t :call CocActionAsync('diagnosticToggle')<CR>
  let g:coc_filetype_map = {'opencl': 'cpp'}
  let g:coc_global_extensions = ['coc-word', 'coc-tag', 'coc-dictionary', 'coc-snippets',
           \ 'coc-prettier', 'coc-yaml', 'coc-cmake', 'coc-clangd', 'coc-perl', 'coc-vimlsp',
           \ 'coc-sh', 'coc-pyright', 'coc-webview', 'coc-markmap', 'coc-markdown-preview-enhanced',
           \ 'coc-markdownlint', 'coc-json', 'coc-css', 'coc-tsserver']
  nmap <F7>  <Plug>(coc-format)
  vmap <F7>  <Plug>(coc-format-selected)
  " Use K to show documentation in preview window
  function! ShowDocumentation()
    if CocAction('hasProvider', 'hover')
      call CocActionAsync('doHover')
    else
      call feedkeys('K', 'in')
    endif
  endfunction
  nnoremap K :call ShowDocumentation()<CR>
  " Highlight the symbol and its references when holding the cursor
  augroup Plugin_Configuration | autocmd CursorHold * call CocActionAsync('highlight') | augroup END
  hi sym_hilight guifg='White' guibg='Black'
endfunction
{
   "languageserver":{
      "clangd": {
       "command": "clangd",
       "filetypes": ["c", "cpp", "objc", "objcpp"],
       "trace.server": "verbose",
       "initializationOptions": {
         "cacheDirectory": "/tmp/ccls"
       }
     }
   },
   "workspace.rootPatterns": [
      ".git",
      ".hg",
      ".projections.json",
      ".project",
      ".svn",
      ".root"
   ],
   "clangd.enabled": false,
   "coc.preferences.jumpCommand": "edit",
   "dialog.floatHighlight": "sym_hilight",
   "diagnostic.enable": false,
   "diagnostic.errorSign": "",
   "diagnostic.messageTarget": "echo",
   "diagnostic.virtualText": true,
   "diagnostic.warningSign": ""
}
@fannheyward
Copy link
Member

Use :call CocAction('diagnosticToggle', 1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants