aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua44
-rw-r--r--runtime/lua/vim/lsp/util.lua21
2 files changed, 41 insertions, 24 deletions
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua
index 6a7dc1bbb0..06f2babde4 100644
--- a/runtime/lua/vim/lsp/diagnostic.lua
+++ b/runtime/lua/vim/lsp/diagnostic.lua
@@ -1197,44 +1197,56 @@ end
--- - Exclusive severity to consider. Overrides {severity_limit}
--- - {severity_limit}: (DiagnosticSeverity)
--- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
+--- - {workspace}: (boolean, default false)
+--- - Set the list with workspace diagnostics
function M.set_loclist(opts)
opts = opts or {}
local open_loclist = if_nil(opts.open_loclist, true)
- local bufnr = vim.api.nvim_get_current_buf()
- local buffer_diags = M.get(bufnr, opts.client_id)
-
- if opts.severity then
- buffer_diags = filter_to_severity_limit(opts.severity, buffer_diags)
- elseif opts.severity_limit then
- buffer_diags = filter_by_severity_limit(opts.severity_limit, buffer_diags)
- end
+ local win_id = vim.api.nvim_get_current_win()
+ local current_bufnr = vim.api.nvim_get_current_buf()
+ local diags = opts.workspace and M.get_all() or {
+ [current_bufnr] = M.get(current_bufnr, opts.client_id)
+ }
local items = {}
- local insert_diag = function(diag)
+ local insert_diag = function(bufnr, diag)
local pos = diag.range.start
local row = pos.line
- local col = util.character_offset(bufnr, row, pos.character)
- local line = (api.nvim_buf_get_lines(bufnr, row, row + 1, false) or {""})[1]
+ local col = util.character_offset(bufnr, row, pos.character) or 0
table.insert(items, {
bufnr = bufnr,
lnum = row + 1,
col = col + 1,
- text = line .. " | " .. diag.message,
+ text = diag.message,
type = loclist_type_map[diag.severity or DiagnosticSeverity.Error] or 'E',
})
end
- for _, diag in ipairs(buffer_diags) do
- insert_diag(diag)
+ for bufnr, diagnostic in pairs(diags) do
+ if opts.severity then
+ diagnostic = filter_to_severity_limit(opts.severity, diagnostic)
+ elseif opts.severity_limit then
+ diagnostic = filter_by_severity_limit(opts.severity_limit, diagnostic)
+ end
+
+ for _, diag in ipairs(diagnostic) do
+ insert_diag(bufnr, diag)
+ end
end
- table.sort(items, function(a, b) return a.lnum < b.lnum end)
+ table.sort(items, function(a, b)
+ if a.bufnr == b.bufnr then
+ return a.lnum < b.lnum
+ else
+ return a.bufnr < b.bufnr
+ end
+ end)
- util.set_loclist(items)
+ util.set_loclist(items, win_id)
if open_loclist then
vim.cmd [[lopen]]
end
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 1e6a4ebd41..d421a10011 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -40,9 +40,12 @@ local function get_border_size(opts)
local width = 0
if type(border) == 'string' then
- -- 'single', 'double', etc.
- height = 2
- width = 2
+ local border_size = {none = {0, 0}, single = {2, 2}, double = {2, 2}, shadow = {1, 1}}
+ if border_size[border] == nil then
+ error("floating preview border is not correct. Please refer to the docs |vim.api.nvim_open_win()|"
+ .. vim.inspect(border))
+ end
+ height, width = unpack(border_size[border])
else
local function border_width(id)
if type(border[id]) == "table" then
@@ -1603,12 +1606,13 @@ function M.locations_to_items(locations)
return items
end
---- Fills current window's location list with given list of items.
+--- Fills target window's location list with given list of items.
--- Can be obtained with e.g. |vim.lsp.util.locations_to_items()|.
+--- Defaults to current window.
---
--@param items (table) list of items
-function M.set_loclist(items)
- vim.fn.setloclist(0, {}, ' ', {
+function M.set_loclist(items, win_id)
+ vim.fn.setloclist(win_id or 0, {}, ' ', {
title = 'Language Server';
items = items;
})
@@ -1849,8 +1853,9 @@ end
--@param row 0-indexed line
--@param col 0-indexed byte offset in line
--@returns (number, number) UTF-32 and UTF-16 index of the character in line {row} column {col} in buffer {buf}
-function M.character_offset(buf, row, col)
- local line = api.nvim_buf_get_lines(buf, row, row+1, true)[1]
+function M.character_offset(bufnr, row, col)
+ local uri = vim.uri_from_bufnr(bufnr)
+ local line = M.get_line(uri, row)
-- If the col is past the EOL, use the line length.
if col > #line then
return str_utfindex(line)