feat: add project_name for safety, so you dont accidently insert into the wrong project

This commit is contained in:
2024-12-13 00:25:03 +01:00
parent 00a52998b8
commit 2eb79c2b1a
3 changed files with 18 additions and 3 deletions

View File

@@ -46,6 +46,7 @@ function M.run_chatgpt_command()
local sections = {
conf.initial_prompt .. "\n" .. user_input,
"\n\nProject name: " .. (conf.project_name or "") .. "\n",
"\n\nProject Structure:\n",
project_structure,
"\n\nBelow are the files from the project, each preceded by its filename in backticks and enclosed in triple backticks.\n"
@@ -69,6 +70,7 @@ end
function M.run_chatgpt_paste_command()
print("Reading ChatGPT YAML response from clipboard...")
local conf = config.load()
local raw = handler.get_clipboard_content()
if raw == "" then
vim.api.nvim_err_writeln("Clipboard is empty. Please copy the YAML response from ChatGPT first.")
@@ -81,6 +83,13 @@ function M.run_chatgpt_paste_command()
return
end
if not data.project_name or data.project_name ~= conf.project_name then
vim.api.nvim_err_writeln("Project name mismatch. The provided changes are for project '" ..
(data.project_name or "unknown") .. "' but current project is '" ..
(conf.project_name or "unconfigured") .. "'. Aborting changes.")
return
end
for _, fileinfo in ipairs(data.files) do
if fileinfo.path and fileinfo.content then
handler.write_file(fileinfo.path, fileinfo.content)