Core service lifecycle management for coc.nvim including starting, stopping, restarting the Node.js service, and checking service status. The service manages LSP connections, extensions, and all background processing.
Start, stop, restart, and control the coc.nvim background service that handles LSP communication and extension management.
:CocStart " Start the coc.nvim service
:CocRestart " Restart the coc.nvim service
:CocDisable " Disable coc event handling
:CocEnable " Re-enable coc event handling
:CocInfo " Show service information and logs
:CocOpenLog " Open coc.nvim log file
:CocOutline " Show document outline
:CocSearch [{options}] {pattern} " Search text across workspaceUsage Examples:
" Start service manually if not auto-started
:CocStart
" Restart service after configuration changes
:CocRestart
" Temporarily disable coc for performance
:CocDisable
" Re-enable when needed
:CocEnable
" Check service status and version info
:CocInfoCheck service status and execute actions conditionally based on service availability.
CocAction({action} [, ...args])
" Execute synchronous action
" Throws error if service not ready
" Returns: action result or error
CocActionAsync({action} [, ...args] [, {callback}])
" Execute asynchronous action
" Parameters:
" {action} - string: action name
" [...args] - any[]: action arguments
" {callback} - function: optional callback
" Returns: empty string or calls callback
CocHasProvider({feature})
" Check if LSP provider exists for feature
" Parameters:
" {feature} - string: provider name
" Returns: booleanUsage Examples:
" Check if completion provider is available
if CocHasProvider('completion')
echo "Completion available"
endif
" Execute action synchronously
let result = CocAction('extensionStats')
" Execute action asynchronously with callback
function! MyCallback(error, result)
if a:error
echo "Error: " . a:error
else
echo "Result: " . string(a:result)
endif
endfunction
call CocActionAsync('workspaceSymbols', '', function('MyCallback'))Direct communication with language servers for advanced use cases and custom integrations.
CocRequest(...)
" Send synchronous LSP request to any language server
" Parameters: variable arguments passed to LSP method
" Returns: LSP response or error
CocRequestAsync(...)
" Send asynchronous LSP request to any language server
" Parameters: variable arguments, optional callback as last argument
" Returns: empty string or calls callback
CocNotify(...)
" Send LSP notification to any language server
" Parameters: variable arguments passed to LSP method
" Returns: void
CocRegistNotification({id}, {method}, {callback})
" Register callback for LSP notifications
" Parameters:
" {id} - string: unique callback id
" {method} - string: LSP notification method
" {callback} - function: notification handler
" Returns: voidUsage Examples:
" Request hover information
let hover = CocRequest('typescript', 'textDocument/hover', {
\ 'textDocument': {'uri': 'file:///path/to/file.ts'},
\ 'position': {'line': 10, 'character': 5}
\ })
" Send workspace configuration notification
call CocNotify('typescript', 'workspace/didChangeConfiguration', {
\ 'settings': {'typescript': {'preferences': {'includeCompletionsForModuleExports': v:true}}}
\ })
" Register for diagnostic notifications
function! DiagnosticHandler(method, params)
echo "Diagnostics updated: " . len(a:params.diagnostics) . " issues"
endfunction
call CocRegistNotification('diagnostic-handler', 'textDocument/publishDiagnostics',
\ function('DiagnosticHandler'))Global variables controlling service behavior and initialization.
g:coc_start_at_startup
" Start service at Vim startup
" Type: Number (0 or 1)
" Default: 1
g:coc_enabled
" Enable/disable coc functionality
" Type: Number (0 or 1)
" Default: 1
g:coc_service_initialized
" Service initialization status (read-only)
" Type: Number (0 or 1)
g:coc_disable_startup_warning
" Disable startup version warnings
" Type: Number (0 or 1)
" Default: 0
g:coc_node_path
" Path to Node.js executable
" Type: String
" Default: 'node' or $COC_NODE_PATHUsage Examples:
" Disable auto-start for manual control
let g:coc_start_at_startup = 0
" Check if service is ready before calling functions
if get(g:, 'coc_service_initialized', 0)
call CocAction('runCommand', 'myextension.customCommand')
endif
" Use custom Node.js path
let g:coc_node_path = '/usr/local/bin/node'
" Disable startup warnings in headless environments
let g:coc_disable_startup_warning = 1Diagnostic functions for troubleshooting service issues and checking system requirements.
" Built-in health check
:checkhealth coc " Run comprehensive health check (Neovim)
" Status checking functions
coc#rpc#ready() " Check if RPC connection ready
coc#rpc#started() " Check if service process started
coc#util#version() " Get coc.nvim version
" Command registration
coc#add_command({id}, {cmd} [, {title}])
" Add vim command to CocCommand list
" Parameters:
" {id} - string: command identifier
" {cmd} - string: vim command to execute
" {title} - string: optional display title
" Returns: voidUsage Examples:
" Check service readiness before operations
if coc#rpc#ready()
call CocAction('doHover')
else
echo "coc.nvim service not ready"
endif
" Version information for bug reports
echo "coc.nvim version: " . coc#util#version()
" Comprehensive health check (Neovim only)
:checkhealth coc