Skip to content

Debug language server

Qiming zhao edited this page Sep 15, 2020 · 22 revisions

Contents

Checkout server stats

Use command :CocList services to open services list, you will have id state and filetypes for each service.

Screen Shot 2020-04-15 at 4 45 00 PM

If service id starts with languageserver, it comes from languageserver configuration in coc-settings.json, if not, it's from extension of coc.nvim.

The service could not start when buffer's filetype not match, use :CocCommand document.echoFileType to get filetype of current buffer used by coc.nvim.

Using output channel

The same as VSCode, each language server has it's own output channel, the output channel can be opened by

:CocCommand workspace.showOutput

To make an output channel track all LSP communication, set [languageserverId].trace.server to verbose in your coc-settings.json.

For example, to make tsserver track LSP communication, use:

  "tsserver.trace.server": "verbose",

to make a custom language server track LSP communication, add a trace.server section in your language server configuration, like:

"languageserver":{
   "ccls": {
    "command": "ccls",
    "filetypes": ["c", "cpp", "objc", "objcpp"],
    "trace.server": "verbose",
    "initializationOptions": {
      "cacheDirectory": "/tmp/ccls"
    }
  }
}

However, the output of LSP communication is difficult for humans to read. You can upload the content to the LSP inspector: https://microsoft.github.io/language-server-protocol/inspector/, which looks like this:

screen shot 2018-07-20 at 12 15 10 pm

Using Chrome developer tools

You can use Chrome to debug a language server which is using node IPC for communication.

First, add execArgv to the language server settings like:

 "css.execArgv": ["--nolazy", "--inspect-brk=6045"]

After the css service starts, open Chrome with the url chrome://inspect

Make sure the Discover network targets option is checked and you have the address added to Target discovery settings, and then you will have the debugging target.

REPL

Clone this wiki locally