diff options
author | cbarrete <62146989+cbarrete@users.noreply.github.com> | 2020-07-18 21:10:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-18 15:10:09 -0400 |
commit | 08efa7037e05ce229150d17db11b1b1c2419631f (patch) | |
tree | 0064d34f56ed96f82094970d60870d02773349cc /runtime/lua/vim/lsp/callbacks.lua | |
parent | a02a267f8ad4b6d8b9038d2c7d9b85f03e734814 (diff) | |
download | rneovim-08efa7037e05ce229150d17db11b1b1c2419631f.tar.gz rneovim-08efa7037e05ce229150d17db11b1b1c2419631f.tar.bz2 rneovim-08efa7037e05ce229150d17db11b1b1c2419631f.zip |
lsp: Add support for call hierarchies (#12556)
* LSP: Add support for call hierarchies
* LSP: Add support for call hierarchies
* LSP: Add support for call hierarchies
* LSP: Jump to call location
Jump to the call site instead of jumping to the definition of the
caller/callee.
* LSP: add tests for the call hierarchy callbacks
* Fix linting error
Co-authored-by: Cédric Barreteau <>
Diffstat (limited to 'runtime/lua/vim/lsp/callbacks.lua')
-rw-r--r-- | runtime/lua/vim/lsp/callbacks.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp/callbacks.lua b/runtime/lua/vim/lsp/callbacks.lua index 4b14f0132d..1ed58995d0 100644 --- a/runtime/lua/vim/lsp/callbacks.lua +++ b/runtime/lua/vim/lsp/callbacks.lua @@ -214,6 +214,33 @@ M['textDocument/documentHighlight'] = function(_, _, result, _) util.buf_highlight_references(bufnr, result) end +-- direction is "from" for incoming calls and "to" for outgoing calls +local make_call_hierarchy_callback = function(direction) + -- result is a CallHierarchy{Incoming,Outgoing}Call[] + return function(_, _, result) + if not result then return end + local items = {} + for _, call_hierarchy_call in pairs(result) do + local call_hierarchy_item = call_hierarchy_call[direction] + for _, range in pairs(call_hierarchy_call.fromRanges) do + table.insert(items, { + filename = assert(vim.uri_to_fname(call_hierarchy_item.uri)), + text = call_hierarchy_item.name, + lnum = range.start.line + 1, + col = range.start.character + 1, + }) + end + end + util.set_qflist(items) + api.nvim_command("copen") + api.nvim_command("wincmd p") + end +end + +M['callHierarchy/incomingCalls'] = make_call_hierarchy_callback('from') + +M['callHierarchy/outgoingCalls'] = make_call_hierarchy_callback('to') + M['window/logMessage'] = function(_, _, result, client_id) local message_type = result.type local message = result.message |