Refresh generated neovim config
This commit is contained in:
@ -462,7 +462,6 @@ actions.edit_register = function(prompt_bufnr)
|
||||
v.content = updated_value
|
||||
end
|
||||
end
|
||||
-- print(vim.inspect(picker.finder.results))
|
||||
end
|
||||
|
||||
--- Paste the selected register into the buffer
|
||||
@ -489,7 +488,9 @@ end
|
||||
actions.insert_symbol = function(prompt_bufnr)
|
||||
local symbol = action_state.get_selected_entry().value[1]
|
||||
actions.close(prompt_bufnr)
|
||||
vim.api.nvim_put({ symbol }, "", true, true)
|
||||
vim.schedule(function()
|
||||
vim.api.nvim_put({ symbol }, "", true, true)
|
||||
end)
|
||||
end
|
||||
|
||||
--- Insert a symbol into the current buffer and keeping the insert mode.
|
||||
@ -1184,13 +1185,28 @@ actions.delete_buffer = function(prompt_bufnr)
|
||||
-- If the current buffer is deleted, switch to the previous buffer
|
||||
-- according to bdelete behavior
|
||||
if ok and selection.bufnr == current_picker.original_bufnr then
|
||||
local jumplist = vim.fn.getjumplist(current_picker.original_win_id)[1]
|
||||
for i = #jumplist, 1, -1 do
|
||||
if jumplist[i].bufnr ~= selection.bufnr and vim.fn.bufloaded(jumplist[i].bufnr) == 1 then
|
||||
vim.api.nvim_win_set_buf(current_picker.original_win_id, jumplist[i].bufnr)
|
||||
break
|
||||
if vim.api.nvim_win_is_valid(current_picker.original_win_id) then
|
||||
local jumplist = vim.fn.getjumplist(current_picker.original_win_id)[1]
|
||||
for i = #jumplist, 1, -1 do
|
||||
if jumplist[i].bufnr ~= selection.bufnr and vim.fn.bufloaded(jumplist[i].bufnr) == 1 then
|
||||
vim.api.nvim_win_set_buf(current_picker.original_win_id, jumplist[i].bufnr)
|
||||
current_picker.original_bufnr = jumplist[i].bufnr
|
||||
return ok
|
||||
end
|
||||
end
|
||||
|
||||
-- no more valid buffers in jumplist, create an empty buffer
|
||||
local empty_buf = vim.api.nvim_create_buf(true, true)
|
||||
vim.api.nvim_win_set_buf(current_picker.original_win_id, empty_buf)
|
||||
current_picker.original_bufnr = empty_buf
|
||||
vim.api.nvim_buf_delete(selection.bufnr, { force = true })
|
||||
return ok
|
||||
end
|
||||
|
||||
-- window of the selected buffer got wiped, switch to first valid window
|
||||
local win_id = vim.fn.win_getid(1, current_picker.original_tabpage)
|
||||
current_picker.original_win_id = win_id
|
||||
current_picker.original_bufnr = vim.api.nvim_win_get_buf(win_id)
|
||||
end
|
||||
return ok
|
||||
end)
|
||||
|
||||
@ -220,6 +220,9 @@ action_set.edit = function(prompt_bufnr, command)
|
||||
end
|
||||
|
||||
if row and col then
|
||||
if vim.api.nvim_buf_get_name(0) == filename then
|
||||
vim.cmd [[normal! m']]
|
||||
end
|
||||
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)
|
||||
|
||||
@ -180,6 +180,7 @@ files.live_grep = function(opts)
|
||||
map("i", "<c-space>", actions.to_fuzzy_refine)
|
||||
return true
|
||||
end,
|
||||
push_cursor_on_edit = true,
|
||||
})
|
||||
:find()
|
||||
end
|
||||
@ -257,6 +258,7 @@ files.grep_string = function(opts)
|
||||
finder = finders.new_oneshot_job(args, opts),
|
||||
previewer = conf.grep_previewer(opts),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
push_cursor_on_edit = true,
|
||||
})
|
||||
:find()
|
||||
end
|
||||
@ -460,6 +462,7 @@ files.treesitter = function(opts)
|
||||
tag = "kind",
|
||||
sorter = conf.generic_sorter(opts),
|
||||
},
|
||||
push_cursor_on_edit = true,
|
||||
})
|
||||
:find()
|
||||
end
|
||||
@ -564,13 +567,13 @@ files.current_buffer_fuzzy_find = function(opts)
|
||||
|
||||
actions.close(prompt_bufnr)
|
||||
vim.schedule(function()
|
||||
vim.cmd "normal! m'"
|
||||
vim.api.nvim_win_set_cursor(0, { selection.lnum, first_col })
|
||||
end)
|
||||
end)
|
||||
|
||||
return true
|
||||
end,
|
||||
push_cursor_on_edit = true,
|
||||
})
|
||||
:find()
|
||||
end
|
||||
|
||||
@ -109,16 +109,18 @@ internal.builtin = function(opts)
|
||||
end
|
||||
|
||||
actions.close(prompt_bufnr)
|
||||
if string.match(selection.text, " : ") then
|
||||
-- Call appropriate function from extensions
|
||||
local split_string = vim.split(selection.text, " : ")
|
||||
local ext = split_string[1]
|
||||
local func = split_string[2]
|
||||
require("telescope").extensions[ext][func](picker_opts)
|
||||
else
|
||||
-- Call appropriate telescope builtin
|
||||
require("telescope.builtin")[selection.text](picker_opts)
|
||||
end
|
||||
vim.schedule(function()
|
||||
if string.match(selection.text, " : ") then
|
||||
-- Call appropriate function from extensions
|
||||
local split_string = vim.split(selection.text, " : ")
|
||||
local ext = split_string[1]
|
||||
local func = split_string[2]
|
||||
require("telescope").extensions[ext][func](picker_opts)
|
||||
else
|
||||
-- Call appropriate telescope builtin
|
||||
require("telescope.builtin")[selection.text](picker_opts)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
|
||||
@ -148,6 +148,26 @@ local apply_action_handler = function(action, items, opts)
|
||||
return items
|
||||
end
|
||||
|
||||
---@param items vim.lsp.util.locations_to_items.ret[]
|
||||
---@param opts table
|
||||
---@return vim.lsp.util.locations_to_items.ret[]
|
||||
local function filter_file_ignore_patters(items, opts)
|
||||
local file_ignore_patterns = vim.F.if_nil(opts.file_ignore_patterns, conf.file_ignore_patterns)
|
||||
file_ignore_patterns = file_ignore_patterns or {}
|
||||
if vim.tbl_isempty(file_ignore_patterns) then
|
||||
return items
|
||||
end
|
||||
|
||||
return vim.tbl_filter(function(item)
|
||||
for _, patt in ipairs(file_ignore_patterns) do
|
||||
if string.match(item.filename, patt) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end, items)
|
||||
end
|
||||
|
||||
---@param action telescope.lsp.list_or_jump_action
|
||||
---@param title string prompt title
|
||||
---@param funname string: name of the calling function
|
||||
@ -157,25 +177,42 @@ local function list_or_jump(action, title, funname, params, opts)
|
||||
opts.reuse_win = vim.F.if_nil(opts.reuse_win, false)
|
||||
opts.curr_filepath = vim.api.nvim_buf_get_name(opts.bufnr)
|
||||
|
||||
vim.lsp.buf_request(opts.bufnr, action, params, function(err, result, ctx, _)
|
||||
if err then
|
||||
vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. err.message)
|
||||
return
|
||||
vim.lsp.buf_request_all(opts.bufnr, action, params, function(results_per_client)
|
||||
local items = {}
|
||||
local first_encoding
|
||||
local errors = {}
|
||||
|
||||
for client_id, result_or_error in pairs(results_per_client) do
|
||||
local error, result = result_or_error.error, result_or_error.result
|
||||
if error then
|
||||
errors[client_id] = error
|
||||
else
|
||||
if result ~= nil then
|
||||
local locations = {}
|
||||
|
||||
if not utils.islist(result) then
|
||||
vim.list_extend(locations, { result })
|
||||
else
|
||||
vim.list_extend(locations, result)
|
||||
end
|
||||
|
||||
local offset_encoding = vim.lsp.get_client_by_id(client_id).offset_encoding
|
||||
|
||||
if not vim.tbl_isempty(result) then
|
||||
first_encoding = offset_encoding
|
||||
end
|
||||
|
||||
vim.list_extend(items, vim.lsp.util.locations_to_items(locations, offset_encoding))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if result == nil then
|
||||
return
|
||||
for _, error in pairs(errors) do
|
||||
vim.api.nvim_err_writeln("Error when executing " .. action .. " : " .. error.message)
|
||||
end
|
||||
|
||||
local locations = {}
|
||||
if not utils.islist(result) then
|
||||
locations = { result }
|
||||
end
|
||||
vim.list_extend(locations, result)
|
||||
|
||||
local offset_encoding = vim.lsp.get_client_by_id(ctx.client_id).offset_encoding
|
||||
local items = vim.lsp.util.locations_to_items(locations, offset_encoding)
|
||||
items = apply_action_handler(action, items, opts)
|
||||
items = filter_file_ignore_patters(items, opts)
|
||||
|
||||
if vim.tbl_isempty(items) then
|
||||
utils.notify(funname, {
|
||||
@ -204,8 +241,8 @@ local function list_or_jump(action, title, funname, params, opts)
|
||||
end
|
||||
end
|
||||
|
||||
local location = item_to_location(item, offset_encoding)
|
||||
vim.lsp.util.jump_to_location(location, offset_encoding, opts.reuse_win)
|
||||
local location = item_to_location(item, first_encoding)
|
||||
vim.lsp.util.jump_to_location(location, first_encoding, opts.reuse_win)
|
||||
else
|
||||
pickers
|
||||
.new(opts, {
|
||||
|
||||
@ -77,7 +77,7 @@ builtin.grep_string = require_on_exported_call("telescope.builtin.__files").grep
|
||||
---@field cwd string: root dir to search from (default: cwd, use utils.buffer_dir() to search relative to open buffer)
|
||||
---@field find_command function|table: cmd to use for the search. Can be a fn(opts) -> tbl (default: autodetect)
|
||||
---@field file_entry_encoding string: encoding of output of `find_command`
|
||||
---@field follow boolean: if true, follows symlinks (i.e. uses `-L` flag for the `find` command)
|
||||
---@field follow boolean: if true, follows symlinks (i.e. uses `-L` flag for the `find` command) (default: false)
|
||||
---@field hidden boolean: determines whether to show hidden files or not (default: false)
|
||||
---@field no_ignore boolean: show files ignored by .gitignore, .ignore, etc. (default: false)
|
||||
---@field no_ignore_parent boolean: show files ignored by .gitignore, .ignore, etc. in parent dirs. (default: false)
|
||||
|
||||
@ -251,21 +251,21 @@ end
|
||||
--- - Compass directions:<br>
|
||||
--- the picker will move to the corresponding edge/corner
|
||||
--- e.g. "NW" -> "top left corner", "E" -> "right edge", "S" -> "bottom edge"
|
||||
resolver.resolve_anchor_pos = function(anchor, p_width, p_height, max_columns, max_lines)
|
||||
resolver.resolve_anchor_pos = function(anchor, p_width, p_height, max_columns, max_lines, anchor_padding)
|
||||
anchor = anchor:upper()
|
||||
local pos = { 0, 0 }
|
||||
if anchor == "CENTER" then
|
||||
return pos
|
||||
end
|
||||
if anchor:find "W" then
|
||||
pos[1] = math.ceil((p_width - max_columns) / 2) + 1
|
||||
pos[1] = math.ceil((p_width - max_columns) / 2) + anchor_padding
|
||||
elseif anchor:find "E" then
|
||||
pos[1] = math.ceil((max_columns - p_width) / 2) - 1
|
||||
pos[1] = math.ceil((max_columns - p_width) / 2) - anchor_padding
|
||||
end
|
||||
if anchor:find "N" then
|
||||
pos[2] = math.ceil((p_height - max_lines) / 2) + 1
|
||||
pos[2] = math.ceil((p_height - max_lines) / 2) + anchor_padding
|
||||
elseif anchor:find "S" then
|
||||
pos[2] = math.ceil((max_lines - p_height) / 2) - 1
|
||||
pos[2] = math.ceil((max_lines - p_height) / 2) - anchor_padding
|
||||
end
|
||||
return pos
|
||||
end
|
||||
|
||||
@ -537,6 +537,7 @@ function Picker:find()
|
||||
|
||||
self.original_bufnr = a.nvim_get_current_buf()
|
||||
self.original_win_id = a.nvim_get_current_win()
|
||||
self.original_tabpage = a.nvim_get_current_tabpage()
|
||||
_, self.original_cword = pcall(vim.fn.expand, "<cword>")
|
||||
_, self.original_cWORD = pcall(vim.fn.expand, "<cWORD>")
|
||||
_, self.original_cfile = pcall(vim.fn.expand, "<cfile>")
|
||||
|
||||
@ -194,6 +194,10 @@ local shared_options = {
|
||||
scroll_speed = "The number of lines to scroll through the previewer",
|
||||
prompt_position = { "Where to place prompt window.", "Available Values: 'bottom', 'top'" },
|
||||
anchor = { "Which edge/corner to pin the picker to", "See |resolver.resolve_anchor_pos()|" },
|
||||
anchor_padding = {
|
||||
"Specifies an amount of additional padding around the anchor",
|
||||
"Values should be a positive integer",
|
||||
},
|
||||
}
|
||||
|
||||
-- Used for generating vim help documentation.
|
||||
@ -375,7 +379,10 @@ layout_strategies.horizontal = make_documented_layout(
|
||||
error(string.format("Unknown prompt_position: %s\n%s", self.window.prompt_position, vim.inspect(layout_config)))
|
||||
end
|
||||
|
||||
local anchor_pos = resolve.resolve_anchor_pos(layout_config.anchor or "", width, height, max_columns, max_lines)
|
||||
local anchor = layout_config.anchor or ""
|
||||
local anchor_padding = layout_config.anchor_padding or 1
|
||||
|
||||
local anchor_pos = resolve.resolve_anchor_pos(anchor, width, height, max_columns, max_lines, anchor_padding)
|
||||
adjust_pos(anchor_pos, prompt, results, preview)
|
||||
|
||||
if tbln then
|
||||
@ -486,7 +493,9 @@ layout_strategies.center = make_documented_layout(
|
||||
results.col, preview.col, prompt.col = width_padding, width_padding, width_padding
|
||||
|
||||
local anchor = layout_config.anchor or ""
|
||||
local anchor_pos = resolve.resolve_anchor_pos(anchor, width, height, max_columns, max_lines)
|
||||
local anchor_padding = layout_config.anchor_padding or 1
|
||||
|
||||
local anchor_pos = resolve.resolve_anchor_pos(anchor, width, height, max_columns, max_lines, anchor_padding)
|
||||
adjust_pos(anchor_pos, prompt, results, preview)
|
||||
|
||||
-- Vertical anchoring (S or N variations) ignores layout_config.mirror
|
||||
@ -740,7 +749,10 @@ layout_strategies.vertical = make_documented_layout(
|
||||
end
|
||||
end
|
||||
|
||||
local anchor_pos = resolve.resolve_anchor_pos(layout_config.anchor or "", width, height, max_columns, max_lines)
|
||||
local anchor = layout_config.anchor or ""
|
||||
local anchor_padding = layout_config.anchor_padding or 1
|
||||
|
||||
local anchor_pos = resolve.resolve_anchor_pos(anchor, width, height, max_columns, max_lines, anchor_padding)
|
||||
adjust_pos(anchor_pos, prompt, results, preview)
|
||||
|
||||
if tbln then
|
||||
|
||||
@ -91,12 +91,15 @@ end
|
||||
--- - `title` a static title for example "File Preview"
|
||||
--- - `dyn_title(self, entry)` a dynamic title function which gets called
|
||||
--- when config value `dynamic_preview_title = true`
|
||||
--- - `env` table: define environment variables to forward to the terminal
|
||||
--- process. Example:
|
||||
--- - `{ ['PAGER'] = '', ['MANWIDTH'] = 50 }`
|
||||
---
|
||||
--- It's an easy way to get your first previewer going and it integrates well
|
||||
--- with `bat` and `less`. Providing out of the box scrolling if the command
|
||||
--- uses less.
|
||||
---
|
||||
--- Furthermore, it will forward all `config.set_env` environment variables to
|
||||
--- Furthermore, if `env` is not set, it will forward all `config.set_env` environment variables to
|
||||
--- that terminal process.
|
||||
previewers.new_termopen_previewer = term_previewer.new_termopen_previewer
|
||||
|
||||
|
||||
@ -202,7 +202,7 @@ previewers.new_termopen_previewer = function(opts)
|
||||
|
||||
local term_opts = {
|
||||
cwd = opts.cwd or vim.loop.cwd(),
|
||||
env = conf.set_env,
|
||||
env = opts.env or conf.set_env,
|
||||
}
|
||||
|
||||
local cmd = opts.get_command(entry, status)
|
||||
|
||||
Reference in New Issue
Block a user