mirror of
https://github.com/neovim/neovim.git
synced 2026-04-27 17:54:10 +00:00
feat(diagnostic): add "code" to the diagnostic structure (#17510)
This commit is contained in:
@@ -39,16 +39,18 @@ modify the diagnostics for a buffer (e.g. |vim.diagnostic.set()|) then it
|
||||
requires a namespace.
|
||||
|
||||
*diagnostic-structure*
|
||||
A diagnostic is a Lua table with the following keys:
|
||||
A diagnostic is a Lua table with the following keys. Required keys are
|
||||
indicated with (*):
|
||||
|
||||
bufnr: Buffer number
|
||||
lnum: The starting line of the diagnostic
|
||||
lnum(*): The starting line of the diagnostic
|
||||
end_lnum: The final line of the diagnostic
|
||||
col: The starting column of the diagnostic
|
||||
col(*): The starting column of the diagnostic
|
||||
end_col: The final column of the diagnostic
|
||||
severity: The severity of the diagnostic |vim.diagnostic.severity|
|
||||
message: The diagnostic text
|
||||
message(*): The diagnostic text
|
||||
source: The source of the diagnostic
|
||||
code: The diagnostic code
|
||||
user_data: Arbitrary data plugins or users can add
|
||||
|
||||
Diagnostics use the same indexing as the rest of the Nvim API (i.e. 0-based
|
||||
|
||||
@@ -104,8 +104,10 @@ local function diagnostic_lsp_to_vim(diagnostics, bufnr, client_id)
|
||||
severity = severity_lsp_to_vim(diagnostic.severity),
|
||||
message = diagnostic.message,
|
||||
source = diagnostic.source,
|
||||
code = diagnostic.code,
|
||||
user_data = {
|
||||
lsp = {
|
||||
-- usage of user_data.lsp.code is deprecated in favor of the top-level code field
|
||||
code = diagnostic.code,
|
||||
codeDescription = diagnostic.codeDescription,
|
||||
tags = diagnostic.tags,
|
||||
@@ -120,7 +122,8 @@ end
|
||||
---@private
|
||||
local function diagnostic_vim_to_lsp(diagnostics)
|
||||
return vim.tbl_map(function(diagnostic)
|
||||
return vim.tbl_extend("error", {
|
||||
return vim.tbl_extend("keep", {
|
||||
-- "keep" the below fields over any duplicate fields in diagnostic.user_data.lsp
|
||||
range = {
|
||||
start = {
|
||||
line = diagnostic.lnum,
|
||||
@@ -134,6 +137,7 @@ local function diagnostic_vim_to_lsp(diagnostics)
|
||||
severity = severity_vim_to_lsp(diagnostic.severity),
|
||||
message = diagnostic.message,
|
||||
source = diagnostic.source,
|
||||
code = diagnostic.code,
|
||||
}, diagnostic.user_data and (diagnostic.user_data.lsp or {}) or {})
|
||||
end, diagnostics)
|
||||
end
|
||||
|
||||
@@ -110,6 +110,7 @@ describe('vim.lsp.diagnostic', function()
|
||||
}
|
||||
]]
|
||||
eq({code = 42, tags = {"foo", "bar"}, data = "Hello world"}, result[1].user_data.lsp)
|
||||
eq(42, result[1].code)
|
||||
eq(42, result[2].code)
|
||||
eq({"foo", "bar"}, result[2].tags)
|
||||
eq("Hello world", result[2].data)
|
||||
|
||||
Reference in New Issue
Block a user