fix(builtin.buffers): previews with specified cwd option (#3111)

Currently, the buffer name is normalized to the `cwd` option value.
This buffer name is then used as the filename, which is used as the file
path for the previewer. But if the `cwd` value is not the actual cwd,
the buffer path can no longer be found by the previewer (relative to the
true cwd).

This is fixed by adding a `path` value to the entry that's the full path
of the buffer. The previewer will then use this full path to find the
file to preview.
This commit is contained in:
James Trew
2024-05-16 22:55:28 -04:00
committed by GitHub
parent 52f500110b
commit ccaeeb5af5

View File

@@ -618,9 +618,8 @@ function make_entry.gen_from_buffer(opts)
end end
return function(entry) return function(entry)
local bufname = entry.info.name ~= "" and entry.info.name or "[No Name]" local filename = entry.info.name ~= "" and entry.info.name or nil
-- if bufname is inside the cwd, trim that part of the string local bufname = filename and Path:new(filename):normalize(cwd) or "[No Name]"
bufname = Path:new(bufname):normalize(cwd)
local hidden = entry.info.hidden == 1 and "h" or "a" local hidden = entry.info.hidden == 1 and "h" or "a"
local readonly = vim.api.nvim_buf_get_option(entry.bufnr, "readonly") and "=" or " " local readonly = vim.api.nvim_buf_get_option(entry.bufnr, "readonly") and "=" or " "
@@ -643,8 +642,8 @@ function make_entry.gen_from_buffer(opts)
value = bufname, value = bufname,
ordinal = entry.bufnr .. " : " .. bufname, ordinal = entry.bufnr .. " : " .. bufname,
display = make_display, display = make_display,
bufnr = entry.bufnr, bufnr = entry.bufnr,
path = filename,
filename = bufname, filename = bufname,
lnum = lnum, lnum = lnum,
indicator = indicator, indicator = indicator,