Skip to content

Commit

Permalink
fix(utils): transform_path filename_first composability (#3065)
Browse files Browse the repository at this point in the history
* Moves filename_first to last position to fix issues with composing other options

* Adds comment
  • Loading branch information
alycklama committed Apr 20, 2024
1 parent a4432df commit ef75145
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions lua/telescope/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,28 @@ utils.transform_path = function(opts, path)
transformed_path = Path:new(transformed_path):make_relative(cwd)
end

if vim.tbl_contains(path_display, "shorten") or path_display["shorten"] ~= nil then
if type(path_display["shorten"]) == "table" then
local shorten = path_display["shorten"]
transformed_path = Path:new(transformed_path):shorten(shorten.len, shorten.exclude)
else
local length = type(path_display["shorten"]) == "number" and path_display["shorten"]
transformed_path = Path:new(transformed_path):shorten(length)
end
end

if vim.tbl_contains(path_display, "truncate") or path_display.truncate then
if opts.__length == nil then
opts.__length = calc_result_length(path_display.truncate)
end
if opts.__prefix == nil then
opts.__prefix = 0
end
transformed_path = truncate(transformed_path, opts.__length - opts.__prefix, nil, -1)
end

-- IMPORTANT: filename_first needs to be the last option. Otherwise the
-- other options will not be displayed correctly.
if vim.tbl_contains(path_display, "filename_first") or path_display["filename_first"] ~= nil then
local reverse_directories = false

Expand Down Expand Up @@ -337,26 +359,6 @@ utils.transform_path = function(opts, path)

path_style = { { { #filename, #transformed_path }, "TelescopeResultsComment" } }
end

if vim.tbl_contains(path_display, "shorten") or path_display["shorten"] ~= nil then
if type(path_display["shorten"]) == "table" then
local shorten = path_display["shorten"]
transformed_path = Path:new(transformed_path):shorten(shorten.len, shorten.exclude)
else
local length = type(path_display["shorten"]) == "number" and path_display["shorten"]
transformed_path = Path:new(transformed_path):shorten(length)
end
end

if vim.tbl_contains(path_display, "truncate") or path_display.truncate then
if opts.__length == nil then
opts.__length = calc_result_length(path_display.truncate)
end
if opts.__prefix == nil then
opts.__prefix = 0
end
transformed_path = truncate(transformed_path, opts.__length - opts.__prefix, nil, -1)
end
end

return transformed_path, path_style
Expand Down

0 comments on commit ef75145

Please sign in to comment.