diff options
| author | Simon Hauser <Simon-Hauser@outlook.de> | 2021-07-23 17:42:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-23 11:42:37 -0400 |
| commit | 79644ab67731c7ba956c354bf0545282f34e10cc (patch) | |
| tree | e65dbf73b3442ab1aa9fc59fc56a35b4c9edf1e0 /lua/telescope/actions/init.lua | |
| parent | 664690029fdb302bee8d3f27a458383e8477add7 (diff) | |
chore: use stylua for formatting (#1040)
* chore: stylua job and config
* reformat with stylua
Diffstat (limited to 'lua/telescope/actions/init.lua')
| -rw-r--r-- | lua/telescope/actions/init.lua | 243 |
1 files changed, 114 insertions, 129 deletions
diff --git a/lua/telescope/actions/init.lua b/lua/telescope/actions/init.lua index 929622d..7e61e63 100644 --- a/lua/telescope/actions/init.lua +++ b/lua/telescope/actions/init.lua @@ -9,30 +9,36 @@ local a = vim.api -local log = require('telescope.log') -local state = require('telescope.state') -local utils = require('telescope.utils') -local p_scroller = require('telescope.pickers.scroller') +local log = require "telescope.log" +local state = require "telescope.state" +local utils = require "telescope.utils" +local p_scroller = require "telescope.pickers.scroller" -local action_state = require('telescope.actions.state') -local action_utils = require('telescope.actions.utils') -local action_set = require('telescope.actions.set') +local action_state = require "telescope.actions.state" +local action_utils = require "telescope.actions.utils" +local action_set = require "telescope.actions.set" -local transform_mod = require('telescope.actions.mt').transform_mod +local transform_mod = require("telescope.actions.mt").transform_mod local actions = setmetatable({}, { __index = function(_, k) -- TODO(conni2461): Remove deprecated messages - if k:find('goto_file_selection') then - error("`" .. k .. "` is removed and no longer usable. " .. - "Use `require('telescope.actions').select_` instead. Take a look at developers.md for more Information.") - elseif k == '_goto_file_selection' then - error("`_goto_file_selection` is deprecated and no longer replaceable. " .. - "Use `require('telescope.actions.set').edit` instead. Take a look at developers.md for more Information.") + if k:find "goto_file_selection" then + error( + "`" + .. k + .. "` is removed and no longer usable. " + .. "Use `require('telescope.actions').select_` instead. Take a look at developers.md for more Information." + ) + elseif k == "_goto_file_selection" then + error( + "`_goto_file_selection` is deprecated and no longer replaceable. " + .. "Use `require('telescope.actions.set').edit` instead. Take a look at developers.md for more Information." + ) end error("Key does not exist for 'telescope.actions': " .. tostring(k)) - end + end, }) -- TODO(conni2461): Remove deprecated messages @@ -40,29 +46,25 @@ local action_is_deprecated = function(name, err) local messager = err and error or log.info return messager( - string.format("`actions.%s()` is deprecated." - .. "Use require('telescope.actions.state').%s() instead", - name, - name - ) + string.format("`actions.%s()` is deprecated." .. "Use require('telescope.actions.state').%s() instead", name, name) ) end function actions.get_selected_entry() -- TODO(1.0): Remove - action_is_deprecated("get_selected_entry") + action_is_deprecated "get_selected_entry" return action_state.get_selected_entry() end function actions.get_current_line() -- TODO(1.0): Remove - action_is_deprecated("get_current_line") + action_is_deprecated "get_current_line" return action_state.get_current_line() end function actions.get_current_picker(prompt_bufnr) -- TODO(1.0): Remove - action_is_deprecated("get_current_picker") + action_is_deprecated "get_current_picker" return action_state.get_current_picker(prompt_bufnr) end @@ -96,31 +98,27 @@ end ---@param prompt_bufnr number: The prompt bufnr function actions.move_to_top(prompt_bufnr) local current_picker = actions.get_current_picker(prompt_bufnr) - current_picker:set_selection(p_scroller.top(current_picker.sorting_strategy, - current_picker.max_results, - current_picker.manager:num_results() - )) + current_picker:set_selection( + p_scroller.top(current_picker.sorting_strategy, current_picker.max_results, current_picker.manager:num_results()) + ) end --- Move to the middle of the picker ---@param prompt_bufnr number: The prompt bufnr function actions.move_to_middle(prompt_bufnr) local current_picker = actions.get_current_picker(prompt_bufnr) - current_picker:set_selection(p_scroller.middle( - current_picker.sorting_strategy, - current_picker.max_results, - current_picker.manager:num_results() - )) + current_picker:set_selection( + p_scroller.middle(current_picker.sorting_strategy, current_picker.max_results, current_picker.manager:num_results()) + ) end --- Move to the bottom of the picker ---@param prompt_bufnr number: The prompt bufnr function actions.move_to_bottom(prompt_bufnr) local current_picker = actions.get_current_picker(prompt_bufnr) - current_picker:set_selection(p_scroller.bottom(current_picker.sorting_strategy, - current_picker.max_results, - current_picker.manager:num_results() - )) + current_picker:set_selection( + p_scroller.bottom(current_picker.sorting_strategy, current_picker.max_results, current_picker.manager:num_results()) + ) end --- Add current entry to multi select @@ -193,7 +191,7 @@ function actions.preview_scrolling_down(prompt_bufnr) end function actions.center(_) - vim.cmd(':normal! zz') + vim.cmd ":normal! zz" end actions.select_default = { @@ -205,7 +203,7 @@ actions.select_default = { end, action = function(prompt_bufnr) return action_set.select(prompt_bufnr, "default") - end + end, } actions.select_horizontal = { @@ -217,7 +215,7 @@ actions.select_horizontal = { end, action = function(prompt_bufnr) return action_set.select(prompt_bufnr, "horizontal") - end + end, } actions.select_vertical = { @@ -229,7 +227,7 @@ actions.select_vertical = { end, action = function(prompt_bufnr) return action_set.select(prompt_bufnr, "vertical") - end + end, } actions.select_tab = { @@ -241,7 +239,7 @@ actions.select_tab = { end, action = function(prompt_bufnr) return action_set.select(prompt_bufnr, "tab") - end + end, } -- TODO: consider adding float! @@ -265,7 +263,7 @@ end function actions.close_pum(_) if 0 ~= vim.fn.pumvisible() then - vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<c-y>", true, true, true), 'n', true) + vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<c-y>", true, true, true), "n", true) end end @@ -299,7 +297,7 @@ end actions.edit_command_line = function(prompt_bufnr) local entry = action_state.get_selected_entry(prompt_bufnr) actions.close(prompt_bufnr) - a.nvim_feedkeys(a.nvim_replace_termcodes(":" .. entry.value , true, false, true), "t", true) + a.nvim_feedkeys(a.nvim_replace_termcodes(":" .. entry.value, true, false, true), "t", true) end actions.set_command_line = function(prompt_bufnr) @@ -313,7 +311,7 @@ end actions.edit_search_line = function(prompt_bufnr) local entry = action_state.get_selected_entry(prompt_bufnr) actions.close(prompt_bufnr) - a.nvim_feedkeys(a.nvim_replace_termcodes("/" .. entry.value , true, false, true), "t", true) + a.nvim_feedkeys(a.nvim_replace_termcodes("/" .. entry.value, true, false, true), "t", true) end actions.set_search_line = function(prompt_bufnr) @@ -352,7 +350,7 @@ actions.paste_register = function(prompt_bufnr) -- ensure that the buffer can be written to if vim.api.nvim_buf_get_option(vim.api.nvim_get_current_buf(), "modifiable") then - print("Paste!") + print "Paste!" vim.api.nvim_paste(entry.content, true, -1) end end @@ -361,22 +359,22 @@ actions.run_builtin = function(prompt_bufnr) local entry = action_state.get_selected_entry(prompt_bufnr) actions._close(prompt_bufnr, true) - if string.match(entry.text," : ") then + if string.match(entry.text, " : ") then -- Call appropriate function from extensions - local split_string = vim.split(entry.text," : ") + local split_string = vim.split(entry.text, " : ") local ext = split_string[1] local func = split_string[2] - require('telescope').extensions[ext][func]() + require("telescope").extensions[ext][func]() else -- Call appropriate telescope builtin - require('telescope.builtin')[entry.text]() + require("telescope.builtin")[entry.text]() end end actions.insert_symbol = function(prompt_bufnr) local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) - vim.api.nvim_put({selection.value[1]}, '', true, true) + vim.api.nvim_put({ selection.value[1] }, "", true, true) end -- TODO: Think about how to do this. @@ -397,25 +395,23 @@ actions.git_create_branch = function(prompt_bufnr) local new_branch = action_state.get_current_line() if new_branch == "" then - print('Please enter the name of the new branch to create') + print "Please enter the name of the new branch to create" else local confirmation = vim.fn.input(string.format('Create new branch "%s"? [y/n]: ', new_branch)) - if string.len(confirmation) == 0 or string.sub(string.lower(confirmation), 0, 1) ~= 'y' then + if string.len(confirmation) == 0 or string.sub(string.lower(confirmation), 0, 1) ~= "y" then print(string.format('Didn\'t create branch "%s"', new_branch)) return end actions.close(prompt_bufnr) - local _, ret, stderr = utils.get_os_command_output({ 'git', 'checkout', '-b', new_branch }, cwd) + local _, ret, stderr = utils.get_os_command_output({ "git", "checkout", "-b", new_branch }, cwd) if ret == 0 then - print(string.format('Switched to a new branch: %s', new_branch)) + print(string.format("Switched to a new branch: %s", new_branch)) else - print(string.format( - 'Error when creating new branch: %s Git returned "%s"', - new_branch, - table.concat(stderr, ' ') - )) + print( + string.format('Error when creating new branch: %s Git returned "%s"', new_branch, table.concat(stderr, " ")) + ) end end end @@ -425,15 +421,11 @@ end actions.git_apply_stash = function(prompt_bufnr) local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) - local _, ret, stderr = utils.get_os_command_output({ 'git', 'stash', 'apply', '--index', selection.value }) + local _, ret, stderr = utils.get_os_command_output { "git", "stash", "apply", "--index", selection.value } if ret == 0 then print("applied: " .. selection.value) else - print(string.format( - 'Error when applying: %s. Git returned: "%s"', - selection.value, - table.concat(stderr, ' ') - )) + print(string.format('Error when applying: %s. Git returned: "%s"', selection.value, table.concat(stderr, " "))) end end @@ -443,15 +435,11 @@ actions.git_checkout = function(prompt_bufnr) local cwd = action_state.get_current_picker(prompt_bufnr).cwd local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) - local _, ret, stderr = utils.get_os_command_output({ 'git', 'checkout', selection.value }, cwd) + local _, ret, stderr = utils.get_os_command_output({ "git", "checkout", selection.value }, cwd) if ret == 0 then print("Checked out: " .. selection.value) else - print(string.format( - 'Error when checking out: %s. Git returned: "%s"', - selection.value, - table.concat(stderr, ' ') - )) + print(string.format('Error when checking out: %s. Git returned: "%s"', selection.value, table.concat(stderr, " "))) end end @@ -463,20 +451,16 @@ actions.git_switch_branch = function(prompt_bufnr) local cwd = action_state.get_current_picker(prompt_bufnr).cwd local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) - local pattern = '^refs/remotes/%w+/' + local pattern = "^refs/remotes/%w+/" local branch = selection.value if string.match(selection.refname, pattern) then - branch = string.gsub(selection.refname, pattern, '') + branch = string.gsub(selection.refname, pattern, "") end - local _, ret, stderr = utils.get_os_command_output({ 'git', 'switch', branch }, cwd) + local _, ret, stderr = utils.get_os_command_output({ "git", "switch", branch }, cwd) if ret == 0 then print("Switched to: " .. branch) else - print(string.format( - 'Error when switching to: %s. Git returned: "%s"', - selection.value, - table.concat(stderr, ' ') - )) + print(string.format('Error when switching to: %s. Git returned: "%s"', selection.value, table.concat(stderr, " "))) end end @@ -486,15 +470,13 @@ actions.git_track_branch = function(prompt_bufnr) local cwd = action_state.get_current_picker(prompt_bufnr).cwd local selection = action_state.get_selected_entry() actions.close(prompt_bufnr) - local _, ret, stderr = utils.get_os_command_output({ 'git', 'checkout', '--track', selection.value }, cwd) + local _, ret, stderr = utils.get_os_command_output({ "git", "checkout", "--track", selection.value }, cwd) if ret == 0 then print("Tracking branch: " .. selection.value) else - print(string.format( - 'Error when tracking branch: %s. Git returned: "%s"', - selection.value, - table.concat(stderr, ' ') - )) + print( + string.format('Error when tracking branch: %s. Git returned: "%s"', selection.value, table.concat(stderr, " ")) + ) end end @@ -504,19 +486,19 @@ actions.git_delete_branch = function(prompt_bufnr) local cwd = action_state.get_current_picker(prompt_bufnr).cwd local selection = action_state.get_selected_entry() - local confirmation = vim.fn.input('Do you really wanna delete branch ' .. selection.value .. '? [Y/n] ') - if confirmation ~= '' and string.lower(confirmation) ~= 'y' then return end + local confirmation = vim.fn.input("Do you really wanna delete branch " .. selection.value .. "? [Y/n] ") + if confirmation ~= "" and string.lower(confirmation) ~= "y" then + return + end actions.close(prompt_bufnr) - local _, ret, stderr = utils.get_os_command_output({ 'git', 'branch', '-D', selection.value }, cwd) + local _, ret, stderr = utils.get_os_command_output({ "git", "branch", "-D", selection.value }, cwd) if ret == 0 then print("Deleted branch: " .. selection.value) else - print(string.format( - 'Error when deleting branch: %s. Git returned: "%s"', - selection.value, - table.concat(stderr, ' ') - )) + print( + string.format('Error when deleting branch: %s. Git returned: "%s"', selection.value, table.concat(stderr, " ")) + ) end end @@ -526,19 +508,19 @@ actions.git_rebase_branch = function(prompt_bufnr) local cwd = action_state.get_current_picker(prompt_bufnr).cwd local selection = action_state.get_selected_entry() - local confirmation = vim.fn.input('Do you really wanna rebase branch ' .. selection.value .. '? [Y/n] ') - if confirmation ~= '' and string.lower(confirmation) ~= 'y' then return end + local confirmation = vim.fn.input("Do you really wanna rebase branch " .. selection.value .. "? [Y/n] ") + if confirmation ~= "" and string.lower(confirmation) ~= "y" then + return + end actions.close(prompt_bufnr) - local _, ret, stderr = utils.get_os_command_output({ 'git', 'rebase', selection.value }, cwd) + local _, ret, stderr = utils.get_os_command_output({ "git", "rebase", selection.value }, cwd) if ret == 0 then print("Rebased branch: " .. selection.value) else - print(string.format( - 'Error when rebasing branch: %s. Git returned: "%s"', - selection.value, - table.concat(stderr, ' ') - )) + print( + string.format('Error when rebasing branch: %s. Git returned: "%s"', selection.value, table.concat(stderr, " ")) + ) end end @@ -546,7 +528,7 @@ actions.git_checkout_current_buffer = function(prompt_bufnr) local cwd = actions.get_current_picker(prompt_bufnr).cwd local selection = actions.get_selected_entry() actions.close(prompt_bufnr) - utils.get_os_command_output({ 'git', 'checkout', selection.value, '--', selection.file }, cwd) + utils.get_os_command_output({ "git", "checkout", selection.value, "--", selection.file }, cwd) end --- Stage/unstage selected file @@ -555,10 +537,10 @@ actions.git_staging_toggle = function(prompt_bufnr) local cwd = action_state.get_current_picker(prompt_bufnr).cwd local selection = action_state.get_selected_entry() - if selection.status:sub(2) == ' ' then - utils.get_os_command_output({ 'git', 'restore', '--staged', selection.value }, cwd) + if selection.status:sub(2) == " " then + utils.get_os_command_output({ "git", "restore", "--staged", selection.value }, cwd) else - utils.get_os_command_output({ 'git', 'add', selection.value }, cwd) + utils.get_os_command_output({ "git", "add", selection.value }, cwd) end end @@ -582,7 +564,7 @@ local send_selected_to_qf = function(prompt_bufnr, mode, target) actions.close(prompt_bufnr) - if target == 'loclist' then + if target == "loclist" then vim.fn.setloclist(picker.original_win_id, qf_entries, mode) else vim.fn.setqflist(qf_entries, mode) @@ -600,7 +582,7 @@ local send_all_to_qf = function(prompt_bufnr, mode, target) actions.close(prompt_bufnr) - if target == 'loclist' then + if target == "loclist" then vim.fn.setloclist(picker.original_win_id, qf_entries, mode) else vim.fn.setqflist(qf_entries, mode) @@ -609,42 +591,42 @@ end --- Sends the selected entries to the quickfix list, replacing the previous entries. actions.send_selected_to_qflist = function(prompt_bufnr) - send_selected_to_qf(prompt_bufnr, 'r') + send_selected_to_qf(prompt_bufnr, "r") end --- Adds the selected entries to the quickfix list, keeping the previous entries. actions.add_selected_to_qflist = function(prompt_bufnr) - send_selected_to_qf(prompt_bufnr, 'a') + send_selected_to_qf(prompt_bufnr, "a") end --- Sends all entries to the quickfix list, replacing the previous entries. actions.send_to_qflist = function(prompt_bufnr) - send_all_to_qf(prompt_bufnr, 'r') + send_all_to_qf(prompt_bufnr, "r") end --- Adds all entries to the quickfix list, keeping the previous entries. actions.add_to_qflist = function(prompt_bufnr) - send_all_to_qf(prompt_bufnr, 'a') + send_all_to_qf(prompt_bufnr, "a") end - --- Sends the selected entries to the location list, replacing the previous entries. +--- 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') + send_selected_to_qf(prompt_bufnr, "r", "loclist") end - --- Adds the selected entries to the location list, keeping the previous entries. +--- 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') + send_selected_to_qf(prompt_bufnr, "a", "loclist") end - --- Sends all entries to the location list, replacing the previous entries. +--- 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') + send_all_to_qf(prompt_bufnr, "r", "loclist") end - --- Adds all entries to the location list, keeping the previous entries. +--- 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') + send_all_to_qf(prompt_bufnr, "a", "loclist") end local smart_send = function(prompt_bufnr, mode, target) @@ -659,25 +641,25 @@ end --- Sends the selected entries to the quickfix list, replacing the previous entries. --- If no entry was selected, sends all entries. actions.smart_send_to_qflist = function(prompt_bufnr) - smart_send(prompt_bufnr, 'r') + smart_send(prompt_bufnr, "r") end --- Adds the selected entries to the quickfix list, keeping the previous entries. --- If no entry was selected, adds all entries. actions.smart_add_to_qflist = function(prompt_bufnr) - smart_send(prompt_bufnr, 'a') + 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') + 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') + smart_send(prompt_bufnr, "a", "loclist") end actions.complete_tag = function(prompt_bufnr) @@ -686,14 +668,14 @@ actions.complete_tag = function(prompt_bufnr) local delimiter = current_picker.sorter._delimiter if not tags then - print('No tag pre-filtering set for this picker') + print "No tag pre-filtering set for this picker" return end -- format tags to match filter_function local prefilter_tags = {} for tag, _ in pairs(tags) do - table.insert(prefilter_tags, string.format('%s%s%s ', delimiter, tag:lower(), delimiter)) + table.insert(prefilter_tags, string.format("%s%s%s ", delimiter, tag:lower(), delimiter)) end local line = action_state.get_current_line() @@ -713,14 +695,13 @@ actions.complete_tag = function(prompt_bufnr) end if vim.tbl_isempty(filtered_tags) then - print('No matches found') + print "No matches found" return end -- incremental completion by substituting string starting from col - #line byte offset local col = vim.api.nvim_win_get_cursor(0)[2] + 1 vim.fn.complete(col - #line, filtered_tags) - end actions.cycle_history_next = function(prompt_bufnr) @@ -729,7 +710,9 @@ actions.cycle_history_next = function(prompt_bufnr) local line = action_state.get_current_line() local entry = history:get_next(line, current_picker) - if entry == false then return end + if entry == false then + return + end current_picker:reset_prompt() if entry ~= nil then @@ -743,7 +726,9 @@ actions.cycle_history_prev = function(prompt_bufnr) local line = action_state.get_current_line() local entry = history:get_prev(line, current_picker) - if entry == false then return end + if entry == false then + return + end if entry ~= nil then current_picker:reset_prompt() current_picker:set_prompt(entry) |
