Coc.nvim: CocAction('codeLens') => Source id of codelens not found

Created on 24 Nov 2018  ·  3Comments  ·  Source: neoclide/coc.nvim

Describe the bug
:call CocAction('codeLens') displays an error message [coc.nvim] Source id of codelens not found"

To Reproduce
~/.config/nvim/coc-settings.json:

{
  "languageserver": {
    "ccls": {
      "command": "ccls",
      "filetypes": ["c", "cpp", "objc", "objcpp"]
    }
  }
}
  1. cd /tmp/d; git init
  2. echo 'int a;' > a.cc
  3. nvim a.cc
  4. Execute :call CocAction('codeLens')

Expected behavior
textDocument/codeLen result is rendered somewhere

Additional context

sysdig -As9999 --unbuffered -p '%evt.buffer' "proc.exe contains ccls and fd.type=unix":

Content-Length: 113

{"jsonrpc":"2.0","id":16,"method":"textDocument/codeLens","params":{"textDocument":{"uri":"file:///tmp/d/a.cc"}}}

Content-Length: 239

{"jsonrpc":"2.0","id":16,"result":[{"range":{"start":{"line":0,"character":4},"end":{"line":0,"character":5}},"command":{"title":"0 ref","command":"ccls.xref","arguments":["{\"usr\":16721564935990383768,\"kind\":4,\"field\":\"uses\"}"]}}]}

Note it encodes a JSON string as the only element of "arguments" (to make VSCode happy):

"arguments":["{\"usr\":16721564935990383768,\"kind\":4,\"field\":\"uses\"}"]

/tmp/coc-nvim.log log entry:

2018-11-23T21:19:51.601 ERROR (pid:17076) [codelens] - Cannot read property 'command' of null
bug

Most helpful comment

Coc will use set_virtual_text of neovim for codeLenes feature.

All 3 comments

The command not exists, an extension could help to regist custom command.

Does it make sense to postpone the error reporting to when the user actually clicks the button (tricks the command)?

My supposed interaction is:

  • User invokes textDocument/codeLens
  • Server returns:
{"jsonrpc":"2.0","id":16,"result":[{"range":{"start":{"line":0,"character":4},"end":{"line":0,"character":5}},"command":{"title":"0 ref","command":"ccls.xref","arguments":["{\"usr\":16721564935990383768,\"kind\":4,\"field\":\"uses\"}"]}}]}
  • range and command.title are rendered even if the server does not know the actual command. In this particular case, "title": "0 ref" means the declaration has 0 references. The title is more important than whether the command is rendered as a clickable button.
  • User clicks the 0 refs button (code lens). As there is no extension to handle the command ccls.xref, coc.nvim can bail out and print an error message in this step, instead of sending
{"title":"0 ref","command":"ccls.xref","arguments":["{\"usr\":16721564935990383768,\"kind\":4,\"field\":\"uses\"}"]}

Here is how CodeLens is rendered in vscode-ccls. These "* refs" are clickable buttons, but whether they are clickable does not matter too much. coc.nvim can print an error message as the command is not supported by an extension.

I feel it is distracting as it takes too much vertical space. emacs-ccls puts all lenses at the line end by default.

Coc will use set_virtual_text of neovim for codeLenes feature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MacGuffinLife picture MacGuffinLife  ·  4Comments

FrankLA0203 picture FrankLA0203  ·  3Comments

cvlmtg picture cvlmtg  ·  3Comments

npearson72 picture npearson72  ·  3Comments

lanox picture lanox  ·  3Comments