Skip to content

Commit

Permalink
fix(builtin.buffers): previews with specified cwd option (#3111)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jamestrew authored May 17, 2024
1 parent 52f5001 commit ccaeeb5
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lua/telescope/make_entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,8 @@ function make_entry.gen_from_buffer(opts)
end

return function(entry)
local bufname = entry.info.name ~= "" and entry.info.name or "[No Name]"
-- if bufname is inside the cwd, trim that part of the string
bufname = Path:new(bufname):normalize(cwd)
local filename = entry.info.name ~= "" and entry.info.name or nil
local bufname = filename and Path:new(filename):normalize(cwd) or "[No Name]"

local hidden = entry.info.hidden == 1 and "h" or "a"
local readonly = vim.api.nvim_buf_get_option(entry.bufnr, "readonly") and "=" or " "
Expand All @@ -643,8 +642,8 @@ function make_entry.gen_from_buffer(opts)
value = bufname,
ordinal = entry.bufnr .. " : " .. bufname,
display = make_display,

bufnr = entry.bufnr,
path = filename,
filename = bufname,
lnum = lnum,
indicator = indicator,
Expand Down

0 comments on commit ccaeeb5

Please sign in to comment.