fix: just load conf once per command
This commit is contained in:
@@ -12,8 +12,8 @@ local function copy_to_clipboard(text)
|
||||
vim.fn.setreg('+', text)
|
||||
end
|
||||
|
||||
local function parse_response(raw)
|
||||
local conf = config.load()
|
||||
-- We now expect 'conf' as a parameter, instead of loading config inside parse_response.
|
||||
local function parse_response(raw, conf)
|
||||
if not ok_yaml then
|
||||
vim.api.nvim_err_writeln("lyaml not available. Install with `luarocks install lyaml`.")
|
||||
return nil
|
||||
@@ -54,8 +54,8 @@ local function is_directory(path)
|
||||
return stat and stat.type == "directory"
|
||||
end
|
||||
|
||||
local function handle_step_by_step_if_needed(prompt)
|
||||
local conf = config.load()
|
||||
-- We now expect 'conf' as a parameter, instead of loading config inside handle_step_by_step_if_needed.
|
||||
local function handle_step_by_step_if_needed(prompt, conf)
|
||||
local length = #prompt
|
||||
if not conf.enable_step_by_step or length <= (conf.prompt_char_limit or 8000) then
|
||||
return { prompt }
|
||||
@@ -293,6 +293,7 @@ local function execute_debug_command(cmd)
|
||||
end
|
||||
|
||||
function M.run_chatgpt_command()
|
||||
-- Load the config once here for the entire command.
|
||||
local conf = config.load()
|
||||
ui.debug_log("Running :ChatGPT command.")
|
||||
local dirs = conf.directories or {"."}
|
||||
@@ -372,7 +373,7 @@ function M.run_chatgpt_command()
|
||||
local prompt = table.concat(initial_sections, "\n")
|
||||
store_prompt_for_reference(prompt)
|
||||
|
||||
local chunks = handle_step_by_step_if_needed(prompt)
|
||||
local chunks = handle_step_by_step_if_needed(prompt, conf)
|
||||
copy_to_clipboard(chunks[1])
|
||||
if #chunks == 1 then
|
||||
vim.api.nvim_out_write("Prompt copied to clipboard! Paste into ChatGPT.\n")
|
||||
@@ -397,7 +398,8 @@ function M.run_chatgpt_paste_command()
|
||||
return
|
||||
end
|
||||
|
||||
local data = parse_response(raw)
|
||||
-- Pass the loaded config into parse_response, so we don’t load config.lua again.
|
||||
local data = parse_response(raw, conf)
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
@@ -504,7 +506,7 @@ function M.run_chatgpt_paste_command()
|
||||
end
|
||||
|
||||
local sections = {
|
||||
config.load().initial_prompt,
|
||||
conf.initial_prompt,
|
||||
"\n\nProject name: " .. (conf.project_name or ""),
|
||||
"\n\nBelow are the requested files from the project, each preceded by its filename in backticks and enclosed in triple backticks.\n",
|
||||
table.concat(file_sections, "\n"),
|
||||
@@ -631,7 +633,7 @@ function M.run_chatgpt_current_buffer_command()
|
||||
|
||||
store_prompt_for_reference(prompt)
|
||||
|
||||
local chunks = handle_step_by_step_if_needed(prompt)
|
||||
local chunks = handle_step_by_step_if_needed(prompt, conf)
|
||||
copy_to_clipboard(chunks[1])
|
||||
if #chunks == 1 then
|
||||
vim.api.nvim_out_write("Prompt (from current buffer) copied to clipboard! Paste into ChatGPT.\n")
|
||||
|
||||
Reference in New Issue
Block a user