mirror of
https://github.com/neovim/neovim.git
synced 2026-01-06 19:39:53 +10:00
refactor: move vim.lsp.diagnostic to vim.diagnostic
This generalizes diagnostic handling outside of just the scope of LSP. LSP clients are now a specific case of a diagnostic producer, but the diagnostic subsystem is decoupled from the LSP subsystem (or will be, eventually). More discussion at [1]. [1]: https://github.com/neovim/neovim/pull/15585
This commit is contained in:
1178
runtime/lua/vim/diagnostic.lua
Normal file
1178
runtime/lua/vim/diagnostic.lua
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1534,8 +1534,5 @@ function lsp._with_extend(name, options, user_config)
|
||||
return resulting_config
|
||||
end
|
||||
|
||||
-- Define the LspDiagnostics signs if they're not defined already.
|
||||
require('vim.lsp.diagnostic')._define_default_signs_and_highlights()
|
||||
|
||||
return lsp
|
||||
-- vim:sw=2 ts=2 et
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -210,10 +210,16 @@ local function response_to_list(map_result, entity)
|
||||
else
|
||||
config = config or {}
|
||||
if config.loclist then
|
||||
util.set_loclist(map_result(result, ctx.bufnr))
|
||||
vim.fn.setloclist(0, {}, ' ', {
|
||||
title = 'Language Server';
|
||||
items = map_result(result, ctx.bufnr);
|
||||
})
|
||||
api.nvim_command("lopen")
|
||||
else
|
||||
util.set_qflist(map_result(result, ctx.bufnr))
|
||||
vim.fn.setqflist({}, ' ', {
|
||||
title = 'Language Server';
|
||||
items = map_result(result, ctx.bufnr);
|
||||
})
|
||||
api.nvim_command("copen")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,16 +31,6 @@ local default_border = {
|
||||
{" ", "NormalFloat"},
|
||||
}
|
||||
|
||||
|
||||
local DiagnosticSeverity = protocol.DiagnosticSeverity
|
||||
local loclist_type_map = {
|
||||
[DiagnosticSeverity.Error] = 'E',
|
||||
[DiagnosticSeverity.Warning] = 'W',
|
||||
[DiagnosticSeverity.Information] = 'I',
|
||||
[DiagnosticSeverity.Hint] = 'I',
|
||||
}
|
||||
|
||||
|
||||
---@private
|
||||
--- Check the border given by opts or the default border for the additional
|
||||
--- size it adds to a float.
|
||||
@@ -1543,6 +1533,9 @@ end
|
||||
--- Returns the items with the byte position calculated correctly and in sorted
|
||||
--- order, for display in quickfix and location lists.
|
||||
---
|
||||
--- The result can be passed to the {list} argument of |setqflist()| or
|
||||
--- |setloclist()|.
|
||||
---
|
||||
---@param locations (table) list of `Location`s or `LocationLink`s
|
||||
---@returns (table) list of items
|
||||
function M.locations_to_items(locations)
|
||||
@@ -1601,6 +1594,8 @@ end
|
||||
--- Can be obtained with e.g. |vim.lsp.util.locations_to_items()|.
|
||||
--- Defaults to current window.
|
||||
---
|
||||
---@deprecated Use |setloclist()|
|
||||
---
|
||||
---@param items (table) list of items
|
||||
function M.set_loclist(items, win_id)
|
||||
vim.fn.setloclist(win_id or 0, {}, ' ', {
|
||||
@@ -1612,6 +1607,8 @@ end
|
||||
--- Fills quickfix list with given list of items.
|
||||
--- Can be obtained with e.g. |vim.lsp.util.locations_to_items()|.
|
||||
---
|
||||
---@deprecated Use |setqflist()|
|
||||
---
|
||||
---@param items (table) list of items
|
||||
function M.set_qflist(items)
|
||||
vim.fn.setqflist({}, ' ', {
|
||||
@@ -1869,40 +1866,6 @@ function M.lookup_section(settings, section)
|
||||
return settings
|
||||
end
|
||||
|
||||
|
||||
--- Convert diagnostics grouped by bufnr to a list of items for use in the
|
||||
--- quickfix or location list.
|
||||
---
|
||||
---@param diagnostics_by_bufnr table bufnr -> Diagnostic[]
|
||||
---@param predicate an optional function to filter the diagnostics.
|
||||
--- If present, only diagnostic items matching will be included.
|
||||
---@return table (A list of items)
|
||||
function M.diagnostics_to_items(diagnostics_by_bufnr, predicate)
|
||||
local items = {}
|
||||
for bufnr, diagnostics in pairs(diagnostics_by_bufnr or {}) do
|
||||
for _, d in pairs(diagnostics) do
|
||||
if not predicate or predicate(d) then
|
||||
table.insert(items, {
|
||||
bufnr = bufnr,
|
||||
lnum = d.range.start.line + 1,
|
||||
col = d.range.start.character + 1,
|
||||
text = d.message,
|
||||
type = loclist_type_map[d.severity or DiagnosticSeverity.Error] or 'E'
|
||||
})
|
||||
end
|
||||
end
|
||||
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)
|
||||
return items
|
||||
end
|
||||
|
||||
|
||||
M._get_line_byte_from_position = get_line_byte_from_position
|
||||
M._warn_once = warn_once
|
||||
|
||||
|
||||
Reference in New Issue
Block a user