diff --git a/README.md b/README.md index 5f44875..df5a8fd 100644 --- a/README.md +++ b/README.md @@ -500,6 +500,7 @@ _See [config.lua#L9](./lua/avante/config.lua) for the full config_ support_paste_from_clipboard = false, minimize_diff = true, -- Whether to remove unchanged lines when applying a code block enable_token_counting = true, -- Whether to enable token counting. Default to true. + auto_add_current_file = true, -- Whether to automatically add the current file when opening a new chat. Default to true. auto_approve_tool_permissions = true, -- Default: auto-approve all tools (no prompts) -- Examples: -- auto_approve_tool_permissions = false, -- Show permission prompts for all tools diff --git a/README_zh.md b/README_zh.md index d646fd9..ffefb0e 100644 --- a/README_zh.md +++ b/README_zh.md @@ -360,6 +360,7 @@ _请参见 [config.lua#L9](./lua/avante/config.lua) 以获取完整配置_ support_paste_from_clipboard = false, minimize_diff = true, -- 是否在应用代码块时删除未更改的行 enable_token_counting = true, -- 是否启用令牌计数。默认为 true。 + auto_add_current_file = true, -- 打开新聊天时是否自动添加当前文件。默认为 true。 enable_cursor_planning_mode = false, -- 是否启用 Cursor 规划模式。默认为 false。 enable_claude_text_editor_tool_mode = false, -- 是否启用 Claude 文本编辑器工具模式。 }, diff --git a/lua/avante/config.lua b/lua/avante/config.lua index 75c567f..851e932 100644 --- a/lua/avante/config.lua +++ b/lua/avante/config.lua @@ -496,6 +496,7 @@ M._defaults = { ---7. support_paste_from_clipboard : Whether to support pasting image from clipboard. This will be determined automatically based whether img-clip is available or not. ---8. minimize_diff : Whether to remove unchanged lines when applying a code block ---9. enable_token_counting : Whether to enable token counting. Default to true. + ---10. auto_add_current_file : Whether to automatically add the current file when opening a new chat. Default to true. behaviour = { auto_focus_sidebar = true, auto_suggestions = false, -- Experimental stage @@ -514,6 +515,7 @@ M._defaults = { auto_check_diagnostics = true, enable_fastapply = false, include_generated_by_commit_line = false, -- Controls if 'Generated-by: ' line is added to git commit message + auto_add_current_file = true, -- Whether to automatically add the current file when opening a new chat }, prompt_logger = { -- logs prompts to disk (timestamped, for replay/debugging) enabled = true, -- toggle logging entirely diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index 7447c32..0983e64 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -1672,15 +1672,18 @@ function Sidebar:initialize() local buf_ft = api.nvim_get_option_value("filetype", { buf = self.code.bufnr }) if vim.list_contains(Config.selector.exclude_auto_select, buf_ft) then return self end - local buf_path = api.nvim_buf_get_name(self.code.bufnr) - -- if the filepath is outside of the current working directory then we want the absolute path - local filepath = Utils.file.is_in_project(buf_path) and Utils.relative_path(buf_path) or buf_path - Utils.debug("Sidebar:initialize adding buffer to file selector", buf_path) - self.file_selector:reset() - local stat = vim.uv.fs_stat(filepath) - if stat == nil or stat.type == "file" then self.file_selector:add_selected_file(filepath) end + -- Only auto-add current file if configured to do so + if Config.behaviour.auto_add_current_file then + local buf_path = api.nvim_buf_get_name(self.code.bufnr) + -- if the filepath is outside of the current working directory then we want the absolute path + local filepath = Utils.file.is_in_project(buf_path) and Utils.relative_path(buf_path) or buf_path + Utils.debug("Sidebar:initialize adding buffer to file selector", buf_path) + + local stat = vim.uv.fs_stat(filepath) + if stat == nil or stat.type == "file" then self.file_selector:add_selected_file(filepath) end + end self:reload_chat_history()