fix: no longer leaking one buffer previewer in some occasions (#664)
* fix: stop leaking last preview buffer * fix: formatting for docs * fix: async check if file is dir or not and - fix for in_fast_event when overriding file_maker * fix: filtering for space in keymaps and fzy * fix: show correct result numbers when using file_ignore_patterns * Handle early close. Caused because we actually cleaning up buffers now * cleanup * [docgen] Update doc/telescope.txt
This commit is contained in:
@@ -23,44 +23,44 @@ telescope.setup({opts}) *telescope.setup()*
|
|||||||
entry_prefix: ~
|
entry_prefix: ~
|
||||||
Prefix in front of each result entry. Current selection not included.
|
Prefix in front of each result entry. Current selection not included.
|
||||||
|
|
||||||
Default: ' '
|
Default: ' '
|
||||||
|
|
||||||
*telescope.defaults.prompt_prefix*
|
*telescope.defaults.prompt_prefix*
|
||||||
prompt_prefix: ~
|
prompt_prefix: ~
|
||||||
Will be shown in front of the prompt.
|
Will be shown in front of the prompt.
|
||||||
|
|
||||||
Default: '> '
|
Default: '> '
|
||||||
|
|
||||||
*telescope.defaults.scroll_strategy*
|
*telescope.defaults.scroll_strategy*
|
||||||
scroll_strategy: ~
|
scroll_strategy: ~
|
||||||
Determines what happens you try to scroll past view of the picker.
|
Determines what happens you try to scroll past view of the picker.
|
||||||
|
|
||||||
Available options are:
|
Available options are:
|
||||||
- "cycle" (default)
|
- "cycle" (default)
|
||||||
- "limit"
|
- "limit"
|
||||||
|
|
||||||
*telescope.defaults.selection_caret*
|
*telescope.defaults.selection_caret*
|
||||||
selection_caret: ~
|
selection_caret: ~
|
||||||
Will be shown in front of the selection.
|
Will be shown in front of the selection.
|
||||||
|
|
||||||
Default: '> '
|
Default: '> '
|
||||||
|
|
||||||
*telescope.defaults.selection_strategy*
|
*telescope.defaults.selection_strategy*
|
||||||
selection_strategy: ~
|
selection_strategy: ~
|
||||||
Determines how the cursor acts after each sort iteration.
|
Determines how the cursor acts after each sort iteration.
|
||||||
|
|
||||||
Available options are:
|
Available options are:
|
||||||
- "reset" (default)
|
- "reset" (default)
|
||||||
- "follow"
|
- "follow"
|
||||||
- "row"
|
- "row"
|
||||||
|
|
||||||
*telescope.defaults.sorting_strategy*
|
*telescope.defaults.sorting_strategy*
|
||||||
sorting_strategy: ~
|
sorting_strategy: ~
|
||||||
Determines the direction "better" results are sorted towards.
|
Determines the direction "better" results are sorted towards.
|
||||||
|
|
||||||
Available options are:
|
Available options are:
|
||||||
- "descending" (default)
|
- "descending" (default)
|
||||||
- "ascending"
|
- "ascending"
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
{opts} (table) Configuration opts. Keys: defaults, extensions
|
{opts} (table) Configuration opts. Keys: defaults, extensions
|
||||||
@@ -269,8 +269,10 @@ previewers.new_termopen_previewer() *previewers.new_termopen_previewer()*
|
|||||||
|
|
||||||
It requires you to specify one table entry `get_command(entry, status)`.
|
It requires you to specify one table entry `get_command(entry, status)`.
|
||||||
This `get_command` function has to return the terminal command that will be
|
This `get_command` function has to return the terminal command that will be
|
||||||
executed for each entry. Example: get_command = function(entry, status)
|
executed for each entry. Example:
|
||||||
return { 'bat', entry.path } end
|
get_command = function(entry, status)
|
||||||
|
return { 'bat', entry.path }
|
||||||
|
end
|
||||||
|
|
||||||
It's an easy way to get your first previewer going and it integrates well
|
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
|
with `bat` and `less`. Providing out of the box scrolling if the command
|
||||||
|
|||||||
@@ -683,7 +683,7 @@ internal.keymaps = function(opts)
|
|||||||
return {
|
return {
|
||||||
valid = line ~= "",
|
valid = line ~= "",
|
||||||
value = line,
|
value = line,
|
||||||
ordinal = line.lhs .. line.rhs,
|
ordinal = utils.display_termcodes(line.lhs) .. line.rhs,
|
||||||
display = line.mode .. ' ' .. utils.display_termcodes(line.lhs) .. ' ' .. line.rhs
|
display = line.mode .. ' ' .. utils.display_termcodes(line.lhs) .. ' ' .. line.rhs
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -59,8 +59,7 @@ function config.set_defaults(defaults)
|
|||||||
|
|
||||||
config.values[name] = get(name, default_val)
|
config.values[name] = get(name, default_val)
|
||||||
if description then
|
if description then
|
||||||
-- TODO(conni2461): trim is wrong. We need to do dedent here
|
config.descriptions[name] = dedent(description)
|
||||||
config.descriptions[name] = dedent(vim.trim(description))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -69,8 +68,7 @@ function config.set_defaults(defaults)
|
|||||||
|
|
||||||
Available options are:
|
Available options are:
|
||||||
- "descending" (default)
|
- "descending" (default)
|
||||||
- "ascending"
|
- "ascending"]])
|
||||||
]])
|
|
||||||
|
|
||||||
set("selection_strategy", "reset", [[
|
set("selection_strategy", "reset", [[
|
||||||
Determines how the cursor acts after each sort iteration.
|
Determines how the cursor acts after each sort iteration.
|
||||||
@@ -78,16 +76,14 @@ function config.set_defaults(defaults)
|
|||||||
Available options are:
|
Available options are:
|
||||||
- "reset" (default)
|
- "reset" (default)
|
||||||
- "follow"
|
- "follow"
|
||||||
- "row"
|
- "row"]])
|
||||||
]])
|
|
||||||
|
|
||||||
set("scroll_strategy", "cycle", [[
|
set("scroll_strategy", "cycle", [[
|
||||||
Determines what happens you try to scroll past view of the picker.
|
Determines what happens you try to scroll past view of the picker.
|
||||||
|
|
||||||
Available options are:
|
Available options are:
|
||||||
- "cycle" (default)
|
- "cycle" (default)
|
||||||
- "limit"
|
- "limit"]])
|
||||||
]])
|
|
||||||
|
|
||||||
set("layout_strategy", "horizontal")
|
set("layout_strategy", "horizontal")
|
||||||
set("layout_defaults", {})
|
set("layout_defaults", {})
|
||||||
@@ -103,18 +99,15 @@ function config.set_defaults(defaults)
|
|||||||
set("prompt_prefix", "> ", [[
|
set("prompt_prefix", "> ", [[
|
||||||
Will be shown in front of the prompt.
|
Will be shown in front of the prompt.
|
||||||
|
|
||||||
Default: '> '
|
Default: '> ']])
|
||||||
]])
|
|
||||||
set("selection_caret", "> ", [[
|
set("selection_caret", "> ", [[
|
||||||
Will be shown in front of the selection.
|
Will be shown in front of the selection.
|
||||||
|
|
||||||
Default: '> '
|
Default: '> ']])
|
||||||
]])
|
|
||||||
set("entry_prefix", " ", [[
|
set("entry_prefix", " ", [[
|
||||||
Prefix in front of each result entry. Current selection not included.
|
Prefix in front of each result entry. Current selection not included.
|
||||||
|
|
||||||
Default: ' '
|
Default: ' ']])
|
||||||
]])
|
|
||||||
set("initial_mode", "insert")
|
set("initial_mode", "insert")
|
||||||
|
|
||||||
set("border", {})
|
set("border", {})
|
||||||
|
|||||||
@@ -450,7 +450,7 @@ function Picker:find()
|
|||||||
-- Register attach
|
-- Register attach
|
||||||
vim.api.nvim_buf_attach(prompt_bufnr, false, {
|
vim.api.nvim_buf_attach(prompt_bufnr, false, {
|
||||||
on_lines = on_lines,
|
on_lines = on_lines,
|
||||||
on_detach = vim.schedule_wrap(function()
|
on_detach = function()
|
||||||
on_lines = nil
|
on_lines = nil
|
||||||
|
|
||||||
-- TODO: Can we add a "cleanup" / "teardown" function that completely removes these.
|
-- TODO: Can we add a "cleanup" / "teardown" function that completely removes these.
|
||||||
@@ -459,9 +459,11 @@ function Picker:find()
|
|||||||
self.sorter = nil
|
self.sorter = nil
|
||||||
self.manager = nil
|
self.manager = nil
|
||||||
|
|
||||||
|
self.closed = true
|
||||||
|
|
||||||
-- TODO: Should we actually do this?
|
-- TODO: Should we actually do this?
|
||||||
collectgarbage(); collectgarbage()
|
collectgarbage(); collectgarbage()
|
||||||
end),
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- TODO: Use WinLeave as well?
|
-- TODO: Use WinLeave as well?
|
||||||
@@ -902,6 +904,7 @@ end
|
|||||||
function Picker:get_status_updater(prompt_win, prompt_bufnr)
|
function Picker:get_status_updater(prompt_win, prompt_bufnr)
|
||||||
return function()
|
return function()
|
||||||
local text = self:get_status_text()
|
local text = self:get_status_text()
|
||||||
|
if self.closed or not vim.api.nvim_buf_is_valid(prompt_bufnr) then return end
|
||||||
local current_prompt = vim.api.nvim_buf_get_lines(prompt_bufnr, 0, 1, false)[1]
|
local current_prompt = vim.api.nvim_buf_get_lines(prompt_bufnr, 0, 1, false)[1]
|
||||||
if not current_prompt then
|
if not current_prompt then
|
||||||
return
|
return
|
||||||
@@ -931,7 +934,7 @@ end
|
|||||||
|
|
||||||
function Picker:get_result_processor(prompt, status_updater)
|
function Picker:get_result_processor(prompt, status_updater)
|
||||||
return function(entry)
|
return function(entry)
|
||||||
if self:is_done() then return end
|
if self.closed or self:is_done() then return end
|
||||||
|
|
||||||
self:_increment("processed")
|
self:_increment("processed")
|
||||||
|
|
||||||
@@ -951,7 +954,8 @@ function Picker:get_result_processor(prompt, status_updater)
|
|||||||
local file = type(entry.value) == 'string' and entry.value or entry.filename
|
local file = type(entry.value) == 'string' and entry.value or entry.filename
|
||||||
if file then
|
if file then
|
||||||
if string.find(file, v) then
|
if string.find(file, v) then
|
||||||
log.debug("SKPIPING", entry.value, "because", v)
|
log.debug("SKIPPING", entry.value, "because", v)
|
||||||
|
self:_decrement("processed")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -986,7 +990,7 @@ end
|
|||||||
|
|
||||||
function Picker:get_result_completor(results_bufnr, prompt, status_updater)
|
function Picker:get_result_completor(results_bufnr, prompt, status_updater)
|
||||||
return function()
|
return function()
|
||||||
if self:is_done() then return end
|
if self.closed == true or self:is_done() then return end
|
||||||
|
|
||||||
local selection_strategy = self.selection_strategy or 'reset'
|
local selection_strategy = self.selection_strategy or 'reset'
|
||||||
|
|
||||||
|
|||||||
@@ -66,28 +66,36 @@ previewers.file_maker = function(filepath, bufnr, opts)
|
|||||||
|
|
||||||
if opts.bufname ~= filepath then
|
if opts.bufname ~= filepath then
|
||||||
if not vim.in_fast_event() then filepath = vim.fn.expand(filepath) end
|
if not vim.in_fast_event() then filepath = vim.fn.expand(filepath) end
|
||||||
local stat = vim.loop.fs_stat(filepath) or {}
|
vim.loop.fs_stat(filepath, function(_, stat)
|
||||||
if stat.type == 'directory' then
|
if not stat then return end
|
||||||
pscan.ls_async(filepath, {
|
if stat.type == 'directory' then
|
||||||
hidden = true,
|
pscan.ls_async(filepath, {
|
||||||
group_directories_first = true,
|
hidden = true,
|
||||||
on_exit = vim.schedule_wrap(function(data, sections)
|
group_directories_first = true,
|
||||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, data)
|
on_exit = vim.schedule_wrap(function(data, sections)
|
||||||
colorize_ls(bufnr, data, sections)
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, data)
|
||||||
if opts.callback then opts.callback(bufnr) end
|
colorize_ls(bufnr, data, sections)
|
||||||
end)})
|
if opts.callback then opts.callback(bufnr) end
|
||||||
else
|
end)})
|
||||||
path.read_file_async(filepath, vim.schedule_wrap(function(data)
|
else
|
||||||
if not vim.api.nvim_buf_is_valid(bufnr) then return end
|
path.read_file_async(filepath, vim.schedule_wrap(function(data)
|
||||||
local ok = pcall(vim.api.nvim_buf_set_lines, bufnr, 0, -1, false, vim.split(data, '[\r]?\n'))
|
if not vim.api.nvim_buf_is_valid(bufnr) then return end
|
||||||
if not ok then return end
|
local ok = pcall(vim.api.nvim_buf_set_lines, bufnr, 0, -1, false, vim.split(data, '[\r]?\n'))
|
||||||
|
if not ok then return end
|
||||||
|
|
||||||
if opts.callback then opts.callback(bufnr) end
|
if opts.callback then opts.callback(bufnr) end
|
||||||
putils.highlighter(bufnr, ft)
|
putils.highlighter(bufnr, ft)
|
||||||
end))
|
end))
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
else
|
else
|
||||||
if opts.callback then opts.callback(bufnr) end
|
if opts.callback then
|
||||||
|
if vim.in_fast_event() then
|
||||||
|
vim.schedule(function() opts.callback(bufnr) end)
|
||||||
|
else
|
||||||
|
opts.callback(bufnr)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -112,8 +120,10 @@ previewers.new_buffer_previewer = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function set_bufnr(self, value)
|
local function set_bufnr(self, value)
|
||||||
if get_bufnr(self) then table.insert(old_bufs, get_bufnr(self)) end
|
if self.state then
|
||||||
if self.state then self.state.bufnr = value end
|
self.state.bufnr = value
|
||||||
|
table.insert(old_bufs, value)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_bufnr_by_bufname(self, value)
|
local function get_bufnr_by_bufname(self, value)
|
||||||
@@ -122,8 +132,12 @@ previewers.new_buffer_previewer = function(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function set_bufname(self, value)
|
local function set_bufname(self, value)
|
||||||
if get_bufnr(self) then bufname_table[value] = get_bufnr(self) end
|
if self.state then
|
||||||
if self.state then self.state.bufname = value end
|
self.state.bufname = value
|
||||||
|
if value then
|
||||||
|
bufname_table[value] = get_bufnr(self)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function opts.setup(self)
|
function opts.setup(self)
|
||||||
|
|||||||
@@ -72,9 +72,11 @@ end
|
|||||||
--- It requires you to specify one table entry `get_command(entry, status)`.
|
--- It requires you to specify one table entry `get_command(entry, status)`.
|
||||||
--- This `get_command` function has to return the terminal command that will be
|
--- This `get_command` function has to return the terminal command that will be
|
||||||
--- executed for each entry. Example:
|
--- executed for each entry. Example:
|
||||||
|
--- <pre>
|
||||||
--- get_command = function(entry, status)
|
--- get_command = function(entry, status)
|
||||||
--- return { 'bat', entry.path }
|
--- return { 'bat', entry.path }
|
||||||
--- end
|
--- end
|
||||||
|
--- </pre>
|
||||||
---
|
---
|
||||||
--- It's an easy way to get your first previewer going and it integrates well
|
--- 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
|
--- with `bat` and `less`. Providing out of the box scrolling if the command
|
||||||
|
|||||||
@@ -38,8 +38,7 @@ utils.job_maker = function(cmd, bufnr, opts)
|
|||||||
on_exit = vim.schedule_wrap(function(j)
|
on_exit = vim.schedule_wrap(function(j)
|
||||||
if not vim.api.nvim_buf_is_valid(bufnr) then return end
|
if not vim.api.nvim_buf_is_valid(bufnr) then return end
|
||||||
if opts.mode == "append" then
|
if opts.mode == "append" then
|
||||||
local count = vim.api.nvim_buf_line_count(bufnr)
|
vim.api.nvim_buf_set_lines(bufnr, -1, -1, false, j:result())
|
||||||
vim.api.nvim_buf_set_lines(bufnr, count, -1, false, j:result())
|
|
||||||
elseif opts.mode == "insert" then
|
elseif opts.mode == "insert" then
|
||||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, j:result())
|
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, j:result())
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user