MaskRay / vscode-ccls

ccls plugin for Visual Studio Code
122 stars 37 forks source link

Simple: Expose suport for references from the keyboard as if pressing ref (one liner code change added) #82

Open flixil opened 5 years ago

flixil commented 5 years ago

Just adding

this._dispose.push(commands.registerCommand("ccls.references", this.makeRefHandler("textDocument/references")));

Onto the serverContext.ts would immediately make this available from a keyboard shortcut such as

"vim.normalModeKeyBindingsNonRecursive": [
    {"before":["<leader>","r"],"commands":[{"command":"ccls.references"}]},
],

This works for variables, functions, etc. and it's the same implementation as clicking on the ref. button, so one doesn't need to remember ccls.vars, ccls.call, ccls.member keystrokes.

As a bonus, on the Peek window, this shows the exact location where there references are used from on the right hand side, instead of the function that contains the calls for ccls.call so it behaves more intuitively.

Kind regards, flixil

MaskRay commented 5 years ago

Isn't it a generic feature that does no ccls-specific thing? Why name it ccls.references?

flixil commented 5 years ago

"Peek references" palete command doesn't shows also the definition and implementation, not only where things are used. So it's not a perfect replacement

It would send the textDocument/references command to ccls with the same behaviour as when we click ref on the editor.

Is there a way to have a keyboard binding without exposing textDocument/references from vscode-ccls?

When you click on ref on the editor we are sending something like

{"jsonrpc":"2.0","id":119,"method":"workspace/executeCommand","params":{"command":"ccls.xref","arguments":["{\"usr\":15001499940446849262,\"kind\":3,\"field\":\"uses\"}"]}}Content-Length: 182

When you send the registerCommand ccls.references you would send something like

{"jsonrpc":"2.0","id":478,"method":"textDocument/references","params":{"position":{"line":830,"character":42},"textDocument":{"uri":"file:///work/main.cpp"}}}Content-Length: 182

flixil commented 5 years ago

The thing is that the current "ccls: Show Cross References" doesn't do the exact same thing as when you click on a ref. button, it just does ccls.call, and I find the button more useful.

Maybe the behaviour of "ccls: Show Cross References" should NOT be just ccls.call as defined now in package.json, but instead "textDocument/references" which would work for all types and move the cursor to the right usage place.