feat: automatically obtain diagnostics after finishing editing the file (#2018)

This commit is contained in:
yetone
2025-05-08 22:50:46 +08:00
committed by GitHub
parent 1e80305af2
commit 6e1e2ac9f2
9 changed files with 171 additions and 93 deletions

View File

@@ -0,0 +1,51 @@
local Base = require("avante.llm_tools.base")
local Helpers = require("avante.llm_tools.helpers")
local Utils = require("avante.utils")
---@class AvanteLLMTool
local M = setmetatable({}, Base)
M.name = "get_diagnostics"
M.description = "Get diagnostics from a specific file"
---@type AvanteLLMToolParam
M.param = {
type = "table",
fields = {
{
name = "path",
description = "The path to the file in the current project scope",
type = "string",
},
},
}
---@type AvanteLLMToolReturn[]
M.returns = {
{
name = "diagnostics",
description = "The diagnostics for the file",
type = "string",
},
{
name = "error",
description = "Error message if the replacement failed",
type = "string",
optional = true,
},
}
---@type AvanteLLMToolFunc<{ path: string, diff: string }>
function M.func(opts, on_log, on_complete, session_ctx)
if not opts.path then return false, "pathf are required" end
if on_log then on_log("path: " .. opts.path) end
local abs_path = Helpers.get_abs_path(opts.path)
if not Helpers.has_permission_to_access(abs_path) then return false, "No permission to access path: " .. abs_path end
if not on_complete then return false, "on_complete is required" end
local diagnostics = Utils.lsp.get_diagnostics_from_filepath(abs_path)
local jsn_str = vim.json.encode(diagnostics)
on_complete(true, jsn_str)
end
return M

View File

@@ -125,7 +125,7 @@ function M.get_bufnr(abs_path)
if not sidebar then return 0, "Avante sidebar not found" end
local current_winid = vim.api.nvim_get_current_win()
vim.api.nvim_set_current_win(sidebar.code.winid)
local bufnr = Utils.get_or_create_buffer_with_filepath(abs_path)
local bufnr = Utils.open_buffer(abs_path)
vim.api.nvim_set_current_win(current_winid)
return bufnr, nil
end

View File

@@ -989,6 +989,7 @@ M._tools = {
},
},
},
require("avante.llm_tools.get_diagnostics"),
require("avante.llm_tools.bash"),
{
name = "web_search",