From ca8a541eeb9cba5061db864a2927507a79882a88 Mon Sep 17 00:00:00 2001 From: Jens Claes <896093+entropitor@users.noreply.github.com> Date: Tue, 19 Mar 2024 15:55:50 +0100 Subject: [PATCH] fix: cache opts.cwd so it cannot be changed by another function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 https://github.com/cljoly/telescope-repo.nvim/pull/70 --- lua/telescope/_extensions/repo/main.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lua/telescope/_extensions/repo/main.lua b/lua/telescope/_extensions/repo/main.lua index 4edb23d..61008d7 100644 --- a/lua/telescope/_extensions/repo/main.lua +++ b/lua/telescope/_extensions/repo/main.lua @@ -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 @@ -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