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

Feature: Implement actions for sending oil entries to quickfix #249

Merged
merged 6 commits into from
Dec 8, 2023
Merged

Feature: Implement actions for sending oil entries to quickfix #249

merged 6 commits into from
Dec 8, 2023

Conversation

lpoto
Copy link
Contributor

@lpoto lpoto commented Dec 6, 2023

Closes #223 .

Exposes actions:

  • actions.send_to_qflist: Sends files from current oil dir to quickfix and replaces old entries
  • actions.add_to_qflist: Sends files from current oil dir to quickfix and keeps old entries
  • actions.send_to_loclist: Sends files from current oil dir to location list and replaces old entries
  • actions.add_to_loclist: Sends files from current oil dir to location list and keeps old entries

The quickfix actions trigger QuickFixCmdPre and QuickFixCmdPost autocommands.

The actions do not open the quickfix window, since you may create an autocmd to open it automatically on QuickFixCmdPost.

@lpoto lpoto changed the title Feature: Implement actions for sending oil entries to quickfix #223 Feature: Implement actions for sending oil entries to quickfix Dec 6, 2023
Copy link
Owner

@stevearc stevearc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Left a few comments. Please re-request review when you're ready for me to take another look

@@ -697,4 +697,54 @@ M.adapter_list_all = function(adapter, url, opts, callback)
end)
end

M.send_to_quickfix = function(opts)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a type annotation for opts? It helps document what the available options are, and provides some type safety. You may also want to include some default values, or make the type non-nilable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It now defaults to replacing items in the quickfix list.

lua/oil/util.lua Outdated
Comment on lines 740 to 746
if opts.target == "loclist" then
vim.fn.setloclist(0, qf_entries, opts.mode)
vim.fn.setloclist(0, {}, "a", { title = qf_title })
else
vim.fn.setqflist(qf_entries, opts.mode)
vim.fn.setqflist({}, "a", { title = qf_title })
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can achieve this with a single call to setloclist/setqflist

vim.fn.setqflist({}, opts.mode, { title = qf_title, items = qf_entries })

lua/oil/util.lua Outdated
Comment on lines 711 to 728
for i = 1, vim.fn.line("$") do
local entry = oil.get_entry_on_line(0, i)
if
entry
and (
entry.type == "file" and opts.files ~= false
or entry.type == "directory" and opts.directories ~= false
)
then
local qf_entry = {
filename = dir .. entry.name,
lnum = 1,
col = 1,
text = entry.name,
}
table.insert(qf_entries, qf_entry)
end
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it adds every entry in the buffer to the quickfix. Maybe we should detect if we're in visual mode and only add the selected entries?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only sends selected items when in visual mode now. I reused the logic you implemented in lua/oil/init.lua:459 and gathered it in get_visual_range function in util module.

Comment on lines 344 to 345
directories = false,
files = true,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that directories = true is going to function correctly with the given logic, but if we don't have an immediate use for these parameters (seems like it's always directories = false and files = true), then I'd err on the side of removing them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to always send only files. It could function with directories aswell, but I agree that there aren't any real use cases for having directories in the quickfix.

lua/oil/util.lua Outdated
end
end
if #qf_entries == 0 then
vim.notify_once("[oil] No entries found to send to quickfix", vim.log.levels.ERROR)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a regular vim.notify

@lpoto lpoto requested a review from stevearc December 7, 2023 10:07
@stevearc
Copy link
Owner

stevearc commented Dec 8, 2023

Looks good, thanks!

@stevearc stevearc merged commit 3ffb830 into stevearc:master Dec 8, 2023
7 checks passed
@lpoto lpoto deleted the feature/quickfix-actions branch December 8, 2023 12:41
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

Successfully merging this pull request may close these issues.

feature request: sending items to quickfix
2 participants