feat: format diagnostic (#895)
This commit is contained in:
parent
5e6d3368f7
commit
c8e688a0ac
@ -1,12 +1,10 @@
|
||||
{%- if use_xml_format -%}
|
||||
{%- if diagnostics -%}
|
||||
<diagnostic_field_description>
|
||||
lnum: The starting line of the diagnostic (1-indexed)
|
||||
end_lnum: The final line of the diagnostic (1-indexed)
|
||||
col: The starting column of the diagnostic (1-indexed)
|
||||
end_col: The final column of the diagnostic (1-indexed)
|
||||
content: The diagnostic content
|
||||
start_line: The starting line of the diagnostic (1-indexed)
|
||||
end_line: The final line of the diagnostic (1-indexed)
|
||||
severity: The severity of the diagnostic
|
||||
message: The diagnostic text
|
||||
source: The source of the diagnostic
|
||||
</diagnostic_field_description>
|
||||
<diagnostics>
|
||||
@ -16,12 +14,10 @@ source: The source of the diagnostic
|
||||
{%- else -%}
|
||||
{%- if diagnostics -%}
|
||||
DIAGNOSTIC_FIELD_DESCRIPTION:
|
||||
lnum: The starting line of the diagnostic (1-indexed)
|
||||
end_lnum: The final line of the diagnostic (1-indexed)
|
||||
col: The starting column of the diagnostic (1-indexed)
|
||||
end_col: The final column of the diagnostic (1-indexed)
|
||||
content: The diagnostic content
|
||||
start_line: The starting line of the diagnostic (1-indexed)
|
||||
end_line: The final line of the diagnostic (1-indexed)
|
||||
severity: The severity of the diagnostic
|
||||
message: The diagnostic text
|
||||
source: The source of the diagnostic
|
||||
|
||||
DIAGNOSTICS:
|
||||
|
@ -772,20 +772,40 @@ function M.update_buffer_content(bufnr, new_lines)
|
||||
end
|
||||
end
|
||||
|
||||
local severity = {
|
||||
[1] = "ERROR",
|
||||
[2] = "WARNING",
|
||||
[3] = "INFORMATION",
|
||||
[4] = "HINT",
|
||||
}
|
||||
|
||||
---@class AvanteDiagnostic
|
||||
---@field content string
|
||||
---@field start_line number
|
||||
---@field end_line number
|
||||
---@field severity string
|
||||
---@field source string
|
||||
|
||||
---@param bufnr integer
|
||||
---@return vim.Diagnostic[]
|
||||
---@return AvanteDiagnostic[]
|
||||
function M.get_diagnostics(bufnr)
|
||||
if bufnr == nil then bufnr = api.nvim_get_current_buf() end
|
||||
local diagnositcs = ---@type vim.Diagnostic[]
|
||||
vim.diagnostic.get(bufnr, { severity = { vim.diagnostic.severity.ERROR, vim.diagnostic.severity.WARN } })
|
||||
vim.diagnostic.get(
|
||||
bufnr,
|
||||
{ severity = { vim.diagnostic.severity.ERROR, vim.diagnostic.severity.WARN, vim.diagnostic.severity.HINT } }
|
||||
)
|
||||
return vim
|
||||
.iter(diagnositcs)
|
||||
:map(function(diagnostic)
|
||||
diagnostic.lnum = diagnostic.lnum + 1
|
||||
diagnostic.end_lnum = diagnostic.end_lnum + 1
|
||||
diagnostic.col = diagnostic.col + 1
|
||||
diagnostic.end_col = diagnostic.end_col + 1
|
||||
return diagnostic
|
||||
local d = {
|
||||
content = diagnostic.message,
|
||||
start_line = diagnostic.lnum + 1,
|
||||
end_line = diagnostic.end_lnum and diagnostic.end_lnum + 1 or diagnostic.lnum + 1,
|
||||
severity = severity[diagnostic.severity],
|
||||
source = diagnostic.source,
|
||||
}
|
||||
return d
|
||||
end)
|
||||
:totable()
|
||||
end
|
||||
@ -796,7 +816,7 @@ function M.get_current_selection_diagnostics(bufnr, selection)
|
||||
local diagnostics = M.get_diagnostics(bufnr)
|
||||
local selection_diagnostics = {}
|
||||
for _, diagnostic in ipairs(diagnostics) do
|
||||
if selection.range.start.lnum <= diagnostic.lnum and selection.range.finish.lnum >= diagnostic.end_lnum then
|
||||
if selection.range.start.lnum <= diagnostic.start_line and selection.range.finish.lnum >= diagnostic.end_line then
|
||||
table.insert(selection_diagnostics, diagnostic)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user