Skip to content

Commit

Permalink
Catch Errors in telescope transform path
Browse files Browse the repository at this point in the history
- Thanks to @brandoncc
  • Loading branch information
bradsherman committed Aug 16, 2023
1 parent 4c96f17 commit 87ed2ab
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lua/telescope/_extensions/git_worktree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,19 @@ local telescope_git_worktree = function(opts)
local index = #results + 1
for key, val in pairs(widths) do
if key == "path" then
local new_path = utils.transform_path(opts, entry[key])
local path_len = strings.strdisplaywidth(new_path or "")
widths[key] = math.max(val, path_len)
-- Some users have found that transform_path raises an error because telescope.state#get_status
-- outputs an empty table. When that happens, we need to use the default value.
-- This seems to happen in distros such as AstroNvim and NvChad
--
-- Reference: https://github.com/ThePrimeagen/git-worktree.nvim/issues/97
local transformed_ok, new_path = pcall(utils.transform_path, opts, entry[key])

if transformed_ok then
local path_len = strings.strdisplaywidth(new_path or "")
widths[key] = math.max(val, path_len)
else
widths[key] = math.max(val, strings.strdisplaywidth(entry[key] or ""))
end
else
widths[key] = math.max(val, strings.strdisplaywidth(entry[key] or ""))
end
Expand Down

0 comments on commit 87ed2ab

Please sign in to comment.