or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/coc.nvim@0.0.x

docs

index.md
tile.json

tessl/npm-coc-nvim

tessl install tessl/npm-coc-nvim@0.0.0

LSP based intellisense engine for neovim & vim8.

diagnostics.mddocs/intelligence/

Diagnostics [Basic]

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.

Table of Contents

  • Common Tasks
  • Commands
  • Key Mappings
  • CocAction API
  • Utility Functions
  • Buffer Variables
  • Global Variables
  • Autocmd Events
  • Highlight Groups
  • Configuration
  • Usage Examples
  • Error Handling
  • Troubleshooting
  • See Also

Common Tasks

Navigate to Next Diagnostic

nmap <silent> ]g <Plug>(coc-diagnostic-next)

Jump to next diagnostic of any severity.

Navigate to Next Error Only

nmap <silent> ]e <Plug>(coc-diagnostic-next-error)

Jump to next error, skipping warnings and hints.

Show Diagnostic Info

nmap <silent> <leader>d <Plug>(coc-diagnostic-info)

Display diagnostic message at cursor in float window.

Open Diagnostic List

:CocDiagnostics

Show all diagnostics in location list window.

Commands

:CocDiagnostics

:CocDiagnostics [height]

Open all diagnostics in a location list window.

Parameters:

  • height: Optional window height in lines

Example:

:CocDiagnostics
:CocDiagnostics 15

Key Mappings

<Plug>(coc-diagnostic-info)

<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)

<Plug>(coc-diagnostic-next)

Jump to next diagnostic of any severity.

Example:

nmap <silent> ]g <Plug>(coc-diagnostic-next)

<Plug>(coc-diagnostic-prev)

<Plug>(coc-diagnostic-prev)

Jump to previous diagnostic of any severity.

Example:

nmap <silent> [g <Plug>(coc-diagnostic-prev)

<Plug>(coc-diagnostic-next-error)

<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)

<Plug>(coc-diagnostic-prev-error)

Jump to previous error diagnostic.

Example:

nmap <silent> [e <Plug>(coc-diagnostic-prev-error)

CocAction API

diagnosticInfo

CocAction('diagnosticInfo')
" Returns: void

Show diagnostic information at cursor in a float window.

Example:

nnoremap <silent> K :call CocAction('diagnosticInfo')<CR>

diagnosticNext

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')

diagnosticPrevious

CocAction('diagnosticPrevious', [severity])

Jump to previous diagnostic, optionally filtered by severity.

Parameters:

  • severity: Optional severity level

Example:

call CocAction('diagnosticPrevious')
call CocAction('diagnosticPrevious', 'warning')

diagnosticList

CocAction('diagnosticList')
" Returns: list

Get all diagnostics for all buffers.

Returns: List of diagnostic objects with properties:

  • file: File path
  • lnum: Line number (1-based)
  • col: Column number (1-based)
  • severity: Severity string
  • message: Diagnostic message
  • source: Diagnostic source

Example:

let diagnostics = CocAction('diagnosticList')
echo 'Total diagnostics: ' . len(diagnostics)

for diag in diagnostics
  echo diag.file . ':' . diag.lnum . ' [' . diag.severity . '] ' . diag.message
endfor

diagnosticToggle

CocAction('diagnosticToggle', [enable])

Toggle diagnostics display globally.

Parameters:

  • enable: Optional boolean to explicitly enable/disable

Example:

" Toggle diagnostics
call CocAction('diagnosticToggle')

" Explicitly disable
call CocAction('diagnosticToggle', v:false)

" Explicitly enable
call CocAction('diagnosticToggle', v:true)

diagnosticToggleBuffer

CocAction('diagnosticToggleBuffer', bufnr)

Toggle diagnostics for a specific buffer.

Parameters:

  • bufnr: Buffer number

Example:

" Toggle for current buffer
call CocAction('diagnosticToggleBuffer', bufnr('%'))

diagnosticPreview

CocAction('diagnosticPreview')

Preview diagnostic at cursor in a floating window with full details.

Example:

nnoremap <silent> <leader>dp :call CocAction('diagnosticPreview')<CR>

diagnosticRefresh

CocAction('diagnosticRefresh', [bufnr])

Force refresh diagnostics, optionally for a specific buffer.

Parameters:

  • bufnr: Optional buffer number

Example:

" Refresh current buffer
call CocAction('diagnosticRefresh')

" Refresh specific buffer
call CocAction('diagnosticRefresh', bufnr('%'))

Utility Functions

coc#util#diagnostic_info()

coc#util#diagnostic_info(bufnr, checkInsert)
" Returns: dictionary

Get diagnostic counts for a buffer.

Parameters:

  • bufnr: Buffer number
  • checkInsert: Check if in insert mode

Returns: Dictionary with keys:

  • error: Error count
  • warning: Warning count
  • information: Info count
  • hint: Hint count

Example:

let info = coc#util#diagnostic_info(bufnr('%'), 0)
echo 'Errors: ' . info.error . ', Warnings: ' . info.warning

coc#util#check_refresh()

coc#util#check_refresh(bufnr)
" Returns: boolean

Check if diagnostics need refresh for a buffer.

Parameters:

  • bufnr: Buffer number

Returns: 1 if refresh needed, 0 otherwise.

Buffer Variables

b:coc_diagnostic_disable

let b:coc_diagnostic_disable = 1

Disable diagnostics for the current buffer.

Type: Number Default: 0

Example:

" Disable diagnostics for log files
autocmd BufEnter *.log let b:coc_diagnostic_disable = 1

b:coc_diagnostic_info

b:coc_diagnostic_info

Read-only variable containing diagnostic counts for the buffer.

Type: Dictionary (read-only) Structure:

  • error: Number of errors
  • warning: Number of warnings
  • information: Number of info diagnostics
  • hint: Number of hints

Example:

if exists('b:coc_diagnostic_info')
  let errors = b:coc_diagnostic_info.error
  echo 'Buffer has ' . errors . ' errors'
endif

Global Variables

g:coc_status_error_sign

let g:coc_status_error_sign = 'E'

Sign text for errors in statusline.

Type: String Default: 'E'

Example:

let g:coc_status_error_sign = '✗'

g:coc_status_warning_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 Events

User CocDiagnosticChange

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

Diagnostic Signs

" Highlight groups for sign column
CocErrorSign
CocWarningSign
CocInfoSign
CocHintSign

Example:

highlight CocErrorSign ctermfg=Red guifg=#ff0000
highlight CocWarningSign ctermfg=Yellow guifg=#ffcc00
highlight CocInfoSign ctermfg=Blue guifg=#00aaff
highlight CocHintSign ctermfg=Cyan guifg=#00ffaa

Diagnostic Virtual Text

" Highlight groups for virtual text
CocErrorVirtualText
CocWarningVirtualText
CocInfoVirtualText
CocHintVirtualText

Diagnostic Highlights

" Highlight groups for code ranges
CocErrorHighlight
CocWarningHighlight
CocInfoHighlight
CocHintHighlight
CocDeprecatedHighlight
CocUnusedHighlight

Diagnostic Lines

" Highlight groups for entire lines
CocErrorLine
CocWarningLine
CocInfoLine
CocHintLine

Diagnostics in Float Windows

" Highlight groups for floating windows
CocErrorFloat
CocWarningFloat
CocInfoFloat
CocHintFloat

Configuration

Common 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
}

