chore: use stylua for formatting (#1040)
* chore: stylua job and config * reformat with stylua
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
local conf = require('telescope.config').values
|
||||
local Path = require('plenary.path')
|
||||
local conf = require("telescope.config").values
|
||||
local Path = require "plenary.path"
|
||||
|
||||
local uv = vim.loop
|
||||
|
||||
@@ -37,7 +37,9 @@ local write_async = function(path, txt, flag)
|
||||
end)
|
||||
end
|
||||
|
||||
local append_async = function(path, txt) write_async(path, txt, "a") end
|
||||
local append_async = function(path, txt)
|
||||
write_async(path, txt, "a")
|
||||
end
|
||||
|
||||
local histories = {}
|
||||
|
||||
@@ -86,7 +88,9 @@ end
|
||||
|
||||
--- Will reset the history index to the default initial state. Will happen after the picker closed
|
||||
function histories.History:reset()
|
||||
if not self.enabled then return end
|
||||
if not self.enabled then
|
||||
return
|
||||
end
|
||||
self._reset(self)
|
||||
end
|
||||
|
||||
@@ -95,7 +99,9 @@ end
|
||||
---@param picker table: the current picker object
|
||||
---@param no_reset boolean: On default it will reset the state at the end. If you don't want to do this set to true
|
||||
function histories.History:append(line, picker, no_reset)
|
||||
if not self.enabled then return end
|
||||
if not self.enabled then
|
||||
return
|
||||
end
|
||||
self._append(self, line, picker, no_reset)
|
||||
end
|
||||
|
||||
@@ -105,11 +111,15 @@ end
|
||||
---@return string: the next history item
|
||||
function histories.History:get_next(line, picker)
|
||||
if not self.enabled then
|
||||
print("You are cycling to next the history item but history is disabled.",
|
||||
"Read ':help telescope.defaults.history'")
|
||||
print(
|
||||
"You are cycling to next the history item but history is disabled.",
|
||||
"Read ':help telescope.defaults.history'"
|
||||
)
|
||||
return false
|
||||
end
|
||||
if self._pre_get then self._pre_get(self, line, picker) end
|
||||
if self._pre_get then
|
||||
self._pre_get(self, line, picker)
|
||||
end
|
||||
|
||||
local next_idx = self.index + 1
|
||||
if next_idx <= #self.content then
|
||||
@@ -126,15 +136,21 @@ end
|
||||
---@return string: the previous history item
|
||||
function histories.History:get_prev(line, picker)
|
||||
if not self.enabled then
|
||||
print("You are cycling to previous the history item but history is disabled.",
|
||||
"Read ':help telescope.defaults.history'")
|
||||
print(
|
||||
"You are cycling to previous the history item but history is disabled.",
|
||||
"Read ':help telescope.defaults.history'"
|
||||
)
|
||||
return false
|
||||
end
|
||||
if self._pre_get then self._pre_get(self, line, picker) end
|
||||
if self._pre_get then
|
||||
self._pre_get(self, line, picker)
|
||||
end
|
||||
|
||||
local next_idx = self.index - 1
|
||||
if self.index == #self.content + 1 then
|
||||
if line ~= '' then self:append(line, picker, true) end
|
||||
if line ~= "" then
|
||||
self:append(line, picker, true)
|
||||
end
|
||||
end
|
||||
if next_idx >= 1 then
|
||||
self.index = next_idx
|
||||
@@ -147,10 +163,12 @@ end
|
||||
---
|
||||
--- It will keep one unified history across all pickers.
|
||||
histories.get_simple_history = function()
|
||||
return histories.new({
|
||||
return histories.new {
|
||||
init = function(obj)
|
||||
local p = Path:new(obj.path)
|
||||
if not p:exists() then p:touch({ parents = true }) end
|
||||
if not p:exists() then
|
||||
p:touch { parents = true }
|
||||
end
|
||||
|
||||
obj.content = Path:new(obj.path):readlines()
|
||||
obj.index = #obj.content
|
||||
@@ -160,7 +178,7 @@ histories.get_simple_history = function()
|
||||
self.index = #self.content + 1
|
||||
end,
|
||||
append = function(self, line, _, no_reset)
|
||||
if line ~= '' then
|
||||
if line ~= "" then
|
||||
if self.content[#self.content] ~= line then
|
||||
table.insert(self.content, line)
|
||||
|
||||
@@ -170,9 +188,9 @@ histories.get_simple_history = function()
|
||||
for i = diff, 1, -1 do
|
||||
table.remove(self.content, i)
|
||||
end
|
||||
write_async(self.path, table.concat(self.content, '\n') .. '\n', 'w')
|
||||
write_async(self.path, table.concat(self.content, "\n") .. "\n", "w")
|
||||
else
|
||||
append_async(self.path, line .. '\n')
|
||||
append_async(self.path, line .. "\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -180,7 +198,7 @@ histories.get_simple_history = function()
|
||||
self:reset()
|
||||
end
|
||||
end,
|
||||
})
|
||||
}
|
||||
end
|
||||
|
||||
return histories
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -27,11 +27,7 @@ action_mt.create = function(mod)
|
||||
end
|
||||
|
||||
local result = {
|
||||
run_replace_or_original(
|
||||
t._replacements[action_name],
|
||||
mod[action_name],
|
||||
...
|
||||
)
|
||||
run_replace_or_original(t._replacements[action_name], mod[action_name], ...),
|
||||
}
|
||||
for _, res in ipairs(result) do
|
||||
table.insert(values, res)
|
||||
@@ -128,7 +124,7 @@ action_mt.create = function(mod)
|
||||
end
|
||||
|
||||
action_mt.transform = function(k, mt, mod, v)
|
||||
local res = setmetatable({k}, mt)
|
||||
local res = setmetatable({ k }, mt)
|
||||
if type(v) == "table" then
|
||||
res._static_pre[k] = v.pre
|
||||
res._static_post[k] = v.post
|
||||
|
||||
@@ -12,18 +12,18 @@
|
||||
|
||||
local a = vim.api
|
||||
|
||||
local log = require('telescope.log')
|
||||
local Path = require('plenary.path')
|
||||
local state = require('telescope.state')
|
||||
local log = require "telescope.log"
|
||||
local Path = require "plenary.path"
|
||||
local state = require "telescope.state"
|
||||
|
||||
local action_state = require('telescope.actions.state')
|
||||
local action_state = require "telescope.actions.state"
|
||||
|
||||
local transform_mod = require('telescope.actions.mt').transform_mod
|
||||
local transform_mod = require("telescope.actions.mt").transform_mod
|
||||
|
||||
local action_set = setmetatable({}, {
|
||||
__index = function(_, k)
|
||||
error("'telescope.actions.set' does not have a value: " .. tostring(k))
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
--- Move the current selection of a picker {change} rows.
|
||||
@@ -65,16 +65,16 @@ end
|
||||
local edit_buffer
|
||||
do
|
||||
local map = {
|
||||
edit = 'buffer',
|
||||
new = 'sbuffer',
|
||||
vnew = 'vert sbuffer',
|
||||
tabedit = 'tab sb',
|
||||
edit = "buffer",
|
||||
new = "sbuffer",
|
||||
vnew = "vert sbuffer",
|
||||
tabedit = "tab sb",
|
||||
}
|
||||
|
||||
edit_buffer = function(command, bufnr)
|
||||
command = map[command]
|
||||
if command == nil then
|
||||
error('There was no associated buffer command')
|
||||
error "There was no associated buffer command"
|
||||
end
|
||||
vim.cmd(string.format("%s %d", command, bufnr))
|
||||
end
|
||||
@@ -88,7 +88,7 @@ action_set.edit = function(prompt_bufnr, command)
|
||||
local entry = action_state.get_selected_entry()
|
||||
|
||||
if not entry then
|
||||
print("[telescope] Nothing currently selected")
|
||||
print "[telescope] Nothing currently selected"
|
||||
return
|
||||
end
|
||||
|
||||
@@ -105,7 +105,7 @@ action_set.edit = function(prompt_bufnr, command)
|
||||
-- to put stuff into `filename`
|
||||
local value = entry.value
|
||||
if not value then
|
||||
print("Could not do anything with blank line...")
|
||||
print "Could not do anything with blank line..."
|
||||
return
|
||||
end
|
||||
|
||||
@@ -122,7 +122,7 @@ action_set.edit = function(prompt_bufnr, command)
|
||||
|
||||
local entry_bufnr = entry.bufnr
|
||||
|
||||
require('telescope.actions').close(prompt_bufnr)
|
||||
require("telescope.actions").close(prompt_bufnr)
|
||||
|
||||
if entry_bufnr then
|
||||
edit_buffer(command, entry_bufnr)
|
||||
@@ -136,7 +136,7 @@ action_set.edit = function(prompt_bufnr, command)
|
||||
end
|
||||
|
||||
if row and col then
|
||||
local ok, err_msg = pcall(a.nvim_win_set_cursor, 0, {row, col})
|
||||
local ok, err_msg = pcall(a.nvim_win_set_cursor, 0, { row, col })
|
||||
if not ok then
|
||||
log.debug("Failed to move to cursor:", err_msg, row, col)
|
||||
end
|
||||
@@ -147,11 +147,11 @@ end
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
---@param direction number: The direction of the scrolling
|
||||
-- Valid directions include: "1", "-1"
|
||||
action_set.scroll_previewer = function (prompt_bufnr, direction)
|
||||
action_set.scroll_previewer = function(prompt_bufnr, direction)
|
||||
local previewer = action_state.get_current_picker(prompt_bufnr).previewer
|
||||
|
||||
-- Check if we actually have a previewer
|
||||
if (type(previewer) ~= "table" or previewer.scroll_fn == nil) then
|
||||
if type(previewer) ~= "table" or previewer.scroll_fn == nil then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
@@ -6,19 +6,19 @@
|
||||
--- Generally used from within other |telescope.actions|
|
||||
---@brief ]]
|
||||
|
||||
local global_state = require('telescope.state')
|
||||
local conf = require('telescope.config').values
|
||||
local global_state = require "telescope.state"
|
||||
local conf = require("telescope.config").values
|
||||
|
||||
local action_state = {}
|
||||
|
||||
--- Get the current entry
|
||||
function action_state.get_selected_entry()
|
||||
return global_state.get_global_key('selected_entry')
|
||||
return global_state.get_global_key "selected_entry"
|
||||
end
|
||||
|
||||
--- Gets the current line
|
||||
function action_state.get_current_line()
|
||||
return global_state.get_global_key('current_line')
|
||||
return global_state.get_global_key "current_line"
|
||||
end
|
||||
|
||||
--- Gets the current picker
|
||||
@@ -38,10 +38,10 @@ function action_state.select_key_to_edit_key(type)
|
||||
end
|
||||
|
||||
function action_state.get_current_history()
|
||||
local history = global_state.get_global_key("history")
|
||||
local history = global_state.get_global_key "history"
|
||||
if not history then
|
||||
if conf.history == false or type(conf.history) ~= "table" then
|
||||
history = require('telescope.actions.history').get_simple_history()
|
||||
history = require("telescope.actions.history").get_simple_history()
|
||||
global_state.set_global_key("history", history)
|
||||
else
|
||||
history = conf.history.handler()
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
--- Generally used from within other |telescope.actions|
|
||||
---@brief ]]
|
||||
|
||||
local action_state = require('telescope.actions.state')
|
||||
local action_state = require "telescope.actions.state"
|
||||
|
||||
local utils = {}
|
||||
|
||||
@@ -33,12 +33,12 @@ local utils = {}
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
---@param f function: Function to map onto entries of picker that takes (entry, index, row) as viable arguments
|
||||
function utils.map_entries(prompt_bufnr, f)
|
||||
vim.validate{
|
||||
f = {f, "function"}
|
||||
vim.validate {
|
||||
f = { f, "function" },
|
||||
}
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
local index = 1
|
||||
-- indices are 1-indexed, rows are 0-indexed
|
||||
-- indices are 1-indexed, rows are 0-indexed
|
||||
for entry in current_picker.manager:iter() do
|
||||
local row = current_picker:get_row(index)
|
||||
f(entry, index, row)
|
||||
@@ -69,8 +69,8 @@ end
|
||||
---@param prompt_bufnr number: The prompt bufnr
|
||||
---@param f function: Function to map onto selection of picker that takes (selection) as a viable argument
|
||||
function utils.map_selections(prompt_bufnr, f)
|
||||
vim.validate{
|
||||
f = {f, "function"}
|
||||
vim.validate {
|
||||
f = { f, "function" },
|
||||
}
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
for _, selection in ipairs(current_picker:get_multi_selection()) do
|
||||
|
||||
Reference in New Issue
Block a user