Skip to main content
Docs / TROUBLESHOOTING

Debug coc.nvim

Diagnose coc.nvim startup, extension, RPC, and editor-integration problems with logs, version checks, minimal reproduction steps, and safe evidence collection.

This page contains tips for debugging coc.nvim. If you have issues with a specific language server, see /docs/debug-language-server first.

Build source code

After cloning the repo, make sure you're using the master branch of coc.nvim, then install dependencies and build the source code:

bash snippet
1npm ci

The JavaScript bundle will exist in the build folder.

To rebuild the source code after making changes, run:

bash snippet
1npm run watch

in your project root; this uses rolldown to compile the source code into a single JavaScript bundle.

After each compile, restart the coc.nvim service with :CocRestart to use the new JavaScript code.

Restarting Vim is needed after you've made changes to coc.nvim's plugin code.

Enable source map support

To create a source map of the JavaScript bundle and compile the source code, run:

bash snippet
1NODE_ENV=development npm run build

To enable source maps in error stack traces, install source-map-support:

bash snippet
1yarn global add source-map-support

Then use a configuration like:

vim snippet
1" Use the `yarn global dir` command in your terminal to check the yarn global directory.
2let g:coc_node_args = ['-r', expand('~/.config/yarn/global/node_modules/source-map-support/register')]

in your vimrc; this makes tracing errors much easier.

Get results from console

Warning: avoid using process.stdout, process.stdin, and related console methods, because coc.nvim has to use stdio for communication between it and (neo)vim.

You can use console.error to write a string message:

js snippet
1console.error('my error')

The message will be echoed in Vim. However, this method is quite limited.

Use the logger module

Use :CocOpenLog to open the log file.

Import the logger module for logging:

js snippet
1const { createLogger } = require('./logger')
2const logger = createLogger('workspace')

Use the logger to inspect any variable, for example:

js snippet
1logger.debug('variable:', variable)

For coc.nvim extensions, use the logger object (Logger) from ExtensionContext. For example:

js snippet
1exports.activate = async (context) => {
2 let { logger } = context;
3 logger.info(`Extension from ${context.extensionPath}`)
4}

If you use console.log in an extension, the output will be appended to coc.nvim's log.

The default log level is info, so debug or trace messages won't be shown in :CocOpenLog. To change the log level, configure the NVIM_COC_LOG_LEVEL environment variable. See :h :CocOpenLog for details.

Inspect communication between vim and coc.nvim

Enable the client log by:

vim snippet
1let g:node_client_debug = 1
2let $NODE_CLIENT_LOG_FILE = '/path/to/logfile'

in your vimrc. Then open $NODE_CLIENT_LOG_FILE in another terminal, or use :call coc#client#open_log() to open the log from the current vim session.

Use a Node.js debugger

Add:

vim snippet
1let g:coc_node_args = ['--nolazy', '--inspect=6045']

to your .vimrc

After restarting coc, you will get a message like this:

text snippet
1[vim-node-coc]: Debugger listening on ws://127.0.0.1:6045/cd7eea09-c79f-4100-b4a0-bfbb43e94f48
2For help, see: https://nodejs.org/en/docs/inspector

This means the debugger protocol has started.

Open chrome://inspect in Chrome, make sure Discover network targets is checked, and then click the Configure... button:

image

Then add 127.0.0.1:6045 to the Target discovery settings.

Check the remote target section, then click inspect for the Node.js target:

image

For more details about debugging, check out Node.js debugging guide.