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.

service-management.mddocs/core/

Service Management [Basic]

Complexity: Basic | Category: Core

Common Tasks: Start service | Restart service | Check status | View logs

Management of the coc.nvim service lifecycle including starting, stopping, restarting, viewing logs, and checking service status.

Table of Contents

  • Common Tasks
  • Commands
  • RPC Functions
  • Client Management
  • CocAction API
  • Global Variables
  • Utility Functions
  • Autocmd Events
  • Examples
  • Error Handling
  • Troubleshooting
  • Performance Notes
  • See Also

Common Tasks

Start Service

:CocStart

Manually start the coc.nvim service.

Restart Service

:CocRestart

Restart the service to resolve issues or apply changes.

Check Service Status

if coc#rpc#ready()
  echo "Service is ready"
endif

Check if service is ready to accept requests.

View Service Info

:CocInfo

Display version, platform, extensions, and status information.

Open Log File

:CocOpenLog

View detailed service logs for debugging.

Commands

:CocStart

:CocStart

Start the coc.nvim service. The service is automatically started when Vim loads if g:coc_start_at_startup is enabled (default: 1). Use this command to manually start the service if it was stopped or if auto-start is disabled.

Example:

:CocStart

" Map to key
nnoremap <silent> <leader>cs :CocStart<CR>

:CocRestart

:CocRestart

Restart the coc.nvim service. This stops the current Node.js process and starts a new one. Useful when extensions are misbehaving or after updating coc.nvim itself.

Example:

:CocRestart

" Quick restart mapping
nmap <silent> <leader>cr :CocRestart<CR>

:CocDisable

:CocDisable

Temporarily disable coc.nvim for the current Vim session. This stops the service and prevents it from running until :CocEnable is called.

Example:

:CocDisable

" Disable for large files
autocmd BufReadPre * if getfsize(expand('%')) > 1000000 | CocDisable | endif

:CocEnable

:CocEnable

Re-enable coc.nvim after it has been disabled with :CocDisable.

Example:

:CocEnable

:CocInfo

:CocInfo

Display diagnostic information about the coc.nvim service including:

  • Version information
  • Platform details
  • Node.js version and path
  • Loaded extensions
  • Active language servers
  • Configuration paths
  • Service status and errors

Example:

:CocInfo

" Map to key
nnoremap <silent> <leader>ci :CocInfo<CR>

:CocOpenLog

:CocOpenLog

Open the coc.nvim log file in a new buffer. The log contains detailed information about service operations, extension loading, LSP communication, and errors.

Example:

:CocOpenLog

" Quick access to logs
nnoremap <silent> <leader>cl :CocOpenLog<CR>

RPC Functions

coc#rpc#start_server()

coc#rpc#start_server()

Start the coc.nvim RPC server. This is called internally by :CocStart.

Example:

call coc#rpc#start_server()

coc#rpc#started()

coc#rpc#started()
" Returns: boolean

Check if the RPC server has been started (process spawned).

Returns: 1 if started, 0 otherwise.

Example:

if coc#rpc#started()
  echo "RPC server is running"
endif

coc#rpc#ready()

coc#rpc#ready()
" Returns: boolean

Check if the RPC server is ready to accept requests (initialized and connected).

Returns: 1 if ready, 0 otherwise.

Example:

if coc#rpc#ready()
  echo "Service is ready"
else
  echo "Service not ready, starting..."
  CocStart
endif

coc#rpc#stop()

coc#rpc#stop()

Stop the RPC server gracefully.

Example:

call coc#rpc#stop()

coc#rpc#restart()

coc#rpc#restart()

Restart the RPC server. Equivalent to calling coc#rpc#stop() followed by coc#rpc#start_server().

Example:

call coc#rpc#restart()

coc#rpc#kill()

coc#rpc#kill()

Forcefully kill the RPC process. Use this if the service is unresponsive and :CocRestart doesn't work.

Example:

" Force kill if hung
call coc#rpc#kill()

coc#rpc#get_errors()

coc#rpc#get_errors()
" Returns: list

Get a list of RPC errors that have occurred.

Returns: List of error messages.

Example:

let errors = coc#rpc#get_errors()
if len(errors) > 0
  echo "Errors detected:"
  for err in errors
    echo err
  endfor
endif

coc#rpc#set_channel()

coc#rpc#set_channel(chan_id)

Set the RPC channel ID. This is used internally for communication.

Parameters:

  • chan_id: Channel identifier

Client Management

coc#client#open_log()

coc#client#open_log()

Open the coc.nvim debug log file. Equivalent to :CocOpenLog.

Example:

call coc#client#open_log()

coc#client#is_running()

coc#client#is_running(name)
" Returns: boolean

Check if a specific language client is running.

Parameters:

  • name: Name of the language client

Returns: 1 if running, 0 otherwise.

Example:

if coc#client#is_running('tsserver')
  echo "TypeScript server is running"
endif

coc#client#stop()

coc#client#stop(name)
" Returns: boolean

Stop a specific language client.

Parameters:

  • name: Name of the language client to stop

