-
Notifications
You must be signed in to change notification settings - Fork 141
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
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
lua/oil/actions.lua
Outdated
directories = false, | ||
files = true, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
always send just files
Looks good, thanks! |
Closes #223 .
Exposes actions:
actions.send_to_qflist
: Sends files from current oil dir to quickfix and replaces old entriesactions.add_to_qflist
: Sends files from current oil dir to quickfix and keeps old entriesactions.send_to_loclist
: Sends files from current oil dir to location list and replaces old entriesactions.add_to_loclist
: Sends files from current oil dir to location list and keeps old entriesThe quickfix actions trigger
QuickFixCmdPre
andQuickFixCmdPost
autocommands.The actions do not open the quickfix window, since you may create an autocmd to open it automatically on
QuickFixCmdPost
.