feat: Add option to disable auto-adding current file when opening new chat (#2764)

Co-authored-by: yetone <1206493+yetone@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
Copilot
2025-10-13 11:34:44 +08:00
committed by GitHub
parent f092bb3ec0
commit 60cb63cdd2
4 changed files with 14 additions and 7 deletions

View File

@@ -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: <provider/model>' 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

View File

@@ -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()