Returns: 1 if successfully stopped, 0 otherwise.

Example:

call coc#client#stop('tsserver')

coc#client#restart()

coc#client#restart(name)

Restart a specific language client.

Parameters:

  • name: Name of the language client to restart

Example:

call coc#client#restart('tsserver')

coc#client#restart_all()

coc#client#restart_all()

Restart all language clients.

Example:

call coc#client#restart_all()

CocAction API

services

CocAction('services')
" Returns: list

Get a list of all language services with their status.

Returns: List of service objects containing name, state, and other metadata.

Example:

let services = CocAction('services')
for service in services
  echo service.id . ': ' . service.state
endfor

toggleService

CocAction('toggleService', name)

Toggle a language service on or off.

Parameters:

  • name: Service name to toggle

Example:

call CocAction('toggleService', 'tsserver')

Global Variables

g:coc_start_at_startup

let g:coc_start_at_startup = 1

Control whether coc.nvim starts automatically when Vim loads.

Type: Number Default: 1 Values:

  • 1: Auto-start enabled
  • 0: Auto-start disabled

Example:

" Disable auto-start
let g:coc_start_at_startup = 0

" Start only for specific filetypes
autocmd FileType javascript,typescript,python CocStart

g:coc_node_path

let g:coc_node_path = '/path/to/node'

Path to the Node.js executable. Coc.nvim will use this path instead of searching PATH.

Type: String Default: 'node'

Example:

" Use a specific Node.js version
let g:coc_node_path = '/usr/local/bin/node'

" Use version manager path
let g:coc_node_path = expand('~/.nvm/versions/node/v16.14.0/bin/node')

g:coc_node_args

let g:coc_node_args = ['--max-old-space-size=4096']

Additional arguments to pass to the Node.js process.

Type: List Default: []

Example:

" Increase memory limit for large projects
let g:coc_node_args = ['--max-old-space-size=8192']

" Enable Node.js debugging
let g:coc_node_args = ['--inspect=9229']

g:node_client_debug

let g:node_client_debug = 1

Enable debug mode for the Node.js client. This increases log verbosity.

Type: Number Default: 0 Values:

  • 1: Debug enabled
  • 0: Debug disabled

Example:

" Enable debug logging
let g:node_client_debug = 1

g:coc_service_initialized

g:coc_service_initialized

Runtime variable that is set to 1 when the coc.nvim service has fully initialized.

Type: Number (read-only)

Example:

if exists('g:coc_service_initialized') && g:coc_service_initialized
  echo "Coc service is ready"
endif

g:coc_process_pid

g:coc_process_pid

Process ID of the coc.nvim Node.js service.

Type: Number (read-only)

Example:

if exists('g:coc_process_pid')
  echo "Coc process ID: " . g:coc_process_pid
endif

Utility Functions

coc#status()

coc#status()
" Returns: string

Get formatted status information for use in the Vim statusline. Returns diagnostic information including error and warning counts from the current buffer.

Returns: String containing formatted status (e.g., "E 2 W 1 ") or empty string if no diagnostics.

Configuration:

  • g:coc_status_error_sign - Custom error sign (default: "E ")
  • g:coc_status_warning_sign - Custom warning sign (default: "W ")
  • g:coc_status - Additional custom status text

Example:

