From 46a621e9dea39609903a533df79acf7ceb472aec Mon Sep 17 00:00:00 2001 From: Aaron Pham Date: Wed, 28 Aug 2024 12:54:06 -0400 Subject: [PATCH] fix: check for clipboard path locally to avoid recursion (#330) Signed-off-by: Aaron Pham --- README.md | 1 + lua/avante/clipboard/init.lua | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c2db14b..159513a 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,7 @@ We would like to express our heartfelt gratitude to the contributors of the foll | --- | --- | --- | --- | | [git-conflict.nvim](https://github.com/akinsho/git-conflict.nvim) | No License | Diff comparison functionality | https://github.com/yetone/avante.nvim/blob/main/lua/avante/diff.lua | | [ChatGPT.nvim](https://github.com/jackMort/ChatGPT.nvim) | Apache 2.0 License | Calculation of tokens count | https://github.com/yetone/avante.nvim/blob/main/lua/avante/utils/tokens.lua | +| [img-clip.nvim](https://github.com/HakonHarnes/img-clip.nvim) | MIT License | Clipboard image support | https://github.com/yetone/avante.nvim/blob/main/lua/avante/clipboard/init.lua | The high quality and ingenuity of these projects' source code have been immensely beneficial throughout our development process. We extend our sincere thanks and respect to the authors and contributors of these projects. It is the selfless dedication of the open-source community that drives projects like avante.nvim forward. diff --git a/lua/avante/clipboard/init.lua b/lua/avante/clipboard/init.lua index dae7344..ada3ca0 100644 --- a/lua/avante/clipboard/init.lua +++ b/lua/avante/clipboard/init.lua @@ -15,11 +15,23 @@ local Config = require("avante.config") ---@class avante.Clipboard: AvanteClipboard local M = {} -M.paste_directory = Path:new(Config.history.storage_path):joinpath("pasted_images") +---@type Path +local paste_directory = nil + +---@return Path +local function get_paste_directory() + if paste_directory then + return paste_directory + end + paste_directory = Path:new(Config.history.storage_path):joinpath("pasted_images") + return paste_directory +end M.setup = function() - if not M.paste_directory:exists() then - M.paste_directory:mkdir({ parent = true }) + get_paste_directory() + + if not paste_directory:exists() then + paste_directory:mkdir({ parent = true }) end end @@ -30,10 +42,7 @@ return setmetatable(M, { local impl = require("avante.clipboard." .. os_mapping) if impl[k] ~= nil then return impl[k] - elseif t[k] ~= nil then - return t[k] - else - error("Failed to find clipboard implementation for " .. os_mapping) end + return t[k] end, })