aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
diff options
context:
space:
mode:
authorMarco Hinz <mh.codebro@gmail.com>2021-05-19 18:58:21 +0200
committerGitHub <noreply@github.com>2021-05-19 18:58:21 +0200
commitf6a86a3d7d96627469c6187b103b559cef7f49f0 (patch)
tree41bf385253af504e2a71f519df04a0c5abf18c10 /runtime/lua/vim/lsp/util.lua
parentedd48f57aa45d35ed5067471d030b626f07cc707 (diff)
parent9051064672f1c0d354c80a097a7ec501747c1f48 (diff)
downloadrneovim-f6a86a3d7d96627469c6187b103b559cef7f49f0.tar.gz
rneovim-f6a86a3d7d96627469c6187b103b559cef7f49f0.tar.bz2
rneovim-f6a86a3d7d96627469c6187b103b559cef7f49f0.zip
Merge pull request #14589 from mhinz/revert-smarter-tagstack
Unfortunately, there are some subtle bugs in the smarter tagstack changes, so we'll revert them for now and try to come up with a better approach. One of the added tests, adds current position to jumplist before jumping, is valuable though and changed to still work after reverting the other two commits. Closes #14571
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r--runtime/lua/vim/lsp/util.lua45
1 files changed, 7 insertions, 38 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 57919e907c..fc5e894801 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -914,23 +914,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 +922,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