Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch errors that occur in telescope.utils#transform_path #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lua/telescope/_extensions/git_worktree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,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