make lsp-treemacs-call-hierarchy show location of call instead of only the caller's name
Jacob-Burckhardt opened this issue · 0 comments
For this file:
void f() {}
int main() {
f();
f();
}
lsp-treemacs-call-hierarchy shows something like this:
f
main
The above does not say where in main
, that f
is called. It also does not show how many locations in main
have calls to f
. It is a minor issue for this small test program, but if it were a big project, main
might have hundreds of lines which is where my suggested enhancement would be really useful.
To be specific I would prefer it to say:
f
main line 4
main line 5
Double-clicking on the row saying main currently moves the cursor to line 3 which is the header line of main. Naturally, I prefer it to move the cursor to inside the body at line 4 or 5 depending on which line was clicked.
clangd appears to give enough info to Emacs to allow the greater detail I request. Below I marked lines 3 and line 4 in bold. I think the LSP protocol refers to the first line in the file as line 0. That is why it says the calls to f
are on lines 3 and 4. Since Emacs assigns the first line as line 1, then Emacs would simply need to add 1 to the line number that clangd gives to get lines 4 and 5 like in my example tree above.
Thanks.
V[17:33:20.129] <<< {"id":167,"jsonrpc":"2.0","method":"textDocument/prepareCallHierarchy","params":{"position":{"character":5,"line":0},"textDocument":{"uri":"file:///home/bjacob/backup/C%2B%2B/tests/a.cpp"}}}
I[17:33:20.129] <-- textDocument/prepareCallHierarchy(167)
V[17:33:20.129] ASTWorker running CallHierarchy on version 49 of /home/bjacob/backup/C++/tests/a.cpp
I[17:33:20.129] --> reply:textDocument/prepareCallHierarchy(167) 0 ms
V[17:33:20.129] >>> {"id":167,"jsonrpc":"2.0","result":[{"data":"B3A9EC6BECD5869C","kind":12,"name":"f","range":{"end":{"character":11,"line":0},"start":{"character":0,"line":0}},"selectionRange":{"end":{"character":6,"line":0},"start":{"character":5,"line":0}},"uri":"file:///home/bjacob/backup/C%2B%2B/tests/a.cpp"}]}V[17:33:23.119] <<< {"id":168,"jsonrpc":"2.0","method":"callHierarchy/incomingCalls","params":{"item":{"data":"B3A9EC6BECD5869C","kind":12,"name":"f","range":{"end":{"character":11,"line":0},"start":{"character":0,"line":0}},"selectionRange":{"end":{"character":6,"line":0},"start":{"character":5,"line":0}},"uri":"file:///home/bjacob/backup/C%2B%2B/tests/a.cpp"}}}
I[17:33:23.119] <-- callHierarchy/incomingCalls(168)
I[17:33:23.120] --> reply:callHierarchy/incomingCalls(168) 0 ms
V[17:33:23.120] >>> {"id":168,"jsonrpc":"2.0","result":[{"from":{"data":"3017D418E3EE7259","kind":12,"name":"main","range":{"end":{"character":8,"line":2},"start":{"character":4,"line":2}},"selectionRange":{"end":{"character":8,"line":2},"start":{"character":4,"line":2}},"uri":"file:///home/bjacob/backup/C%2B%2B/tests/a.cpp"},"fromRanges":[{"end":{"character":4,"line":3},"start":{"character":3,"line":3}},{"end":{"character":4,"line":4},"start":{"character":3,"line":4}}]}]}