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.

hover-signatures.mddocs/intelligence/

Hover and Signatures [Basic]

Complexity: Basic | Category: Intelligence

Common Tasks: Show documentation | Display function signatures | View type information | Get symbol details

Display hover information, function signatures, and documentation from language servers.

Table of Contents

  • Common Tasks
  • CocAction API
  • Global Functions
  • Utility Functions
  • Global Variables
  • Configuration
  • Usage Examples
  • Error Handling
  • Troubleshooting
  • See Also

Common Tasks

Show Documentation on Hover

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

Display documentation for symbol under cursor.

Show Function Signature

inoremap <silent> <C-k> <C-r>=CocActionAsync('showSignatureHelp')<CR>

Show function signature help while typing.

Auto-Show Hover on Cursor Hold

autocmd CursorHold * silent call CocActionAsync('doHover')
set updatetime=300

Automatically display hover info when cursor stops moving.

Get Hover Data Without Display

let hover = CocAction('getHover')

Retrieve hover information programmatically.

CocAction API

doHover

CocAction('doHover')

Show hover information for symbol at cursor position in a floating window.

Example:

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

" Show on cursor hold
autocmd CursorHold * silent call CocActionAsync('doHover')
set updatetime=300

definitionHover

CocAction('definitionHover')

Show hover information for the definition of the symbol at cursor.

Example:

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

showSignatureHelp

CocAction('showSignatureHelp')

Show function signature help for the function being called.

Example:

nnoremap <silent> <C-k> :call CocAction('showSignatureHelp')<CR>

" Show signature help in insert mode
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')

getHover

CocAction('getHover')
" Returns: list

Get hover information without displaying it.

Returns: List of hover content strings.

Example:

let hover = CocAction('getHover')
if len(hover) > 0
  echo join(hover, "\n")
endif

Global Functions

CocHasProvider()

CocHasProvider(feature)
" Returns: boolean

Check if a language server provides a specific feature.

Parameters:

  • feature: Feature name (e.g., 'hover', 'signature', 'rename', 'format')

Returns: 1 if provider exists, 0 otherwise.

Example:

if CocHasProvider('hover')
  nnoremap <silent> K :call CocAction('doHover')<CR>
else
  nnoremap <silent> K :normal! K<CR>
endif

Utility Functions

coc#ui#echo_hover()

coc#ui#echo_hover(msg)

Echo hover message in command line.

Parameters:

  • msg: Message string to display

Example:

call coc#ui#echo_hover('Documentation text here')

coc#ui#echo_signatures()

coc#ui#echo_signatures(signatures)

Echo signature help in command line.

Parameters:

  • signatures: Signature help data

Example:

let sigs = CocAction('getSignatureHelp')
call coc#ui#echo_signatures(sigs)

coc#ui#preview_info()

coc#ui#preview_info(lines, filetype, [bufnr])

Show information in preview window.

Parameters:

  • lines: List of lines to display
  • filetype: Filetype for syntax highlighting
  • bufnr: Optional buffer number

Example:

call coc#ui#preview_info(['line 1', 'line 2'], 'markdown')

Global Variables

g:coc_last_hover_message

g:coc_last_hover_message

Runtime variable containing the last hover message displayed.

Type: String (read-only)

Example:

if exists('g:coc_last_hover_message')
  echo g:coc_last_hover_message
endif

Configuration

Hover and signature settings in coc-settings.json:

{
  "hover.enable": true,
  "hover.target": "float",
  "hover.floatConfig": {
    "border": true,
    "rounded": true,
    "maxWidth": 80,
    "maxHeight": 20
  },
  "signature.enable": true,
  "signature.target": "float",
  "signature.floatConfig": {
    "border": true
  },
  "signature.preferShownAbove": true,
  "signature.hideOnTextChange": false
}

Usage Examples

Basic Hover Setup

" Show hover on K
nnoremap <silent> K :call CocAction('doHover')<CR>

" Show signature help
inoremap <silent> <C-k> <C-r>=CocActionAsync('showSignatureHelp')<CR>

Smart Hover Function

function! ShowDocumentation() abort
  if CocAction('hasProvider', 'hover')
    call CocActionAsync('doHover')
  else
    " Fallback to vim's built-in help
    execute '!' . &keywordprg . " " . expand('<cword>')
  endif
endfunction

nnoremap <silent> K :call ShowDocumentation()<CR>

Auto-Show Hover

" Show hover on cursor hold
set updatetime=300

function! s:show_hover_auto() abort
  if CocAction('hasProvider', 'hover')
    call CocActionAsync('doHover')
  endif
