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.

coc.nvim project documentation · Content sources and maintainers

Edit this page

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 repository, switch to the master branch of coc.nvim, then install the dependencies and build the source code:

bash snippet
1npm ci

The build creates a JavaScript bundle in the build folder.

To rebuild the source code after making changes, run the following command from the project root:

bash snippet
1npm run watch

This uses rolldown to compile the source code into a single JavaScript bundle.

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

Restart Vim after changing 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 add a configuration like this to your vimrc:

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

This makes tracing errors easier.

Get results from console

Warning: Avoid using process.stdout, process.stdin, and related console methods because coc.nvim uses stdio to communicate with Vim or Neovim.

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

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

Vim echoes the message, but this method is 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

To enable the client log, add the following to your vimrc:

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

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

Use a Node.js debugger

Add the following to your .vimrc:

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

After restarting coc.nvim, you should see 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 indicates that the debugger is listening.

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, see the Node.js debugging guide.