" Add coc status to statusline
set statusline=%{coc#status()}%{get(b:,'coc_current_function','')}

" Customize status signs
let g:coc_status_error_sign = '✗ '
let g:coc_status_warning_sign = '⚠ '

" Lightline integration
let g:lightline = {
  \ 'active': {
  \   'right': [['coc_status'], ['lineinfo']]
  \ },
  \ 'component_function': {
  \   'coc_status': 'coc#status'
  \ }
  \ }

coc#util#api_version()

coc#util#api_version()
" Returns: number

Get the coc.nvim API version.

Returns: API version number.

Example:

let api_ver = coc#util#api_version()
echo 'Coc API version: ' . api_ver

coc#util#version()

coc#util#version()
" Returns: string

Get the coc.nvim version string.

Returns: Version string (e.g., "0.0.82").

Example:

let version = coc#util#version()
echo 'Coc version: ' . version

Autocmd Events

User CocNvimInit

autocmd User CocNvimInit {command}

Triggered when coc.nvim has finished initializing. Use this to run commands that depend on coc.nvim being ready.

Example:

autocmd User CocNvimInit call s:CocInitialized()

function! s:CocInitialized() abort
  echo "Coc initialized with version: " . coc#util#version()

  " Setup statusline
  set statusline=%{coc#status()}

  " Configure extensions
  let services = CocAction('services')
  echo "Loaded " . len(services) . " services"
endfunction

Examples

Basic Service Management

" Check if service is running
if coc#rpc#ready()
  echo "Coc service is ready"
else
  " Start the service
  CocStart
endif

" Restart when needed
nmap <silent> <leader>cr :CocRestart<CR>

Debug Service Issues

" View service information
:CocInfo

" Open log file
:CocOpenLog

" Check for errors
let errors = coc#rpc#get_errors()
if len(errors) > 0
  echo "Service errors detected:"
  for err in errors
    echo err
  endfor
endif

Custom Initialization

" Wait for coc to initialize before running commands
autocmd User CocNvimInit call s:CocInitialized()

function! s:CocInitialized() abort
  " Your initialization code here
  echo "Coc initialized with version: " . coc#util#version()

  " Load extensions
  let services = CocAction('services')
  echo "Loaded " . len(services) . " services"
endfunction

Conditional Auto-Start

" Disable auto-start
let g:coc_start_at_startup = 0

" Start only for specific filetypes
autocmd FileType javascript,typescript,python CocStart

Service Health Check

function! CheckCocHealth() abort
  if !coc#rpc#ready()
    echohl WarningMsg
    echo "Coc service is not ready"
    echohl None
    return
  endif

  let services = CocAction('services')
  let active = 0
  for service in services
    if service.state == 'running'
      let active += 1
    endif
  endfor

  echo "Coc version: " . coc#util#version()
  echo "Active services: " . active . "/" . len(services)
endfunction

command! CocHealth call CheckCocHealth()

Disable for Large Files

" Disable coc for files larger than 1MB
function! s:DisableForLargeFile() abort
  let size = getfsize(expand('%'))
  if size > 1000000 || size == -2
    silent! CocDisable
    echo "Coc disabled for large file"
  endif
endfunction

autocmd BufReadPre * call s:DisableForLargeFile()

Service Toggle

function! ToggleCocService() abort
  if coc#rpc#ready()
    CocDisable
    echo "Coc service disabled"
  else
    CocEnable
    echo "Coc service enabled"
  endif
endfunction

nnoremap <silent> <leader>ct :call ToggleCocService()<CR>

Monitor Service Status

function! MonitorCocService() abort
  let status = {
    \ 'version': coc#util#version(),
    \ 'started': coc#rpc#started(),
    \ 'ready': coc#rpc#ready(),
    \ 'errors': len(coc#rpc#get_errors())
    \ }

  if exists('g:coc_process_pid')
    let status.pid = g:coc_process_pid
  endif

  echo 'Coc Status:'
  for [key, val] in items(status)
    echo '  ' . key . ': ' . string(val)
  endfor
endfunction

command! CocStatus call MonitorCocService()

Error Handling

Service Won't Start

If the service fails to start, check:

" Check Node.js availability
:!node --version

" Check for errors
let errors = coc#rpc#get_errors()
for err in errors
  echo err
endfor

" View logs
:CocOpenLog

Service Crashes

If the service crashes frequently:

" Increase Node.js memory
let g:coc_node_args = ['--max-old-space-size=8192']

" Enable debug logging
let g:node_client_debug = 1

" Restart to apply changes
:CocRestart

Unresponsive Service

If the service becomes unresponsive:

" Force kill the process
call coc#rpc#kill()

" Start fresh
:CocStart

" Or use restart
:CocRestart

Troubleshooting

Service Not Starting Automatically

Problem: Coc doesn't start when Vim opens.

Solutions:

  1. Check auto-start setting: echo g:coc_start_at_startup
  2. Enable auto-start: let g:coc_start_at_startup = 1
  3. Check for errors in :CocInfo
  4. View logs: :CocOpenLog
  5. Verify Node.js installation: :!node --version

Service Keeps Restarting

Problem: Service repeatedly crashes and restarts.

Solutions:

  1. Check logs for errors: :CocOpenLog
  2. Update coc.nvim: :CocUpdate
  3. Rebuild extensions: :CocRebuild
  4. Increase memory: let g:coc_node_args = ['--max-old-space-size=8192']
  5. Disable problematic extensions

Commands Not Working

Problem: Coc commands don't execute or show "Not an editor command".

Solutions:

  1. Check if service is ready: if coc#rpc#ready() | echo "Ready" | endif
  2. Start service manually: :CocStart
  3. Verify coc.nvim is installed correctly
  4. Check for plugin conflicts

High Memory Usage

Problem: Coc service uses excessive memory.

Solutions:

  1. Limit memory: let g:coc_node_args = ['--max-old-space-size=4096']
  2. Disable unused extensions
  3. Restart service periodically: :CocRestart
  4. Check for memory leaks in logs

Wrong Node.js Version

Problem: Coc uses incorrect Node.js version.

Solutions:

  1. Specify path: let g:coc_node_path = '/path/to/correct/node'
  2. Verify path: echo g:coc_node_path
  3. Test version: :!node --version
  4. Restart after setting: :CocRestart

Performance Notes

  • Startup Time: Disable auto-start and manually start for specific filetypes to reduce startup time
  • Memory Usage: Set g:coc_node_args with --max-old-space-size to limit memory consumption
  • Large Files: Consider disabling coc for files over 1MB using b:coc_enabled = 0
  • Service Restarts: Avoid frequent restarts as they interrupt LSP communication and lose context

See Also

  • Configuration - Configure service behavior and settings
  • Extensions - Manage extensions that run in the service
  • Diagnostics - View diagnostic information in statusline
  • Variables - All service-related variables
  • Autocmd Events - Integration with Vim events