aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorkevinhwang91 <kevin.hwang@live.com>2021-05-20 21:15:31 +0800
committerkevinhwang91 <kevin.hwang@live.com>2021-05-20 21:15:31 +0800
commitd29148ffd812058cf7281607d1b6a9dd937d5d6c (patch)
tree8dc16d1b0949b0093a3fd71991ac3ed438fca4d6 /runtime/lua/vim
parent2dc0f812710b19f8befcfa64ef9335cadc510296 (diff)
parent5d9c5601275abfa17396b3a80c7b958c48080807 (diff)
downloadrneovim-d29148ffd812058cf7281607d1b6a9dd937d5d6c.tar.gz
rneovim-d29148ffd812058cf7281607d1b6a9dd937d5d6c.tar.bz2
rneovim-d29148ffd812058cf7281607d1b6a9dd937d5d6c.zip
Merge remote-tracking branch 'origin/master' into qftf
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/lsp/buf.lua24
-rw-r--r--runtime/lua/vim/lsp/util.lua51
2 files changed, 25 insertions, 50 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index 341a3e82fc..5dd7109bb0 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -297,26 +297,30 @@ local function pick_call_hierarchy_item(call_hierarchy_items)
return choice
end
+local function call_hierarchy(method)
+ local params = util.make_position_params()
+ request('textDocument/prepareCallHierarchy', params, function(err, _, result)
+ if err then
+ vim.notify(err.message, vim.log.levels.WARN)
+ return
+ end
+ local call_hierarchy_item = pick_call_hierarchy_item(result)
+ vim.lsp.buf_request(0, method, { item = call_hierarchy_item })
+ end)
+end
+
--- Lists all the call sites of the symbol under the cursor in the
--- |quickfix| window. If the symbol can resolve to multiple
--- items, the user can pick one in the |inputlist|.
function M.incoming_calls()
- local params = util.make_position_params()
- request('textDocument/prepareCallHierarchy', params, function(_, _, result)
- local call_hierarchy_item = pick_call_hierarchy_item(result)
- vim.lsp.buf_request(0, 'callHierarchy/incomingCalls', { item = call_hierarchy_item })
- end)
+ call_hierarchy('callHierarchy/incomingCalls')
end
--- Lists all the items that are called by the symbol under the
--- cursor in the |quickfix| window. If the symbol can resolve to
--- multiple items, the user can pick one in the |inputlist|.
function M.outgoing_calls()
- local params = util.make_position_params()
- request('textDocument/prepareCallHierarchy', params, function(_, _, result)
- local call_hierarchy_item = pick_call_hierarchy_item(result)
- vim.lsp.buf_request(0, 'callHierarchy/outgoingCalls', { item = call_hierarchy_item })
- end)
+ call_hierarchy('callHierarchy/outgoingCalls')
end
--- List workspace folders.
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 57919e907c..e403a8ee1b 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -566,13 +566,15 @@ end
--@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
local function get_completion_word(item)
if item.textEdit ~= nil and item.textEdit.newText ~= nil and item.textEdit.newText ~= "" then
- if protocol.InsertTextFormat[item.insertTextFormat] == "PlainText" then
+ local insert_text_format = protocol.InsertTextFormat[item.insertTextFormat]
+ if insert_text_format == "PlainText" or insert_text_format == nil then
return item.textEdit.newText
else
return M.parse_snippet(item.textEdit.newText)
end
elseif item.insertText ~= nil and item.insertText ~= "" then
- if protocol.InsertTextFormat[item.insertTextFormat] == "PlainText" then
+ local insert_text_format = protocol.InsertTextFormat[item.insertTextFormat]
+ if insert_text_format == "PlainText" or insert_text_format == nil then
return item.insertText
else
return M.parse_snippet(item.insertText)
@@ -914,23 +916,6 @@ function M.make_floating_popup_options(width, height, opts)
}
end
-local function _should_add_to_tagstack(new_item)
- local stack = vim.fn.gettagstack()
-
- -- Check if we're at the bottom of the tagstack.
- if stack.curidx <= 1 then return true end
-
- local top_item = stack.items[stack.curidx-1]
-
- -- Check if the item at the top of the tagstack is exactly the
- -- same as the one we want to push.
- if top_item.tagname ~= new_item.tagname then return true end
- for i, v in ipairs(top_item.from) do
- if v ~= new_item.from[i] then return true end
- end
- return false
-end
-
--- Jumps to a location.
---
--@param location (`Location`|`LocationLink`)
@@ -939,36 +924,22 @@ function M.jump_to_location(location)
-- location may be Location or LocationLink
local uri = location.uri or location.targetUri
if uri == nil then return end
-
- local from_bufnr = vim.fn.bufnr('%')
- local from = {from_bufnr, vim.fn.line('.'), vim.fn.col('.'), 0}
- local item = {tagname=vim.fn.expand('<cword>'), from=from}
-
+ local bufnr = vim.uri_to_bufnr(uri)
-- Save position in jumplist
- vim.cmd("mark '")
+ vim.cmd "normal! m'"
+
+ -- Push a new item into tagstack
+ local from = {vim.fn.bufnr('%'), vim.fn.line('.'), vim.fn.col('.'), 0}
+ local items = {{tagname=vim.fn.expand('<cword>'), from=from}}
+ vim.fn.settagstack(vim.fn.win_getid(), {items=items}, 't')
--- Jump to new location (adjusting for UTF-16 encoding of characters)
- local bufnr = vim.uri_to_bufnr(uri)
api.nvim_set_current_buf(bufnr)
api.nvim_buf_set_option(0, 'buflisted', true)
local range = location.range or location.targetSelectionRange
local row = range.start.line
local col = get_line_byte_from_position(0, range.start)
- -- This prevents the tagstack to be filled with items that provide
- -- no motion when CTRL-T is pressed because they're both the source
- -- and the destination.
- local motionless =
- bufnr == from_bufnr and
- row+1 == from[2] and col+1 == from[3]
- if not motionless and _should_add_to_tagstack(item) then
- local winid = vim.fn.win_getid()
- local items = {item}
- vim.fn.settagstack(winid, {items=items}, 't')
- end
-
- -- Jump to new location
api.nvim_win_set_cursor(0, {row + 1, col})
-
return true
end