Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CocAction('codeLens') => Source id of codelens not found #174

Closed
MaskRay opened this issue Nov 24, 2018 · 3 comments
Closed

CocAction('codeLens') => Source id of codelens not found #174

MaskRay opened this issue Nov 24, 2018 · 3 comments
Labels
bug Something isn't working

Comments

@MaskRay
Copy link

MaskRay commented Nov 24, 2018

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
@chemzqm
Copy link
Member

chemzqm commented Nov 24, 2018

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

@MaskRay
Copy link
Author

MaskRay commented Nov 24, 2018

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.

@chemzqm
Copy link
Member

chemzqm commented Nov 24, 2018

Coc will use set_virtual_text of neovim for codeLenes feature.

@chemzqm chemzqm added the bug Something isn't working label Nov 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants