aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/lsp/buf.lua24
-rw-r--r--runtime/lua/vim/lsp/util.lua51
-rw-r--r--runtime/lua/vim/treesitter/query.lua22
3 files changed, 47 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 287624f310..e403a8ee1b 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -916,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`)
@@ -941,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
@@ -1597,6 +1566,12 @@ function M.make_given_range_params(start_pos, end_pos)
if B[2] > 0 then
B = {B[1], M.character_offset(0, B[1], B[2])}
end
+ -- we need to offset the end character position otherwise we loose the last
+ -- character of the selection, as LSP end position is exclusive
+ -- see https://microsoft.github.io/language-server-protocol/specification#range
+ if vim.o.selection ~= 'exclusive' then
+ B[2] = B[2] + 1
+ end
return {
textDocument = M.make_text_document_params(),
range = {
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
index 9b4d28e09a..b81eb18945 100644
--- a/runtime/lua/vim/treesitter/query.lua
+++ b/runtime/lua/vim/treesitter/query.lua
@@ -231,7 +231,7 @@ local predicate_handlers = {
local compiled_vim_regexes = setmetatable({}, {
__index = function(t, pattern)
- local res = vim.regex(check_magic(vim.fn.escape(pattern, '\\')))
+ local res = vim.regex(check_magic(pattern))
rawset(t, pattern, res)
return res
end
@@ -260,7 +260,25 @@ local predicate_handlers = {
end
return false
- end
+ end,
+
+ ["any-of?"] = function(match, _, source, predicate)
+ local node = match[predicate[2]]
+ local node_text = M.get_node_text(node, source)
+
+ -- Since 'predicate' will not be used by callers of this function, use it
+ -- to store a string set built from the list of words to check against.
+ local string_set = predicate["string_set"]
+ if not string_set then
+ string_set = {}
+ for i=3,#predicate do
+ string_set[predicate[i]] = true
+ end
+ predicate["string_set"] = string_set
+ end
+
+ return string_set[node_text]
+ end,
}
-- As we provide lua-match? also expose vim-match?