aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua')
-rw-r--r--runtime/lua/vim/lsp.lua33
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua12
-rw-r--r--runtime/lua/vim/lsp/util.lua42
3 files changed, 46 insertions, 41 deletions
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index e48d879495..26700288af 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -1179,38 +1179,11 @@ function lsp._vim_exit_handler()
client.stop()
end
- local function wait_async(timeout, ms, predicate, cb)
- local timer = uv.new_timer()
- local time = 0
-
- local function done(in_time)
- timer:stop()
- timer:close()
- cb(in_time)
+ if not vim.wait(500, function() return tbl_isempty(active_clients) end, 50) then
+ for _, client in pairs(active_clients) do
+ client.stop(true)
end
-
- timer:start(0, ms, function()
- if predicate() == true then
- done(true)
- return
- end
-
- if time == timeout then
- done(false)
- return
- end
-
- time = time + ms
- end)
end
-
- wait_async(500, 50, function() return tbl_isempty(active_clients) end, function(in_time)
- if not in_time then
- for _, client in pairs(active_clients) do
- client.stop(true)
- end
- end
- end)
end
nvim_command("autocmd VimLeavePre * lua vim.lsp._vim_exit_handler()")
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua
index e6132e78bf..6f2f846a3b 100644
--- a/runtime/lua/vim/lsp/diagnostic.lua
+++ b/runtime/lua/vim/lsp/diagnostic.lua
@@ -406,9 +406,7 @@ function M.get_line_diagnostics(bufnr, line_nr, opts, client_id)
line_diagnostics = filter_by_severity_limit(opts.severity_limit, line_diagnostics)
end
- if opts.severity_sort then
- table.sort(line_diagnostics, function(a, b) return a.severity < b.severity end)
- end
+ table.sort(line_diagnostics, function(a, b) return a.severity < b.severity end)
return line_diagnostics
end
@@ -997,6 +995,8 @@ end
--- - See |vim.lsp.diagnostic.set_signs()|
--- - update_in_insert: (default=false)
--- - Update diagnostics in InsertMode or wait until InsertLeave
+--- - severity_sort: (default=false)
+--- - Sort diagnostics (and thus signs and virtual text)
function M.on_publish_diagnostics(_, _, params, client_id, _, config)
local uri = params.uri
local bufnr = vim.uri_to_bufnr(uri)
@@ -1007,6 +1007,10 @@ function M.on_publish_diagnostics(_, _, params, client_id, _, config)
local diagnostics = params.diagnostics
+ if config and if_nil(config.severity_sort, false) then
+ table.sort(diagnostics, function(a, b) return a.severity > b.severity end)
+ end
+
-- Always save the diagnostics, even if the buf is not loaded.
-- Language servers may report compile or build errors via diagnostics
-- Users should be able to find these, even if they're in files which
@@ -1034,6 +1038,7 @@ function M.display(diagnostics, bufnr, client_id, config)
underline = true,
virtual_text = true,
update_in_insert = false,
+ severity_sort = false,
}, config)
-- TODO(tjdevries): Consider how we can make this a "standardized" kind of thing for |lsp-handlers|.
@@ -1116,7 +1121,6 @@ end
---@return table {popup_bufnr, win_id}
function M.show_line_diagnostics(opts, bufnr, line_nr, client_id)
opts = opts or {}
- opts.severity_sort = if_nil(opts.severity_sort, true)
local show_header = if_nil(opts.show_header, true)
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 71ec85381b..92ec447b55 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -914,6 +914,23 @@ 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`)
@@ -922,22 +939,33 @@ 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 bufnr = vim.uri_to_bufnr(uri)
- -- Save position in jumplist
- 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')
+ 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}
--- 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