fix: diagnostics lnum starts with 1 (#892)
This commit is contained in:
parent
9042f5f202
commit
67e946ef13
@ -201,7 +201,7 @@ function Selection:create_editing_input()
|
||||
input = mentions.new_content
|
||||
local project_context = mentions.enable_project_context and RepoMap.get_repo_map(file_ext) or nil
|
||||
|
||||
local diagnostics = Utils.get_current_selection_diagnostics()
|
||||
local diagnostics = Utils.get_current_selection_diagnostics(code_bufnr, self.selection)
|
||||
|
||||
Llm.stream({
|
||||
bufnr = code_bufnr,
|
||||
|
@ -1542,8 +1542,8 @@ function Sidebar:create_input(opts)
|
||||
|
||||
local diagnostics = nil
|
||||
if mentions.enable_diagnostics then
|
||||
if self.selected_code ~= nil then
|
||||
diagnostics = Utils.get_current_selection_diagnostics()
|
||||
if self.code ~= nil and self.code.bufnr ~= nil and self.code.selection ~= nil then
|
||||
diagnostics = Utils.get_current_selection_diagnostics(self.code.bufnr, self.code.selection)
|
||||
else
|
||||
diagnostics = Utils.get_diagnostics(self.code.bufnr)
|
||||
end
|
||||
|
@ -1,11 +1,29 @@
|
||||
{%- 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)
|
||||
severity: The severity of the diagnostic
|
||||
message: The diagnostic text
|
||||
source: The source of the diagnostic
|
||||
</diagnostic_field_description>
|
||||
<diagnostics>
|
||||
{{diagnostics}}
|
||||
</diagnostics>
|
||||
{%- endif %}
|
||||
{%- 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)
|
||||
severity: The severity of the diagnostic
|
||||
message: The diagnostic text
|
||||
source: The source of the diagnostic
|
||||
|
||||
DIAGNOSTICS:
|
||||
{{diagnostics}}
|
||||
{%- endif %}
|
||||
|
@ -772,18 +772,31 @@ function M.update_buffer_content(bufnr, new_lines)
|
||||
end
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@return vim.Diagnostic[]
|
||||
function M.get_diagnostics(bufnr)
|
||||
if bufnr == nil then bufnr = api.nvim_get_current_buf() end
|
||||
return vim.diagnostic.get(bufnr, { severity = { vim.diagnostic.severity.ERROR, vim.diagnostic.severity.WARN } })
|
||||
local diagnositcs = ---@type vim.Diagnostic[]
|
||||
vim.diagnostic.get(bufnr, { severity = { vim.diagnostic.severity.ERROR, vim.diagnostic.severity.WARN } })
|
||||
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
|
||||
end)
|
||||
:totable()
|
||||
end
|
||||
|
||||
function M.get_current_selection_diagnostics()
|
||||
local selection = M.get_visual_selection_and_range()
|
||||
if not selection then return {} end
|
||||
local diagnostics = M.get_diagnostics()
|
||||
---@param bufnr integer
|
||||
---@param selection avante.SelectionResult
|
||||
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:contains(diagnostic.lnum, diagnostic.col) then
|
||||
if selection.range.start.lnum <= diagnostic.lnum and selection.range.finish.lnum >= diagnostic.end_lnum then
|
||||
table.insert(selection_diagnostics, diagnostic)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user