feat: add lint tool

This commit is contained in:
2025-01-31 10:43:28 +01:00
parent 0ff77954db
commit 35bd0a7278
6 changed files with 120 additions and 18 deletions

View File

@@ -1,4 +1,6 @@
local handler = require("chatgpt_nvim.handler")
local lint = require("chatgpt_nvim.tools.lint")
local M = {}
M.run = function(tool_call, conf, prompt_user_tool_accept, is_subpath, read_file)
@@ -14,13 +16,26 @@ M.run = function(tool_call, conf, prompt_user_tool_accept, is_subpath, read_file
return string.format("Tool [edit_file for '%s'] REJECTED. Path outside project root.", path)
end
-- 1) Write the new content
handler.write_file(path, new_content, conf)
local msg = {}
msg[#msg+1] = string.format("Tool [edit_file for '%s'] Result:\nThe content was successfully saved to %s.", path, path)
msg[#msg+1] = "\nHere is the full, updated content of the file that was saved:\n"
msg[#msg+1] = string.format("<final_file_content path=\"%s\">\n%s\n</final_file_content>", path, new_content)
msg[#msg+1] = "\nIMPORTANT: For any future changes to this file, use the final_file_content shown above as your reference.\n"
-- 2) Lint check if enabled
if conf.auto_lint then
local output, err = lint.lint_file(path)
if output then
msg[#msg+1] = "\n--- Lint Results ---\n"
msg[#msg+1] = output
else
msg[#msg+1] = "\n(Lint) " .. (err or "Could not lint this file.")
end
end
return table.concat(msg, "")
end