endfunction

autocmd CursorHold * silent call s:show_hover_auto()

" Don't show in certain filetypes
autocmd FileType qf,help,fugitive autocmd! CursorHold

Signature Help in Insert Mode

" Auto-show signature help when typing
function! s:trigger_signature() abort
  if CocAction('hasProvider', 'signature')
    call CocActionAsync('showSignatureHelp')
  endif
endfunction

" Show after typing (
autocmd InsertCharPre * if v:char ==# '(' | call timer_start(100, {-> s:trigger_signature()}) | endif

" Show on demand
inoremap <silent><expr> <C-s> CocActionAsync('showSignatureHelp')

Get and Display Hover

function! DisplayHoverInfo() abort
  let hover = CocAction('getHover')

  if len(hover) == 0
    echo "No hover information available"
    return
  endif

  " Display in custom way
  echo "=== Hover Information ==="
  for line in hover
    echo line
  endfor
endfunction

nnoremap <silent> <leader>h :call DisplayHoverInfo()<CR>

Hover in Preview Window

function! HoverInPreview() abort
  let hover = CocAction('getHover')

  if len(hover) == 0
    echo "No documentation available"
    return
  endif

  " Show in preview window
  call coc#ui#preview_info(hover, 'markdown')
endfunction

nnoremap <silent> <leader>hp :call HoverInPreview()<CR>

Double-Tap Hover

" First tap shows hover, second tap jumps to definition
let g:last_hover_time = 0

function! SmartHover() abort
  let current_time = localtime()
  let time_diff = current_time - g:last_hover_time

  if time_diff < 1
    " Double tap - jump to definition
    call CocAction('jumpDefinition')
    let g:last_hover_time = 0
  else
    " Single tap - show hover
    call CocAction('doHover')
    let g:last_hover_time = current_time
  endif
endfunction

nnoremap <silent> K :call SmartHover()<CR>

Hover with Timeout

function! HoverWithTimeout(timeout) abort
  " Show hover for specific duration
  call CocAction('doHover')

  " Close after timeout
  call timer_start(a:timeout, {-> execute('call coc#float#close_all()')})
endfunction

nnoremap <silent> <leader>ht :call HoverWithTimeout(3000)<CR>

Save Hover to Register

function! YankHover() abort
  let hover = CocAction('getHover')

  if len(hover) == 0
    echo "No hover information"
    return
  endif

  " Join and yank to clipboard
  let text = join(hover, "\n")
  let @+ = text
  let @" = text
  echo "Hover information yanked"
endfunction

nnoremap <silent> <leader>yh :call YankHover()<CR>

Hover History

let g:hover_history = []

function! HoverWithHistory() abort
  let hover = CocAction('getHover')

  if len(hover) > 0
    call add(g:hover_history, {
      \ 'file': expand('%:p'),
      \ 'line': line('.'),
      \ 'content': hover
      \ })
  endif

  call CocAction('doHover')
endfunction

function! ShowHoverHistory() abort
  if len(g:hover_history) == 0
    echo "No hover history"
    return
  endif

  for i in range(len(g:hover_history))
    let entry = g:hover_history[i]
    echo (i + 1) . '. ' . entry.file . ':' . entry.line
  endfor
endfunction

nnoremap <silent> K :call HoverWithHistory()<CR>
nnoremap <silent> <leader>hh :call ShowHoverHistory()<CR>

Signature Help with Parameter Highlighting

function! SmartSignatureHelp() abort
  if !CocAction('hasProvider', 'signature')
    return
  endif

  call CocActionAsync('showSignatureHelp')
endfunction

" Trigger on function call
autocmd User CocJumpPlaceholder call SmartSignatureHelp()

" Trigger in insert mode
inoremap <silent> <C-h> <C-r>=SmartSignatureHelp()<CR>

Conditional Hover Display

function! ConditionalHover() abort
  " Only show hover for specific filetypes
  let allowed_fts = ['javascript', 'typescript', 'python', 'rust', 'go']

  if index(allowed_fts, &filetype) < 0
    echo "Hover disabled for " . &filetype
    return
  endif

  call CocAction('doHover')
endfunction

nnoremap <silent> K :call ConditionalHover()<CR>

Hover in Statusline

function! HoverStatusline() abort
  if !exists('g:coc_last_hover_message')
    return ''
  endif

  " Truncate to fit statusline
  let msg = g:coc_last_hover_message
  let max_len = 50

  if len(msg) > max_len
    return msg[:max_len - 4] . '...'
  endif

  return msg
