Skip to content

Commit

Permalink
fix: cache opts.cwd so it cannot be changed by another function
Browse files Browse the repository at this point in the history
I'm not sure why but for me opts.cwd reverted back to my home directory
in the make_display function (while it's correct in the gen_from_fd
function). By caching it this way, it works fine 🤷

See also #70
  • Loading branch information
entropitor authored and cljoly committed Mar 20, 2024
1 parent b4c0b70 commit ca8a541
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lua/telescope/_extensions/repo/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ local function gen_from_fd(opts)
items = { {} },
})

-- This prevents opts.cwd from changing later when it’s called in the
-- display function
local cwd = opts.cwd
local function make_display(entry)
local dir = (function(path)
if path == Path.path.root() then
Expand All @@ -83,8 +86,8 @@ local function gen_from_fd(opts)
return p:shorten()
end

if vim.startswith(path, opts.cwd) and path ~= opts.cwd then
return Path:new(p):make_relative(opts.cwd)
if vim.startswith(path, cwd) and path ~= cwd then
return Path:new(p):make_relative(cwd)
end

if vim.startswith(path, os_home) then
Expand Down

0 comments on commit ca8a541

Please sign in to comment.