Skip to content

Commit

Permalink
refactor(context): extract buffer list logic to new function
Browse files Browse the repository at this point in the history
Move buffer list filtering logic from config.lua to a new dedicated function
`buffers()` in context.lua for better code organization and reusability.
  • Loading branch information
deathbeam committed Nov 30, 2024
1 parent d0e0c83 commit 63f101e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
9 changes: 1 addition & 8 deletions lua/CopilotChat/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,7 @@ return {
end,
resolve = function(input)
input = input or 'listed'
return vim.tbl_map(
context.buffer,
vim.tbl_filter(function(b)
return utils.buf_valid(b)
and vim.fn.buflisted(b) == 1
and (input == 'listed' or #vim.fn.win_findbuf(b) > 0)
end, vim.api.nvim_list_bufs())
)
return context.buffers(input)
end,
},
file = {
Expand Down
16 changes: 16 additions & 0 deletions lua/CopilotChat/context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,22 @@ function M.buffer(bufnr)
)
end

--- Get content of all buffers
---@param buf_type string
---@return table<CopilotChat.context.embed>
function M.buffers(buf_type)
async.util.scheduler()

return vim.tbl_map(
M.buffer,
vim.tbl_filter(function(b)
return utils.buf_valid(b)
and vim.fn.buflisted(b) == 1
and (buf_type == 'listed' or #vim.fn.win_findbuf(b) > 0)
end, vim.api.nvim_list_bufs())
)
end

--- Get the content of an URL
---@param url string
---@return CopilotChat.context.embed?
Expand Down

0 comments on commit 63f101e

Please sign in to comment.