tessl install tessl/npm-coc-nvim@0.0.0LSP based intellisense engine for neovim & vim8.
Complexity: Basic | Category: Intelligence
Common Tasks: View errors | Navigate diagnostics | Toggle display | Filter by severity
View, navigate, and manage diagnostics (errors, warnings, hints, and information) from language servers.
nmap <silent> ]g <Plug>(coc-diagnostic-next)Jump to next diagnostic of any severity.
nmap <silent> ]e <Plug>(coc-diagnostic-next-error)Jump to next error, skipping warnings and hints.
nmap <silent> <leader>d <Plug>(coc-diagnostic-info)Display diagnostic message at cursor in float window.
:CocDiagnosticsShow all diagnostics in location list window.
:CocDiagnostics [height]Open all diagnostics in a location list window.
Parameters:
height: Optional window height in linesExample:
:CocDiagnostics
:CocDiagnostics 15<Plug>(coc-diagnostic-info)Show diagnostic message at cursor position in a float window.
Example:
nmap <silent> <leader>di <Plug>(coc-diagnostic-info)<Plug>(coc-diagnostic-next)Jump to next diagnostic of any severity.
Example:
nmap <silent> ]g <Plug>(coc-diagnostic-next)<Plug>(coc-diagnostic-prev)Jump to previous diagnostic of any severity.
Example:
nmap <silent> [g <Plug>(coc-diagnostic-prev)<Plug>(coc-diagnostic-next-error)Jump to next error diagnostic (skip warnings, info, hints).
Example:
nmap <silent> ]e <Plug>(coc-diagnostic-next-error)<Plug>(coc-diagnostic-prev-error)Jump to previous error diagnostic.
Example:
nmap <silent> [e <Plug>(coc-diagnostic-prev-error)CocAction('diagnosticInfo')
" Returns: voidShow diagnostic information at cursor in a float window.
Example:
nnoremap <silent> K :call CocAction('diagnosticInfo')<CR>CocAction('diagnosticNext', [severity])Jump to next diagnostic, optionally filtered by severity.
Parameters:
severity: Optional severity level ('error', 'warning', 'information', 'hint')Example:
" Jump to next diagnostic of any severity
call CocAction('diagnosticNext')
" Jump to next error only
call CocAction('diagnosticNext', 'error')CocAction('diagnosticPrevious', [severity])Jump to previous diagnostic, optionally filtered by severity.
Parameters:
severity: Optional severity levelExample:
call CocAction('diagnosticPrevious')
call CocAction('diagnosticPrevious', 'warning')CocAction('diagnosticList')
" Returns: listGet all diagnostics for all buffers.
Returns: List of diagnostic objects with properties:
file: File pathlnum: Line number (1-based)col: Column number (1-based)severity: Severity stringmessage: Diagnostic messagesource: Diagnostic sourceExample:
let diagnostics = CocAction('diagnosticList')
echo 'Total diagnostics: ' . len(diagnostics)
for diag in diagnostics
echo diag.file . ':' . diag.lnum . ' [' . diag.severity . '] ' . diag.message
endforCocAction('diagnosticToggle', [enable])Toggle diagnostics display globally.
Parameters:
enable: Optional boolean to explicitly enable/disableExample:
" Toggle diagnostics
call CocAction('diagnosticToggle')
" Explicitly disable
call CocAction('diagnosticToggle', v:false)
" Explicitly enable
call CocAction('diagnosticToggle', v:true)CocAction('diagnosticToggleBuffer', bufnr)Toggle diagnostics for a specific buffer.
Parameters:
bufnr: Buffer numberExample:
" Toggle for current buffer
call CocAction('diagnosticToggleBuffer', bufnr('%'))CocAction('diagnosticPreview')Preview diagnostic at cursor in a floating window with full details.
Example:
nnoremap <silent> <leader>dp :call CocAction('diagnosticPreview')<CR>CocAction('diagnosticRefresh', [bufnr])Force refresh diagnostics, optionally for a specific buffer.
Parameters:
bufnr: Optional buffer numberExample:
" Refresh current buffer
call CocAction('diagnosticRefresh')
" Refresh specific buffer
call CocAction('diagnosticRefresh', bufnr('%'))coc#util#diagnostic_info(bufnr, checkInsert)
" Returns: dictionaryGet diagnostic counts for a buffer.
Parameters:
bufnr: Buffer numbercheckInsert: Check if in insert modeReturns: Dictionary with keys:
error: Error countwarning: Warning countinformation: Info counthint: Hint countExample:
let info = coc#util#diagnostic_info(bufnr('%'), 0)
echo 'Errors: ' . info.error . ', Warnings: ' . info.warningcoc#util#check_refresh(bufnr)
" Returns: booleanCheck if diagnostics need refresh for a buffer.
Parameters:
bufnr: Buffer numberReturns: 1 if refresh needed, 0 otherwise.
let b:coc_diagnostic_disable = 1Disable diagnostics for the current buffer.
Type: Number
Default: 0
Example:
" Disable diagnostics for log files
autocmd BufEnter *.log let b:coc_diagnostic_disable = 1b:coc_diagnostic_infoRead-only variable containing diagnostic counts for the buffer.
Type: Dictionary (read-only) Structure:
error: Number of errorswarning: Number of warningsinformation: Number of info diagnosticshint: Number of hintsExample:
if exists('b:coc_diagnostic_info')
let errors = b:coc_diagnostic_info.error
echo 'Buffer has ' . errors . ' errors'
endiflet g:coc_status_error_sign = 'E'Sign text for errors in statusline.
Type: String
Default: 'E'
Example:
let g:coc_status_error_sign = '✗'let g:coc_status_warning_sign = 'W'Sign text for warnings in statusline.
Type: String
Default: 'W'
Example:
let g:coc_status_warning_sign = '⚠'autocmd User CocDiagnosticChange {command}Triggered when diagnostics are updated for any buffer.
Example:
autocmd User CocDiagnosticChange call UpdateStatusLine()
function! UpdateStatusLine() abort
let info = get(b:, 'coc_diagnostic_info', {})
let errors = get(info, 'error', 0)
let warnings = get(info, 'warning', 0)
echo 'Diagnostics: E' . errors . ' W' . warnings
endfunction" Highlight groups for sign column
CocErrorSign
CocWarningSign
CocInfoSign
CocHintSignExample:
highlight CocErrorSign ctermfg=Red guifg=#ff0000
highlight CocWarningSign ctermfg=Yellow guifg=#ffcc00
highlight CocInfoSign ctermfg=Blue guifg=#00aaff
highlight CocHintSign ctermfg=Cyan guifg=#00ffaa" Highlight groups for virtual text
CocErrorVirtualText
CocWarningVirtualText
CocInfoVirtualText
CocHintVirtualText" Highlight groups for code ranges
CocErrorHighlight
CocWarningHighlight
CocInfoHighlight
CocHintHighlight
CocDeprecatedHighlight
CocUnusedHighlight" Highlight groups for entire lines
CocErrorLine
CocWarningLine
CocInfoLine
CocHintLine" Highlight groups for floating windows
CocErrorFloat
CocWarningFloat
CocInfoFloat
CocHintFloatCommon diagnostic settings in coc-settings.json:
{
"diagnostic.enable": true,
"diagnostic.enableSign": true,
"diagnostic.enableHighlightLineNumber": true,
"diagnostic.refreshOnInsertMode": false,
"diagnostic.checkCurrentLine": true,
"diagnostic.virtualText": false,
"diagnostic.virtualTextCurrentLineOnly": true,
"diagnostic.virtualTextPrefix": " ❯❯❯ ",
"diagnostic.errorSign": "✗",
"diagnostic.warningSign": "⚠",
"diagnostic.infoSign": "ℹ",
"diagnostic.hintSign": "➤",
"diagnostic.locationlistUpdate": true,
"diagnostic.messageTarget": "float",
"diagnostic.messageDelay": 250,
"diagnostic.maxWindowHeight": 20,
"diagnostic.maxWindowWidth": 80
}" Navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" Navigate errors only
nmap <silent> [e <Plug>(coc-diagnostic-prev-error)
nmap <silent> ]e <Plug>(coc-diagnostic-next-error)
" Show diagnostic info
nmap <silent> <leader>d <Plug>(coc-diagnostic-info)" Show all diagnostics in location list
nnoremap <silent> <leader>dl :CocDiagnostics<CR>
" Custom diagnostic list function
function! ShowDiagnosticList() abort
let diagnostics = CocAction('diagnosticList')
if len(diagnostics) == 0
echo "No diagnostics found"
return
endif
" Group by severity
let errors = []
let warnings = []
let info = []
for diag in diagnostics
if diag.severity == 'Error'
call add(errors, diag)
elseif diag.severity == 'Warning'
call add(warnings, diag)
else
call add(info, diag)
endif
endfor
echo "Errors: " . len(errors)
echo "Warnings: " . len(warnings)
echo "Info: " . len(info)
endfunction
command! DiagnosticSummary call ShowDiagnosticList()" Toggle diagnostics globally
nnoremap <silent> <leader>dt :call CocAction('diagnosticToggle')<CR>
" Toggle for current buffer
nnoremap <silent> <leader>db :call CocAction('diagnosticToggleBuffer', bufnr('%'))<CR>
" Disable for specific filetypes
autocmd FileType markdown,text let b:coc_diagnostic_disable = 1" Show diagnostic info in statusline
function! StatusDiagnostic() abort
let info = get(b:, 'coc_diagnostic_info', {})
if empty(info) | return '' | endif
let msgs = []
if get(info, 'error', 0)
call add(msgs, g:coc_status_error_sign . info.error)
endif
if get(info, 'warning', 0)
call add(msgs, g:coc_status_warning_sign . info.warning)
endif
return join(msgs, ' ')
endfunction
set statusline+=%{StatusDiagnostic()}" Show diagnostic info on cursor hold
autocmd CursorHold * silent call CocActionAsync('diagnosticInfo')
" Set update time for faster response
set updatetime=300function! ShowErrorsOnly() abort
let all_diags = CocAction('diagnosticList')
let errors = filter(all_diags, 'v:val.severity == "Error"')
if len(errors) == 0
echo "No errors found"
return
endif
for err in errors
echo err.file . ':' . err.lnum . ' - ' . err.message
endfor
endfunction
command! CocErrors call ShowErrorsOnly()function! DiagnosticStats() abort
let all_diagnostics = CocAction('diagnosticList')
let stats = {'Error': 0, 'Warning': 0, 'Information': 0, 'Hint': 0}
let by_file = {}
for diag in all_diagnostics
let stats[diag.severity] += 1
if !has_key(by_file, diag.file)
let by_file[diag.file] = 0
endif
let by_file[diag.file] += 1
endfor
echo "=== Diagnostic Statistics ==="
echo "Errors: " . stats.Error
echo "Warnings: " . stats.Warning
echo "Info: " . stats.Information
echo "Hints: " . stats.Hint
echo "Total: " . len(all_diagnostics)
echo "\nFiles with issues: " . len(by_file)
endfunction
command! DiagStats call DiagnosticStats()let g:diagnostic_severity_index = 0
let g:diagnostic_severities = ['error', 'warning', 'information', 'hint']
function! CycleDiagnosticSeverity() abort
let g:diagnostic_severity_index = (g:diagnostic_severity_index + 1) % len(g:diagnostic_severities)
let severity = g:diagnostic_severities[g:diagnostic_severity_index]
echo "Jumping to: " . severity
call CocAction('diagnosticNext', severity)
endfunction
nnoremap <silent> <leader>dn :call CycleDiagnosticSeverity()<CR>" Customize sign appearance
let g:coc_user_config = {
\ 'diagnostic.errorSign': '✗',
\ 'diagnostic.warningSign': '⚠',
\ 'diagnostic.infoSign': 'ℹ',
\ 'diagnostic.hintSign': '➤'
\ }
" Customize sign highlight colors
highlight CocErrorSign ctermfg=Red guifg=#e06c75
highlight CocWarningSign ctermfg=Yellow guifg=#e5c07b
highlight CocInfoSign ctermfg=Blue guifg=#61afef
highlight CocHintSign ctermfg=Cyan guifg=#56b6c2" Refresh diagnostics for current buffer
nnoremap <silent> <leader>dr :call CocAction('diagnosticRefresh')<CR>
" Auto-refresh on save
autocmd BufWritePost * call CocAction('diagnosticRefresh')Problem: Diagnostics don't appear even though there are errors in the code.
Solutions:
" Check if diagnostics are enabled
:CocCommand workspace.showOutput
" Verify diagnostic settings
echo coc#util#get_config('diagnostic.enable')
" Check buffer-specific disable
if get(b:, 'coc_diagnostic_disable', 0)
echo "Diagnostics disabled for this buffer"
endif
" Manually refresh
call CocAction('diagnosticRefresh')Problem: Language server is running but not reporting diagnostics.
Solutions:
" Check LSP connection
:CocInfo
" Restart language server
:CocRestart
" Check language server configuration
:CocConfig
" Verify file is saved (some servers only diagnose saved files)
:wProblem: Diagnostic messages are overwhelming or distracting.
Solutions:
nmap ]e <Plug>(coc-diagnostic-next-error) (errors only)"diagnostic.virtualText": false"diagnostic.messageDelay": 500"diagnostic.virtualTextCurrentLineOnly": trueProblem: Diagnostic updates cause editor to slow down.
Solutions:
"diagnostic.refreshOnInsertMode": false"diagnostic.refreshAfterSave": trueautocmd BufEnter * if line('$') > 5000 | let b:coc_diagnostic_disable = 1 | endifProblem: Sign column doesn't show diagnostic indicators.
Solutions:
"diagnostic.enableSign": true:set signcolumn=yeshighlight CocErrorSign ctermfg=Red guifg=#ff0000
highlight CocWarningSign ctermfg=Yellow guifg=#ffcc00Problem: Diagnostics report errors that aren't actually errors.
Solutions:
:CocUpdate:CocLocalConfig:CocRestartProblem: After fixing code, diagnostics still show old errors.
Solutions:
:w (many servers require save)call CocAction('diagnosticRefresh')"diagnostic.refreshAfterSave": true:CocRestart