endfunction

set statusline+=%{HoverStatusline()}

Multi-Provider Hover

function! MultiHover() abort
  " Try hover first
  if CocAction('hasProvider', 'hover')
    call CocAction('doHover')
    return
  endif

  " Try definition hover
  if CocAction('hasProvider', 'definition')
    call CocAction('definitionHover')
    return
  endif

  " Fallback
  echo "No hover information available"
endfunction

nnoremap <silent> K :call MultiHover()<CR>

Hover with Syntax Highlighting

function! HoverWithSyntax() abort
  let hover = CocAction('getHover')

  if len(hover) == 0
    return
  endif

  " Detect code blocks and apply syntax
  let lines = []
  let in_code = 0
  let lang = ''

  for line in hover
    if line =~# '^```'
      let in_code = !in_code
      if in_code
        let lang = matchstr(line, '^```\zs\w\+')
      endif
    else
      call add(lines, line)
    endif
  endfor

  call coc#ui#preview_info(lines, lang)
endfunction

nnoremap <silent> <leader>hs :call HoverWithSyntax()<CR>

Error Handling

No Hover Information

Problem: Hover command shows no documentation.

Solutions:

" Check if hover provider exists
if CocHasProvider('hover')
  echo "Hover supported"
else
  echo "No hover provider for " . &filetype
endif

" Verify language server is running
:CocInfo

" Check cursor is on valid symbol
echo expand('<cword>')

" Try definition hover instead
call CocAction('definitionHover')

Signature Help Not Showing

Problem: Signature help doesn't appear when calling functions.

Solutions:

" Check signature provider
if CocHasProvider('signature')
  echo "Signature help supported"
endif

" Manually trigger
call CocAction('showSignatureHelp')

" Verify in correct context (inside function call)
" Check language server output
:CocCommand workspace.showOutput

Hover Window Closes Immediately

Problem: Hover float window disappears too quickly.

Solutions:

" Increase hover delay in settings
{
  "hover.autoHide": false
}

" Disable auto-hide
{
  "hover.floatConfig": {
    "focusable": true
  }
}

" Keep window open with custom timeout
function! HoverWithTimeout(ms)
  call CocAction('doHover')
  call timer_start(a:ms, {-> execute('call coc#float#close_all()')})
endfunction

Troubleshooting

Hover shows incorrect information

Problem: Documentation doesn't match the actual symbol.

Solutions:

  1. Ensure cursor is positioned correctly on symbol
  2. Update language server: :CocUpdate
  3. Restart language server: :CocRestart
  4. Check for multiple definitions: :CocList symbols
  5. Verify workspace is correctly configured

Signature help shows wrong parameters

Problem: Parameter hints don't match function signature.

Solutions:

  1. Verify cursor is inside function call parentheses
  2. Check if overloaded function (multiple signatures)
  3. Update language server for better signature detection
  4. Manually check documentation: K on function name

Hover window appears in wrong position

Problem: Float window is positioned awkwardly or off-screen.

Solutions:

" Configure float window position
{
  "hover.floatConfig": {
    "preferTop": true,
    "maxWidth": 80,
    "maxHeight": 20
  }
}

" Adjust based on screen size
{
  "hover.floatConfig": {
    "border": true,
    "rounded": true
  }
}

Too many hover windows stacking

Problem: Multiple hover windows appear simultaneously.

Solutions:

  1. Close previous windows before opening new ones:
    autocmd CursorMoved * call coc#float#close_all()
  2. Disable auto-hover:
    autocmd! CursorHold
  3. Use single hover mapping instead of auto-show

Hover content is truncated

Problem: Documentation is cut off or incomplete.

Solutions:

" Increase window size limits
{
  "hover.floatConfig": {
    "maxWidth": 120,
    "maxHeight": 40
  }
}

" Use preview window for long content
function! HoverInPreview()
  let hover = CocAction('getHover')
  call coc#ui#preview_info(hover, 'markdown')
endfunction

" Scroll in hover window
" Use <C-f> and <C-b> if focusable

Hover not working in specific filetypes

Problem: Hover works in some languages but not others.

Solutions:

  1. Check language server is installed: :CocList extensions
  2. Verify LSP is attached: :CocCommand workspace.showOutput
  3. Install appropriate language server extension
  4. Check file type: :set filetype?
  5. Review language server configuration: :CocConfig

See Also

  • Completion - Code completion with documentation
  • Diagnostics - Error and warning information
  • Code Navigation - Jump to definitions
  • Float Windows - Float window configuration
  • Configuration - Hover and signature settings