Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lua/codecompanion/_extensions/history/pickers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

---@type table<CodeCompanion.History.Pickers, CodeCompanion.History.PickerSpec>
local picker_configs = {
mini = {
module = "mini",
},
telescope = {
module = "telescope",
},
Expand Down Expand Up @@ -52,7 +55,7 @@ end
---@return CodeCompanion.History.Pickers resolved picker name
local function get_history_picker()
-- Priority order for history pickers
local providers = { "telescope", "fzf-lua", "snacks" }
local providers = { "telescope", "fzf-lua", "snacks", "mini" }
return find_available_picker(providers, picker_configs, "default")
end

Expand Down
109 changes: 109 additions & 0 deletions lua/codecompanion/_extensions/history/pickers/mini.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---@class CodeCompanion.History.MiniPicker : CodeCompanion.History.DefaultPicker
local MiniPicker = setmetatable({}, {
__index = require("codecompanion._extensions.history.pickers.default"),
})
MiniPicker.__index = MiniPicker

function MiniPicker:browse()
local mini_pick = require("mini.pick")

local function get_selected_items()
local state = mini_pick.get_picker_state()
if not state then
return {}
end

if state.selection and #state.selection > 0 then
return state.selection
end

if state.current then
return { state.current }
end

return {}
end

local mappings = {
[self.config.keymaps.rename.n] = function()
local state = mini_pick.get_picker_state()
local item = state and state.current
if not item then
return
end
self.config.handlers.on_rename(item)
end,
[self.config.keymaps.rename.i] = function()
local state = mini_pick.get_picker_state()
local item = state and state.current
if not item then
return
end
self.config.handlers.on_rename(item)
end,
[self.config.keymaps.delete.n] = function()
local items = get_selected_items()
if #items == 0 then
return
end
self.config.handlers.on_delete(items)
end,
[self.config.keymaps.delete.i] = function()
local items = get_selected_items()
if #items == 0 then
return
end
self.config.handlers.on_delete(items)
end,
[self.config.keymaps.duplicate.n] = function()
local state = mini_pick.get_picker_state()
local item = state and state.current
if item and self.config.handlers.on_duplicate then
self.config.handlers.on_duplicate(item)
end
end,
[self.config.keymaps.duplicate.i] = function()
local state = mini_pick.get_picker_state()
local item = state and state.current
if item and self.config.handlers.on_duplicate then
self.config.handlers.on_duplicate(item)
end
end,
}

local source = {
name = self.config.title,
items = self.config.items,
show = function(item)
return self:format_entry(item)
end,
on_choice = function(item)
if item then
self.config.handlers.on_select(item)
end
end,
mappings = mappings,
}

local ok, err = pcall(mini_pick.start, {
source = source,
})

if not ok then
mini_pick.start({
source = self.config.title,
items = self.config.items,
show = function(item)
return self:format_entry(item)
end,
on_choice = function(item)
if item then
self.config.handlers.on_select(item)
end
end,
mappings = mappings,
})
end
end

return MiniPicker
2 changes: 1 addition & 1 deletion lua/codecompanion/_extensions/history/title_generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function TitleGenerator:_make_adapter_request(chat, prompt, callback)
if _adapter.handlers.chat_output then
result = _adapter.handlers.chat_output(_adapter, data)
else
result = adapters.call_handler(_adapter, "parse_chat", data)
result = adapters.call_handler(_adapter, "parse_chat", { data = data })
end
if result and result.status then
if result.status == CONSTANTS.STATUS_SUCCESS then
Expand Down