Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(picker): add custom action to setqflist #1522

Open
S1M0N38 opened this issue Mar 7, 2025 · 1 comment
Open

feat(picker): add custom action to setqflist #1522

S1M0N38 opened this issue Mar 7, 2025 · 1 comment

Comments

@S1M0N38
Copy link

S1M0N38 commented Mar 7, 2025

The default action for vim.fn.setqflist is to create a new list.
From the help:

If {action} is not present or is set to ' ', then a new list
is created. The new quickfix list is added after the current
quickfix list in the stack and all the following lists are
freed.

It would be nice if

https://github.com/folke/snacks.nvim/blob/bc0630e43be5699bb94dadc302c0d21615421d93/lua/snacks/picker/actions.lua#L420C1-L444C4

let you specify a custom action while keeping the " " as default.

For example

---@param items snacks.picker.Item[]
---@param opts? {win?:number}
---@param action? string
local function setqflist(items, opts, action)
  local qf = {} ---@type vim.quickfix.entry[]
  for _, item in ipairs(items) do
    qf[#qf + 1] = {
      filename = Snacks.picker.util.path(item),
      bufnr = item.buf,
      lnum = item.pos and item.pos[1] or 1,
      col = item.pos and item.pos[2] + 1 or 1,
      end_lnum = item.end_pos and item.end_pos[1] or nil,
      end_col = item.end_pos and item.end_pos[2] + 1 or nil,
      text = item.line or item.comment or item.label or item.name or item.detail or item.text,
      pattern = item.search,
      valid = true,
    }
  end
  if opts and opts.win then
    vim.fn.setloclist(opts.win, qf, action or " ")
    vim.cmd("botright lopen")
  else
    vim.fn.setqflist(qf, action or " ")
    vim.cmd("botright copen")
  end
end

With the current <C-Q>, the user cannot add to the qflist items from different sources (e.g. diagnostic and buffer) to the same qflist. The same can be said for loclist.

@S1M0N38 S1M0N38 changed the title feat: add custom action to setqflist feat(picker): add custom action to setqflist Mar 7, 2025
@S1M0N38
Copy link
Author

S1M0N38 commented Mar 9, 2025

This issue was open before #1539.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant