feat: send to loclist (#868)

This commit is contained in:
runiq
2021-05-31 08:47:05 +02:00
committed by GitHub
parent 654b11aa08
commit e659e3336f
2 changed files with 91 additions and 7 deletions

View File

@@ -489,7 +489,7 @@ local entry_to_qf = function(entry)
}
end
local send_selected_to_qf = function(prompt_bufnr, mode)
local send_selected_to_qf = function(prompt_bufnr, mode, target)
local picker = action_state.get_current_picker(prompt_bufnr)
local qf_entries = {}
@@ -499,10 +499,14 @@ local send_selected_to_qf = function(prompt_bufnr, mode)
actions.close(prompt_bufnr)
vim.fn.setqflist(qf_entries, mode)
if target == 'loclist' then
vim.fn.setloclist(picker.original_win_id, qf_entries, mode)
else
vim.fn.setqflist(qf_entries, mode)
end
end
local send_all_to_qf = function(prompt_bufnr, mode)
local send_all_to_qf = function(prompt_bufnr, mode, target)
local picker = action_state.get_current_picker(prompt_bufnr)
local manager = picker.manager
@@ -513,7 +517,11 @@ local send_all_to_qf = function(prompt_bufnr, mode)
actions.close(prompt_bufnr)
vim.fn.setqflist(qf_entries, mode)
if target == 'loclist' then
vim.fn.setloclist(picker.original_win_id, qf_entries, mode)
else
vim.fn.setqflist(qf_entries, mode)
end
end
--- Sends the selected entries to the quickfix list, replacing the previous entries.
@@ -536,12 +544,32 @@ actions.add_to_qflist = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, 'a')
end
local smart_send = function(prompt_bufnr, mode)
--- Sends the selected entries to the location list, replacing the previous entries.
actions.send_selected_to_loclist = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, 'r', 'loclist')
end
--- Adds the selected entries to the location list, keeping the previous entries.
actions.add_selected_to_loclist = function(prompt_bufnr)
send_selected_to_qf(prompt_bufnr, 'a', 'loclist')
end
--- Sends all entries to the location list, replacing the previous entries.
actions.send_to_loclist = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, 'r', 'loclist')
end
--- Adds all entries to the location list, keeping the previous entries.
actions.add_to_loclist = function(prompt_bufnr)
send_all_to_qf(prompt_bufnr, 'a', 'loclist')
end
local smart_send = function(prompt_bufnr, mode, target)
local picker = action_state.get_current_picker(prompt_bufnr)
if table.getn(picker:get_multi_selection()) > 0 then
send_selected_to_qf(prompt_bufnr, mode)
send_selected_to_qf(prompt_bufnr, mode, target)
else
send_all_to_qf(prompt_bufnr, mode)
send_all_to_qf(prompt_bufnr, mode, target)
end
end
@@ -557,6 +585,18 @@ actions.smart_add_to_qflist = function(prompt_bufnr)
smart_send(prompt_bufnr, 'a')
end
--- Sends the selected entries to the location list, replacing the previous entries.
--- If no entry was selected, sends all entries.
actions.smart_send_to_loclist = function(prompt_bufnr)
smart_send(prompt_bufnr, 'r', 'loclist')
end
--- Adds the selected entries to the location list, keeping the previous entries.
--- If no entry was selected, adds all entries.
actions.smart_add_to_loclist = function(prompt_bufnr)
smart_send(prompt_bufnr, 'a', 'loclist')
end
actions.complete_tag = function(prompt_bufnr)
local current_picker = action_state.get_current_picker(prompt_bufnr)
local tags = current_picker.sorter.tags
@@ -605,6 +645,11 @@ actions.open_qflist = function(_)
vim.cmd [[copen]]
end
--- Open the location list
actions.open_loclist = function(_)
vim.cmd [[lopen]]
end
-- ==================================================
-- Transforms modules and sets the corect metatables.
-- ==================================================