Usage Examples

Basic Navigation

" 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)

Diagnostic List Display

" 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

" 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

Statusline Integration

" 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()}

Auto-Open Diagnostic Float

" Show diagnostic info on cursor hold
autocmd CursorHold * silent call CocActionAsync('diagnosticInfo')

" Set update time for faster response
set updatetime=300

Filter Diagnostics by Severity

function! 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()

Diagnostic Statistics

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()

Cycle Through Severity Levels

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>

Custom Diagnostic Signs

" 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 Manually

" Refresh diagnostics for current buffer
nnoremap <silent> <leader>dr :call CocAction('diagnosticRefresh')<CR>

" Auto-refresh on save
autocmd BufWritePost * call CocAction('diagnosticRefresh')

Error Handling

Diagnostics Not Showing

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')

Language Server Not Providing Diagnostics

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)
:w

Troubleshooting

Too many diagnostic messages

Problem: Diagnostic messages are overwhelming or distracting.

Solutions:

  1. Filter by severity: nmap ]e <Plug>(coc-diagnostic-next-error) (errors only)
  2. Disable virtual text: "diagnostic.virtualText": false
  3. Increase message delay: "diagnostic.messageDelay": 500
  4. Show only on current line: "diagnostic.virtualTextCurrentLineOnly": true

Diagnostics lag or slow performance

Problem: Diagnostic updates cause editor to slow down.

Solutions:

  1. Disable in insert mode: "diagnostic.refreshOnInsertMode": false
  2. Increase refresh delay: "diagnostic.refreshAfterSave": true
  3. Disable for large files:
    autocmd BufEnter * if line('$') > 5000 | let b:coc_diagnostic_disable = 1 | endif

Diagnostic signs not visible

Problem: Sign column doesn't show diagnostic indicators.

Solutions:

  1. Enable signs: "diagnostic.enableSign": true
  2. Check sign column is visible: :set signcolumn=yes
  3. Verify highlight groups are defined:
    highlight CocErrorSign ctermfg=Red guifg=#ff0000
    highlight CocWarningSign ctermfg=Yellow guifg=#ffcc00

False positive diagnostics

Problem: Diagnostics report errors that aren't actually errors.

Solutions:

  1. Update language server: :CocUpdate
  2. Check workspace configuration: :CocLocalConfig
  3. Add to ignore patterns in language server config
  4. Restart coc.nvim: :CocRestart

Diagnostics don't update after fixing

Problem: After fixing code, diagnostics still show old errors.

Solutions:

  1. Save file: :w (many servers require save)
  2. Manual refresh: call CocAction('diagnosticRefresh')
  3. Check auto-save settings: "diagnostic.refreshAfterSave": true
  4. Restart if stuck: :CocRestart

See Also

  • Code Actions - Quick fixes for diagnostics
  • Completion - Code completion features
  • Hover and Signatures - Documentation display
  • Float Windows - Diagnostic display windows
  • Highlights - Diagnostic highlight groups