fix: load config just once per call

This commit is contained in:
2025-01-05 01:45:43 +01:00
parent 6950c542ad
commit ca729140c3
4 changed files with 103 additions and 93 deletions

View File

@@ -1,7 +1,9 @@
local M = {}
local uv = vim.loop
local config = require('chatgpt_nvim.config')
-- Remove local config = require('chatgpt_nvim.config')
-- We'll accept conf from outside or init.lua
-- local config = require('chatgpt_nvim.config')
local function ensure_dir(path)
local st = uv.fs_stat(path)
@@ -16,8 +18,7 @@ local function ensure_dir(path)
return true
end
function M.get_clipboard_content()
local conf = config.load()
function M.get_clipboard_content(conf)
local content = vim.fn.getreg('+')
if conf.debug then
vim.api.nvim_out_write("[chatgpt_nvim:handler] Clipboard content length: " .. #content .. "\n")
@@ -25,8 +26,7 @@ function M.get_clipboard_content()
return content
end
function M.write_file(filepath, content)
local conf = config.load()
function M.write_file(filepath, content, conf)
local dir = filepath:match("(.*)/")
if dir and dir ~= "" then
ensure_dir(dir)
@@ -46,8 +46,7 @@ function M.write_file(filepath, content)
end
end
function M.delete_file(filepath)
local conf = config.load()
function M.delete_file(filepath, conf)
local st = uv.fs_stat(filepath)
if st then
local success, err = uv.fs_unlink(filepath)
@@ -73,4 +72,4 @@ function M.finish()
print("Finished processing files.")
end
return M
return M