Skip to content

Commit fb2d596

Browse files
committed
wip
1 parent 9b8c7b1 commit fb2d596

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

lua/codecompanion/interactions/chat/helpers/diff.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ end
304304
---Create a diff for a buffer or file and set up keymaps
305305
---@param bufnr_or_path number|string The buffer number or file path to create diff for
306306
---@param diff_id number|string Unique identifier for this diff
307-
---@param opts? { chat_bufnr?: number, original_content: string[], set_keymaps?: boolean }
307+
---@param opts? { chat_bufnr?: number, original_content: string[], set_keymaps?: boolean, tool_name?: string }
308308
---@return table|nil diff The diff object, or nil if no diff was created
309309
function M.create(bufnr_or_path, diff_id, opts)
310310
opts = opts or {}
@@ -378,7 +378,7 @@ function M.setup_keymaps(diff, opts)
378378
.new({
379379
bufnr = diff.bufnr,
380380
callbacks = require("codecompanion.interactions.inline.keymaps"),
381-
data = { diff = diff },
381+
data = { bufnr = opts.chat_bufnr, diff = diff, tool_name = opts.tool_name },
382382
keymaps = inline_config.keymaps,
383383
})
384384
:set()

lua/codecompanion/interactions/chat/tools/approvals.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ function Approvals:is_approved(bufnr, args)
7474
return true
7575
end
7676

77-
return approvals[args.tool_name] == true
77+
if args and args.tool_name then
78+
return approvals[args.tool_name] == true
79+
end
80+
81+
return false
7882
end
7983

8084
---Toggle yolo mode for a given chat buffer

lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/init.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,10 @@ local function edit_file(action, chat_bufnr, output_handler, opts)
792792
end
793793

794794
local diff_id = math.random(10000000)
795-
local original_lines = vim.split(current_content, "\n", { plain = true })
796795
local should_diff = diff.create(path, diff_id, {
797796
chat_bufnr = chat_bufnr,
798-
original_content = original_lines,
797+
original_content = vim.split(current_content, "\n", { plain = true }),
798+
tool_name = "insert_edit_into_file",
799799
})
800800

801801
local final_success = success_response(fmt("Edited `%s` file%s", action.filepath, extract_explanation(action)))
@@ -892,6 +892,7 @@ local function edit_buffer(bufnr, chat_bufnr, action, output_handler, opts)
892892
local should_diff = diff.create(bufnr, diff_id, {
893893
chat_bufnr = chat_bufnr,
894894
original_content = original_content,
895+
tool_name = "insert_edit_into_file",
895896
})
896897

897898
local start_line = nil

lua/codecompanion/interactions/inline/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,15 +718,15 @@ function Inline:start_diff(original_content)
718718

719719
local approvals = require("codecompanion.interactions.chat.tools.approvals")
720720

721-
if approvals:is_approved(self.bufnr) or config.display.diff.enabled == false then
721+
if approvals:is_approved(self.bufnr, { tool_name = "inline" }) or config.display.diff.enabled == false then
722722
return self:reset()
723723
end
724724

725725
if self.classification.placement == "new" then
726726
return self:reset()
727727
end
728728

729-
self:set_keymaps(self.buffer_context.bufnr, { exclude_keymaps = { "stop" } })
729+
self:set_keymaps(self.buffer_context.bufnr, { tool_name = "inline", exclude_keymaps = { "stop" } })
730730

731731
local provider = config.display.diff.provider
732732
local ok, diff = pcall(require, "codecompanion.providers.diff." .. provider)

lua/codecompanion/interactions/inline/keymaps.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ M.reject_change = {
4040

4141
M.always_accept = {
4242
desc = "Accept and enable auto mode",
43-
callback = function(inline)
43+
callback = function(obj)
4444
local approvals = require("codecompanion.interactions.chat.tools.approvals")
45-
approvals:toggle_yolo_mode(inline.bufnr)
45+
approvals:always(obj.bufnr, { tool_name = obj.tool_name })
4646

47-
if inline.diff then
48-
log:trace("[Inline] Auto-accepting diff for id=%s", tostring(inline.id))
49-
inline.diff:accept()
50-
clear_map(config.interactions.inline.keymaps, inline.diff.bufnr)
47+
if obj.diff then
48+
log:trace("[Inline] Auto-accepting diff for id=%s", tostring(obj.id))
49+
obj.diff:accept()
50+
clear_map(config.interactions.inline.keymaps, obj.diff.bufnr)
5151
end
5252
end,
5353
}

0 commit comments

Comments
 (0)