Skip to content

Commit 0ed06a6

Browse files
authored
refactor(utils): re-order and remove func (#2581)
Co-authored-by: Oli Morris <[email protected]>
1 parent 24a48e4 commit 0ed06a6

File tree

4 files changed

+11
-41
lines changed

4 files changed

+11
-41
lines changed

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,20 +179,17 @@ local function create_diff_floating_window(bufnr, path)
179179

180180
local _, winnr = ui_utils.create_float(content, {
181181
bufnr = bufnr,
182-
set_content = false, -- Don't overwrite existing buffer content
183-
window = { width = window_config.width, height = window_config.height },
184182
row = window_config.row,
185183
col = window_config.col,
186-
relative = window_config.relative,
187184
filetype = filetype,
188-
title = ui_utils.build_float_title({
189-
title_prefix = " Diff",
190-
path = path,
191-
}),
192-
lock = false, -- Allow edits for diff
193185
ignore_keymaps = true,
186+
lock = false, -- Allow edits for diff
194187
opts = window_config.opts,
188+
overwrite_buffer = false,
189+
relative = window_config.relative,
195190
show_dim = show_dim,
191+
title = " Diff: " .. (path and vim.fs.relpath(vim.uv.cwd(), vim.fs.normalize(path)) or "[No Name]") .. " ",
192+
window = { width = window_config.width, height = window_config.height },
196193
})
197194

198195
return winnr

lua/codecompanion/utils/ui.lua

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ M.create_float = function(lines, opts)
9696
zindex = opts.show_dim and 99 or nil, -- When dimming, set above background win but below notifications
9797
})
9898

99-
-- Only set content if we created a new buffer OR if not explicitly disabled
100-
if not opts.bufnr or opts.set_content ~= false then
99+
if not opts.bufnr or opts.overwrite_buffer ~= false then
101100
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
102101
end
103102

@@ -137,25 +136,6 @@ M.create_float = function(lines, opts)
137136
return bufnr, winnr
138137
end
139138

140-
---Build a floating window title with smart path handling
141-
---@param opts { title?: string, title_prefix?: string, path?: string }
142-
---@return string title The formatted title
143-
function M.build_float_title(opts)
144-
opts = opts or {}
145-
local title = opts.title or opts.title_prefix or "CodeCompanion"
146-
147-
if opts.path then
148-
local ok, relative_path = pcall(function()
149-
return vim.fs.relpath(vim.uv.cwd(), vim.fs.normalize(opts.path))
150-
end)
151-
local path_to_use = (ok and relative_path and relative_path ~= "") and relative_path or opts.path
152-
153-
title = " " .. (opts.title_prefix or " Diff") .. ": " .. path_to_use .. " "
154-
end
155-
156-
return title
157-
end
158-
159139
---@param bufnr number
160140
---@param ns_id number
161141
---@param message string

tests/interactions/chat/acp/test_permission_request.lua

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,6 @@ local function with_mocks(opts)
119119
})
120120
return w
121121
end,
122-
build_float_title = function(opts)
123-
opts = opts or {}
124-
if opts.path then
125-
return (opts.title_prefix or "Test") .. ": " .. vim.fn.fnamemodify(opts.path, ":t")
126-
end
127-
return opts.title or opts.title_prefix or "Test"
128-
end
129122
}
130123
131124
-- Mock wait helper

tests/utils/test_ui.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ T["UI create_float Screenshots"]["Uses existing buffer without overwriting conte
8686
})
8787
vim.bo[existing_bufnr].filetype = "lua"
8888
89-
-- Use create_float with existing buffer and set_content = false
89+
-- Use create_float with existing buffer and overwrite_buffer = false
9090
local dummy_lines = {"This should not appear", "These lines ignored"}
9191
9292
local bufnr, winnr = ui.create_float(dummy_lines, {
9393
bufnr = existing_bufnr,
94-
set_content = false,
95-
window = { width = 45, height = 8 },
9694
row = "center",
9795
col = "center",
96+
overwrite_buffer = false,
9897
relative = "editor",
99-
title = "Existing Buffer Test",
10098
show_dim = true,
99+
title = "Existing Buffer Test",
100+
window = { width = 45, height = 8 },
101101
})
102102
103103
-- Verify existing content was preserved
@@ -144,7 +144,7 @@ T["UI create_float Screenshots"]["Uses existing buffer with content overwrite (d
144144
-- Use create_float with existing buffer (debug.lua pattern)
145145
local bufnr, winnr = ui.create_float(new_debug_lines, {
146146
bufnr = existing_bufnr,
147-
-- set_content is not specified, so defaults to true
147+
-- overwrite_buffer is not specified, so defaults to true
148148
window = { width = 55, height = 16 },
149149
row = "center",
150150
col = "center",

0 commit comments

Comments
 (0)