diff options
| author | tzachar <Nir.tzachar@gmail.com> | 2023-01-06 12:58:16 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-06 11:58:16 +0100 |
| commit | c571d96fe52a7f30787a4a9ee7abf6d931ea5902 (patch) | |
| tree | be2b4ea9d17b8bf8e712ecacf2f609bda01e18c1 /lua/telescope/make_entry.lua | |
| parent | a606bd10c79ec5989c76c49cc6f736e88b63f0da (diff) | |
fix: do not use nvim_buf_line_count on unloaded buffers (#2261)
Diffstat (limited to 'lua/telescope/make_entry.lua')
| -rw-r--r-- | lua/telescope/make_entry.lua | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 6b096da..362c1b6 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -641,7 +641,18 @@ function make_entry.gen_from_buffer(opts) local readonly = vim.api.nvim_buf_get_option(entry.bufnr, "readonly") and "=" or " " local changed = entry.info.changed == 1 and "+" or " " local indicator = entry.flag .. hidden .. readonly .. changed - local line_count = vim.api.nvim_buf_line_count(entry.bufnr) + local lnum = 1 + + -- account for potentially stale lnum as getbufinfo might not be updated or from resuming buffers picker + if entry.info.lnum ~= 0 then + -- but make sure the buffer is loaded, otherwise line_count is 0 + if vim.api.nvim_buf_is_loaded(entry.bufnr) then + local line_count = vim.api.nvim_buf_line_count(entry.bufnr) + lnum = math.max(math.min(entry.info.lnum, line_count), 1) + else + lnum = entry.info.lnum + end + end return make_entry.set_default_entry_mt({ value = bufname, @@ -650,8 +661,7 @@ function make_entry.gen_from_buffer(opts) bufnr = entry.bufnr, filename = bufname, - -- account for potentially stale lnum as getbufinfo might not be updated or from resuming buffers picker - lnum = entry.info.lnum ~= 0 and math.max(math.min(entry.info.lnum, line_count), 1) or 1, + lnum = lnum, indicator = indicator, }, opts) end |
