From a663398418ffad1ef51ad646a65bf38740def51e Mon Sep 17 00:00:00 2001 From: Oli Morris Date: Wed, 25 Mar 2026 21:49:54 +0000 Subject: [PATCH 1/5] wip --- doc/codecompanion.txt | 10 ++++++++-- doc/configuration/chat-buffer.md | 8 +++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/doc/codecompanion.txt b/doc/codecompanion.txt index d49d8a255..201bb678c 100644 --- a/doc/codecompanion.txt +++ b/doc/codecompanion.txt @@ -1,4 +1,4 @@ -*codecompanion.txt* For NVIM v0.11 Last change: 2026 March 24 +*codecompanion.txt* For NVIM v0.11 Last change: 2026 March 25 ============================================================================== Table of Contents *codecompanion-table-of-contents* @@ -1980,7 +1980,13 @@ plugin. If you utilize the `insert_edit_into_file` tool or use an ACP adapter, then the plugin will update files and buffers, displaying the changes in a floating window. -There are a number of configuration option available to you: +For small changes, the diff is shown inline in the chat buffer. This can be +controlled by the `inline_threshold`, which corresponds to the size of the diff +in terms of changed lines. For larger changes, the diff will automatically open +in a floating window when the chat buffer is active. Or, you will be prompted +to view the diff manually (`gv` by default). + +There are a number of configuration options available to you: diff --git a/doc/configuration/chat-buffer.md b/doc/configuration/chat-buffer.md index e8c8bac11..9940df334 100644 --- a/doc/configuration/chat-buffer.md +++ b/doc/configuration/chat-buffer.md @@ -209,7 +209,9 @@ vim.api.nvim_create_autocmd("User", { CodeCompanion has a built-in diff engine that's leveraged throughout the plugin. If you utilize the `insert_edit_into_file` tool or use an ACP adapter, then the plugin will update files and buffers, displaying the changes in a floating window. -There are a number of configuration option available to you: +For small changes, the diff is shown inline in the chat buffer. This can be controlled by the `inline_threshold`, which corresponds to the size of the diff in terms of changed lines. For larger changes, the diff will automatically open in a floating window when the chat buffer is active. Or, you will be prompted to view the diff manually (`gv` by default). + +There are a number of configuration options available to you: ::: code-group @@ -218,6 +220,10 @@ require("codecompanion").setup({ display = { diff = { enabled = true, + + -- At or below this diff size, always display the diff in the chat buffer + inline_threshold = 6, + word_highlights = { additions = true, deletions = true, From 366edf46586efcc36f47f3e8a871220fc7d45a99 Mon Sep 17 00:00:00 2001 From: Oli Morris Date: Wed, 25 Mar 2026 21:50:21 +0000 Subject: [PATCH 2/5] wip --- tests/interactions/chat/acp/test_permission_request.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/interactions/chat/acp/test_permission_request.lua b/tests/interactions/chat/acp/test_permission_request.lua index f9feb608f..f84ba9f38 100644 --- a/tests/interactions/chat/acp/test_permission_request.lua +++ b/tests/interactions/chat/acp/test_permission_request.lua @@ -178,7 +178,10 @@ T["diff flow -> approval prompt shows view option"] = function() return _G.__approval_opts ]]) - h.eq("View Proposed Edits", result.title) + -- Small diff triggers inline mode with "Proposed Edits" title + h.eq("Proposed Edits", result.title) + -- Inline diff text is included in the prompt + h.eq(true, result.prompt:find("diff") ~= nil) h.eq("gv", result.choice_keys[1]) h.eq("View", result.choice_labels[1]) h.eq("Always accept", result.choice_labels[2]) From 5114340a122aa6458f69f1ccd6baa12f72884e2d Mon Sep 17 00:00:00 2001 From: Oli Morris Date: Wed, 25 Mar 2026 21:50:23 +0000 Subject: [PATCH 3/5] wip --- lua/codecompanion/config.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/codecompanion/config.lua b/lua/codecompanion/config.lua index 18ba5ac14..6ff9d5d31 100644 --- a/lua/codecompanion/config.lua +++ b/lua/codecompanion/config.lua @@ -1120,6 +1120,8 @@ The user is working on a %s machine. Please respond with system specific command diff = { enabled = true, + inline_threshold = 6, -- At or below this, always display the diff in the chat buffer + -- Options for any diff windows (extends from floating_window) window = { opts = {}, From be99391c938678c271e93fbaeb256649f760c4c6 Mon Sep 17 00:00:00 2001 From: Oli Morris Date: Thu, 26 Mar 2026 07:32:01 +0000 Subject: [PATCH 4/5] wip --- CLAUDE.md | 3 +- lua/codecompanion/diff/utils.lua | 31 ++++ .../chat/acp/request_permission.lua | 154 ++++++++++------ .../builtin/insert_edit_into_file/diff.lua | 168 +++++++++++------- .../builtin/insert_edit_into_file/init.lua | 6 +- 5 files changed, 243 insertions(+), 119 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 4a51a67d8..a1add9052 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -13,9 +13,10 @@ Neovim plugin (Lua) providing LLM-powered coding assistance: chat, inline transf - **Naming:** snake_case for files/functions, PascalCase for classes, underscore prefix for private functions - **Explicit names:** `pattern` not `pat`, `should_include` not `include_ok` +- **Readable code:** names, variables, and control flow should read like clean English. Prefer `threshold_met` over a long inline condition. Avoid generic names like `ctx` — use domain-specific names (`permission`, `request`, `source`) - **Function params:** prefer a single table argument over positional args - **Error handling:** `pcall` + `log:error()`, return nil on failure -- **Type annotations:** LuaCATS for public APIs +- **Type annotations:** LuaCATS for public APIs. Keep doc blocks concise — one description line, params should be self-explanatory without inline comments - **Functions:** keep under 50 lines - **Globals:** avoid; use module-local state - **Code blocks:** use four backticks with language spec diff --git a/lua/codecompanion/diff/utils.lua b/lua/codecompanion/diff/utils.lua index 688bb4d2f..4c007b37c 100644 --- a/lua/codecompanion/diff/utils.lua +++ b/lua/codecompanion/diff/utils.lua @@ -234,4 +234,35 @@ function M.split_words(str) return ret end +---Count the number of changed lines (additions + deletions) +---@param from_lines string[] +---@param to_lines string[] +---@return number +function M.changed_lines(from_lines, to_lines) + local hunks = require("codecompanion.diff")._diff(from_lines, to_lines) + + local count = 0 + for _, hunk in ipairs(hunks) do + count = count + hunk[2] + hunk[4] + end + + return count +end + +---Generate a unified diff string suitable for inline display +---@param from_lines string[] +---@param to_lines string[] +---@return string +function M.unified(from_lines, to_lines) + ---@diagnostic disable-next-line: deprecated + local diff_fn = vim.text.diff or vim.diff + local result = + diff_fn(table.concat(from_lines, "\n"), table.concat(to_lines, "\n"), { result_type = "unified", ctxlen = 3 }) + + -- Strip the newline marker + result = (result or ""):gsub("\n?\\ No newline at end of file%s*", ""):gsub("\n$", "") + + return result +end + return M diff --git a/lua/codecompanion/interactions/chat/acp/request_permission.lua b/lua/codecompanion/interactions/chat/acp/request_permission.lua index 905549cb5..2edcd1d35 100644 --- a/lua/codecompanion/interactions/chat/acp/request_permission.lua +++ b/lua/codecompanion/interactions/chat/acp/request_permission.lua @@ -1,8 +1,13 @@ +local config = require("codecompanion.config") +local diff_utils = require("codecompanion.diff.utils") local log = require("codecompanion.utils.log") +local ui_utils = require("codecompanion.utils.ui") local utils = require("codecompanion.utils") local labels = require("codecompanion.interactions.chat.tools.labels") +local fmt = string.format + ---Ref: https://agentclientprotocol.com/protocol/schema#permissionoptionkind local ACP_OPTIONS = { allow_once = { label = labels.accept, keymap = "accept" }, @@ -14,10 +19,10 @@ local ACP_OPTIONS = { local M = {} ---Find the first reject option from the request options ----@param options table +---@param opts table ---@return string|nil optionId -local function find_reject_option(options) - for _, opt in ipairs(options or {}) do +local function find_reject_option(opts) + for _, opt in ipairs(opts or {}) do if opt.kind:find("^reject", 1, true) then return opt.optionId end @@ -26,11 +31,11 @@ local function find_reject_option(options) end ---Build a map of kind -> optionId for easy lookup ----@param options table +---@param opts table ---@return table kind -> optionId -local function build_kind_map(options) +local function build_kind_map(opts) local map = {} - for _, opt in ipairs(options or {}) do + for _, opt in ipairs(opts or {}) do if type(opt.kind) == "string" and type(opt.optionId) == "string" then map[opt.kind] = opt.optionId end @@ -40,7 +45,7 @@ end ---Get the shared keymap key for an ACP option kind ---@param kind string ----@param keys table Resolved keymaps from labels.keymaps() +---@param keys table ---@return string|nil local function key_for_kind(kind, keys) local opt = ACP_OPTIONS[kind] @@ -51,8 +56,8 @@ local function key_for_kind(kind, keys) end ---Build the banner displayed in the diff window winbar ----@param kind_map table kind -> optionId ----@param keys table Resolved keymaps from labels.keymaps() +---@param kind_map table +---@param keys table ---@return string local function build_banner(kind_map, keys) local parts = {} @@ -63,11 +68,11 @@ local function build_banner(kind_map, keys) local lhs = key_for_kind(kind, keys) if lhs then local label = (ACP_OPTIONS[kind] and ACP_OPTIONS[kind].label) or kind:gsub("_", " ") - table.insert(parts, string.format("%s %s", lhs, label)) + table.insert(parts, fmt("%s %s", lhs, label)) end end - table.insert(parts, string.format("%s/%s Next/Prev", keys.next_hunk, keys.previous_hunk)) + table.insert(parts, fmt("%s/%s Next/Prev", keys.next_hunk, keys.previous_hunk)) table.insert(parts, "q Close") return table.concat(parts, " | ") @@ -150,28 +155,26 @@ local function setup_diff_keymaps(opts) }) end ----Display the diff preview and resolve permission by user decision ----@param opts { chat: CodeCompanion.Chat, request: table, on_done: fun(choice_label: string) } ----@return nil -local function show_diff(opts) - local d = get_diff(opts.request.tool_call) +---Open the floating diff view for an ACP permission request +---@param permission table +local function open_diff_view(permission) + local d = get_diff(permission.request.tool_call) - local diff_id = math.random(1000000) - local kind_map = build_kind_map(opts.request.options) + local kind_map = build_kind_map(permission.request.options) local keys = labels.keymaps() local diff_ui = require("codecompanion.helpers").show_diff({ from_lines = vim.split(d.old or "", "\n", { plain = true }), to_lines = vim.split(d.new or "", "\n", { plain = true }), banner = build_banner(kind_map, keys), - chat_bufnr = opts.chat.bufnr, - diff_id = diff_id, + chat_bufnr = permission.chat.bufnr, + diff_id = math.random(1000000), ft = vim.filetype.match({ filename = d.path }) or "text", keymaps = { on_reject = function() - opts.on_done(labels.reject) - local rejected = find_reject_option(opts.request.options) - opts.request.respond(rejected, false) + permission.on_done(labels.reject) + local rejected = find_reject_option(permission.request.options) + permission.request.respond(rejected, false) end, }, skip_default_keymaps = true, @@ -182,32 +185,19 @@ local function show_diff(opts) diff_ui = diff_ui, kind_map = kind_map, keys = keys, - request = opts.request, - on_done = opts.on_done, + request = permission.request, + on_done = permission.on_done, }) end ----Show the permission request to the user and handle their response ----@param chat CodeCompanion.Chat ----@param request table ----@return nil -function M.confirm(chat, request) - local approval_prompt = require("codecompanion.interactions.chat.helpers.approval_prompt") - - local tool_call = request.tool_call - local prompt = string.format( - "%s: %s", - utils.capitalize(tool_call and tool_call.kind or "Permission"), - tool_call and tool_call.title or "Agent requested permission" - ) - - local has_diff = request.tool_call and requires_diff(request.tool_call) +---Build the approval choices for an ACP permission request +---@param permission table +---@param has_diff boolean +---@return CodeCompanion.Chat.ApprovalChoice[] +local function build_choices(permission, has_diff) local keys = labels.keymaps() - local choices = {} - local on_done - if has_diff then table.insert(choices, { keymap = keys.view, @@ -215,12 +205,12 @@ function M.confirm(chat, request) preview = true, callback = function() log:debug("[acp::request_permission] Opening diff for review") - show_diff({ chat = chat, request = request, on_done = on_done }) + open_diff_view(permission) end, }) end - for _, opt in ipairs(request.options or {}) do + for _, opt in ipairs(permission.request.options or {}) do local key = key_for_kind(opt.kind, keys) if key then table.insert(choices, { @@ -228,7 +218,7 @@ function M.confirm(chat, request) label = (ACP_OPTIONS[opt.kind] and ACP_OPTIONS[opt.kind].label) or opt.name, callback = function() log:debug("[acp::request_permission] User selected option %s", opt.optionId) - request.respond(opt.optionId, false) + permission.request.respond(opt.optionId, false) end, }) end @@ -239,17 +229,77 @@ function M.confirm(chat, request) label = labels.cancel, callback = function() log:debug("[acp::request_permission] User cancelled") - request.respond(nil, true) + permission.request.respond(nil, true) end, }) - on_done = approval_prompt.request(chat, { - id = request.id, - name = tool_call and tool_call.kind or nil, - title = has_diff and "View Proposed Edits" or nil, - prompt = prompt, + return choices +end + +---Allow the user to approve from within the chat buffer +---@param permission table +---@param choices CodeCompanion.Chat.ApprovalChoice[] +---@param prompt_opts { title?: string, prompt: string } +local function approve_in_chat(permission, choices, prompt_opts) + local approval_prompt = require("codecompanion.interactions.chat.helpers.approval_prompt") + permission.on_done = approval_prompt.request(permission.chat, { choices = choices, + id = permission.request.id, + name = permission.request.tool_call and permission.request.tool_call.kind or nil, + prompt = prompt_opts.prompt, + title = prompt_opts.title, }) end +---Show the permission request to the user and handle their response +---@param chat CodeCompanion.Chat +---@param request table +---@return nil +function M.confirm(chat, request) + local tool_call = request.tool_call + local has_diff = tool_call and requires_diff(tool_call) + + local base_prompt = fmt( + "%s: %s", + utils.capitalize(tool_call and tool_call.kind or "Permission"), + tool_call and tool_call.title or "Agent requested permission" + ) + + local permission = { chat = chat, request = request } + local choices = build_choices(permission, has_diff) + + if not has_diff then + return approve_in_chat(permission, choices, { prompt = base_prompt }) + end + + local d = get_diff(tool_call) + local from_lines = vim.split(d.old or "", "\n", { plain = true }) + local to_lines = vim.split(d.new or "", "\n", { plain = true }) + local changed_lines = diff_utils.changed_lines(from_lines, to_lines) + local threshold = config.display.diff.inline_threshold + local threshold_met = threshold and threshold > 0 and changed_lines > 0 and changed_lines <= threshold + + if threshold_met then + -- Show small diffs in the chat buffer + local diff_text = diff_utils.unified(from_lines, to_lines) + local prompt = fmt( + [[%s + +`````diff +%s +`````]], + base_prompt, + diff_text + ) + return approve_in_chat(permission, choices, { title = "Proposed Edits", prompt = prompt }) + elseif ui_utils.buf_is_active(chat.bufnr) then + -- If the chat is active, show the diff in the floating window + approve_in_chat(permission, choices, { title = "View Proposed Edits", prompt = base_prompt }) + return open_diff_view(permission) + else + -- Otherwise, don't force the diff on the user, just show the approval + return approve_in_chat(permission, choices, { title = "View Proposed Edits", prompt = base_prompt }) + end +end + return M diff --git a/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/diff.lua b/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/diff.lua index 44770c5d7..812f69bd9 100644 --- a/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/diff.lua +++ b/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/diff.lua @@ -1,5 +1,6 @@ local approvals = require("codecompanion.interactions.chat.tools.approvals") local config = require("codecompanion.config") +local diff_utils = require("codecompanion.diff.utils") local ui_utils = require("codecompanion.utils.ui") local fmt = string.format @@ -14,7 +15,7 @@ local function make_response(status, msg) return { status = status, data = msg } end ----Prompt user for rejection reason +---Prompt the user for a rejection reason ---@param callback function local function get_rejection_reason(callback) ui_utils.input({ prompt = "Rejection reason" }, function(input) @@ -22,16 +23,15 @@ local function get_rejection_reason(callback) end) end ----Open the diff UI with accept/reject/always_accept keymaps +---Open the floating diff view with associated keymaps ---@param opts table -local function show_diff(opts) - local diff_id = math.random(10000000) +local function open_diff_view(opts) local diff_helpers = require("codecompanion.helpers") local labels = require("codecompanion.interactions.chat.tools.labels") diff_helpers.show_diff({ chat_bufnr = opts.chat_bufnr, - diff_id = diff_id, + diff_id = math.random(10000000), ft = opts.ft, from_lines = opts.from_lines, to_lines = opts.to_lines, @@ -39,15 +39,21 @@ local function show_diff(opts) tool_name = "insert_edit_into_file", keymaps = { on_always_accept = function() - opts.on_done(labels.always_accept) + if opts.on_done then + opts.on_done(labels.always_accept) + end approvals:always(opts.chat_bufnr, { tool_name = "insert_edit_into_file" }) end, on_accept = function() - opts.on_done(labels.accept) - opts.apply_fn() + if opts.on_done then + opts.on_done(labels.accept) + end + opts.apply() end, on_reject = function() - opts.on_done(labels.reject) + if opts.on_done then + opts.on_done(labels.reject) + end get_rejection_reason(function(reason) local msg = fmt('User rejected the edits for `%s`, with the reason "%s"', opts.title, reason) opts.output_cb(make_response("error", msg)) @@ -57,69 +63,105 @@ local function show_diff(opts) }) end +---Build out the choices that users have with respect to the diff and approval flow +---@param opts table +---@return CodeCompanion.Chat.ApprovalChoice[] +local function build_approval_choices(opts) + local labels = require("codecompanion.interactions.chat.tools.labels") + local keys = labels.keymaps() + + return { + { + keymap = keys.view, + label = labels.view, + preview = true, + callback = function() + open_diff_view(opts) + end, + }, + { + keymap = keys.always_accept, + label = labels.always_accept, + callback = function() + approvals:always(opts.chat_bufnr, { tool_name = "insert_edit_into_file" }) + opts.apply() + end, + }, + { + keymap = keys.accept, + label = labels.accept, + callback = function() + opts.apply() + end, + }, + { + keymap = keys.reject, + label = labels.reject, + callback = function() + get_rejection_reason(function(reason) + local msg = fmt('User rejected the edits for `%s`, with the reason "%s"', opts.title, reason) + opts.output_cb(make_response("error", msg)) + end) + end, + }, + { + keymap = keys.cancel, + label = labels.cancel, + callback = function() + opts.output_cb(make_response("error", fmt("User cancelled the edits for `%s`", opts.title))) + end, + }, + } +end + +---Allow the user to approve from within the chat buffer +---@param chat CodeCompanion.Chat +---@param opts table +local function approve_in_chat(chat, opts) + local approval_prompt = require("codecompanion.interactions.chat.helpers.approval_prompt") + opts.on_done = approval_prompt.request(chat, { + choices = build_approval_choices(opts), + prompt = opts.prompt, + title = opts.title, + }) +end + ---Show diff and handle approval flow for edits ---@param opts table ---@return any -function M.approve_and_diff(opts) +function M.review(opts) local diff_enabled = config.display.diff.enabled == true if opts.approved or diff_enabled == false or opts.require_confirmation_after == false then - return opts.apply_fn() + return opts.apply() end - local approval_prompt = require("codecompanion.interactions.chat.helpers.approval_prompt") - local labels = require("codecompanion.interactions.chat.tools.labels") - local keys = labels.keymaps() + local changed_lines = diff_utils.changed_lines(opts.from_lines, opts.to_lines) + local threshold = config.display.diff.inline_threshold + local threshold_met = threshold and threshold > 0 and changed_lines > 0 and changed_lines <= threshold - local on_done - - on_done = approval_prompt.request(opts.chat, { - title = "View Proposed Edits", - prompt = opts.title, - choices = { - { - keymap = keys.view, - label = labels.view, - preview = true, - callback = function() - opts.on_done = on_done - show_diff(opts) - end, - }, - { - keymap = keys.always_accept, - label = labels.always_accept, - callback = function() - approvals:always(opts.chat_bufnr, { tool_name = "insert_edit_into_file" }) - opts.apply_fn() - end, - }, - { - keymap = keys.accept, - label = labels.accept, - callback = function() - opts.apply_fn() - end, - }, - { - keymap = keys.reject, - label = labels.reject, - callback = function() - get_rejection_reason(function(reason) - local msg = fmt('User rejected the edits for `%s`, with the reason "%s"', opts.title, reason) - opts.output_cb(make_response("error", msg)) - end) - end, - }, - { - keymap = keys.cancel, - label = labels.cancel, - callback = function() - opts.output_cb(make_response("error", fmt("User cancelled the edits for `%s`", opts.title))) - end, - }, - }, - }) + if threshold_met then + -- Show small diffs in the chat buffer + local diff_text = diff_utils.unified(opts.from_lines, opts.to_lines) + opts.title = "Proposed Edits" + opts.prompt = fmt("`%s`\n\n`````diff\n%s\n`````", opts.title, diff_text) + + return approve_in_chat(opts.chat, opts) + elseif ui_utils.buf_is_active(opts.chat_bufnr) then + -- If the chat is active, show the diff in the floating window + opts.title = "View Proposed Edits" + opts.prompt = opts.title + approve_in_chat(opts.chat, opts) + + opts.title = opts.title + return open_diff_view(opts) + else + -- Otherwise, don't force the diff on the user, just show the approval + opts.title = "View Proposed Edits" + opts.prompt = opts.title + + return approve_in_chat(opts.chat, opts) + end end return M diff --git a/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/init.lua b/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/init.lua index 1e5b76946..4de4feeb5 100644 --- a/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/init.lua +++ b/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/init.lua @@ -28,7 +28,7 @@ local Path = require("plenary.path") local approvals = require("codecompanion.interactions.chat.tools.approvals") local constants = require("codecompanion.interactions.chat.tools.builtin.insert_edit_into_file.constants") -local diff_mod = require("codecompanion.interactions.chat.tools.builtin.insert_edit_into_file.diff") +local diff = require("codecompanion.interactions.chat.tools.builtin.insert_edit_into_file.diff") local io_mod = require("codecompanion.interactions.chat.tools.builtin.insert_edit_into_file.io") local json_repair = require("codecompanion.interactions.chat.tools.builtin.insert_edit_into_file.json_repair") local match_selector = require("codecompanion.interactions.chat.tools.builtin.insert_edit_into_file.match_selector") @@ -161,10 +161,10 @@ local function execute_edit(source, action, opts) local success_msg = fmt("Edited `%s`%s", source.display_name, extract_explanation(action)) - return diff_mod.approve_and_diff({ + return diff.review({ from_lines = vim.split(source.content, "\n", { plain = true }), to_lines = vim.split(edit.content, "\n", { plain = true }), - apply_fn = function() + apply = function() local write_ok, write_err = source.write(edit.content) if not write_ok then return opts.output_cb(make_response("error", fmt("Error writing to `%s`: %s", source.display_name, write_err))) From cbb0235edfca79f6e7d705b57f09afad3536d9aa Mon Sep 17 00:00:00 2001 From: Oli Morris Date: Thu, 26 Mar 2026 07:36:19 +0000 Subject: [PATCH 5/5] wip --- doc/codecompanion.txt | 6 +++--- doc/configuration/chat-buffer.md | 4 ++-- lua/codecompanion/config.lua | 2 +- .../interactions/chat/acp/request_permission.lua | 2 +- .../chat/tools/builtin/insert_edit_into_file/diff.lua | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/doc/codecompanion.txt b/doc/codecompanion.txt index 201bb678c..555650aa2 100644 --- a/doc/codecompanion.txt +++ b/doc/codecompanion.txt @@ -1,4 +1,4 @@ -*codecompanion.txt* For NVIM v0.11 Last change: 2026 March 25 +*codecompanion.txt* For NVIM v0.11 Last change: 2026 March 26 ============================================================================== Table of Contents *codecompanion-table-of-contents* @@ -1980,8 +1980,8 @@ plugin. If you utilize the `insert_edit_into_file` tool or use an ACP adapter, then the plugin will update files and buffers, displaying the changes in a floating window. -For small changes, the diff is shown inline in the chat buffer. This can be -controlled by the `inline_threshold`, which corresponds to the size of the diff +For small changes, the diff is shown directly in the chat buffer. This can be +controlled by `threshold_for_chat`, which corresponds to the size of the diff in terms of changed lines. For larger changes, the diff will automatically open in a floating window when the chat buffer is active. Or, you will be prompted to view the diff manually (`gv` by default). diff --git a/doc/configuration/chat-buffer.md b/doc/configuration/chat-buffer.md index 9940df334..38c37f4c6 100644 --- a/doc/configuration/chat-buffer.md +++ b/doc/configuration/chat-buffer.md @@ -209,7 +209,7 @@ vim.api.nvim_create_autocmd("User", { CodeCompanion has a built-in diff engine that's leveraged throughout the plugin. If you utilize the `insert_edit_into_file` tool or use an ACP adapter, then the plugin will update files and buffers, displaying the changes in a floating window. -For small changes, the diff is shown inline in the chat buffer. This can be controlled by the `inline_threshold`, which corresponds to the size of the diff in terms of changed lines. For larger changes, the diff will automatically open in a floating window when the chat buffer is active. Or, you will be prompted to view the diff manually (`gv` by default). +For small changes, the diff is shown directly in the chat buffer. This can be controlled by `threshold_for_chat`, which corresponds to the size of the diff in terms of changed lines. For larger changes, the diff will automatically open in a floating window when the chat buffer is active. Or, you will be prompted to view the diff manually (`gv` by default). There are a number of configuration options available to you: @@ -222,7 +222,7 @@ require("codecompanion").setup({ enabled = true, -- At or below this diff size, always display the diff in the chat buffer - inline_threshold = 6, + threshold_for_chat = 6, word_highlights = { additions = true, diff --git a/lua/codecompanion/config.lua b/lua/codecompanion/config.lua index 6ff9d5d31..6328ab3e5 100644 --- a/lua/codecompanion/config.lua +++ b/lua/codecompanion/config.lua @@ -1120,7 +1120,7 @@ The user is working on a %s machine. Please respond with system specific command diff = { enabled = true, - inline_threshold = 6, -- At or below this, always display the diff in the chat buffer + threshold_for_chat = 6, -- At or below this, always display the diff in the chat buffer -- Options for any diff windows (extends from floating_window) window = { diff --git a/lua/codecompanion/interactions/chat/acp/request_permission.lua b/lua/codecompanion/interactions/chat/acp/request_permission.lua index 2edcd1d35..aef2925b4 100644 --- a/lua/codecompanion/interactions/chat/acp/request_permission.lua +++ b/lua/codecompanion/interactions/chat/acp/request_permission.lua @@ -276,7 +276,7 @@ function M.confirm(chat, request) local from_lines = vim.split(d.old or "", "\n", { plain = true }) local to_lines = vim.split(d.new or "", "\n", { plain = true }) local changed_lines = diff_utils.changed_lines(from_lines, to_lines) - local threshold = config.display.diff.inline_threshold + local threshold = config.display.diff.threshold_for_chat local threshold_met = threshold and threshold > 0 and changed_lines > 0 and changed_lines <= threshold if threshold_met then diff --git a/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/diff.lua b/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/diff.lua index 812f69bd9..870d5449d 100644 --- a/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/diff.lua +++ b/lua/codecompanion/interactions/chat/tools/builtin/insert_edit_into_file/diff.lua @@ -137,7 +137,7 @@ function M.review(opts) end local changed_lines = diff_utils.changed_lines(opts.from_lines, opts.to_lines) - local threshold = config.display.diff.inline_threshold + local threshold = config.display.diff.threshold_for_chat local threshold_met = threshold and threshold > 0 and changed_lines > 0 and changed_lines <= threshold if threshold_met then