From 8c3f2b630be0241fe10709e61ee9dab473518f32 Mon Sep 17 00:00:00 2001 From: Luke Kershaw <35707277+l-kershaw@users.noreply.github.com> Date: Sun, 18 Jul 2021 12:19:27 +0100 Subject: [PATCH] feat: check type of `path_display` and warn user if wrong (#1023) --- lua/telescope/utils.lua | 47 +++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 6e35b81..eb59962 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -281,34 +281,39 @@ utils.transform_path = function(opts, path) if type(path_display) == "function" then return path_display(opts, transformed_path) - end - if utils.is_path_hidden(nil, path_display) then - return '' - end + elseif utils.is_path_hidden(nil, path_display) then + return '' - if vim.tbl_contains(path_display, "tail") or path_display.tail then - transformed_path = utils.path_tail(transformed_path) - else - if not vim.tbl_contains(path_display, "absolute") or path_display.absolute == false then - local cwd - if opts.cwd then - cwd = opts.cwd - if not vim.in_fast_event() then - cwd = vim.fn.expand(opts.cwd) + elseif type(path_display) == "table" then + + if vim.tbl_contains(path_display, "tail") or path_display.tail then + transformed_path = utils.path_tail(transformed_path) + else + if not vim.tbl_contains(path_display, "absolute") or path_display.absolute == false then + local cwd + if opts.cwd then + cwd = opts.cwd + if not vim.in_fast_event() then + cwd = vim.fn.expand(opts.cwd) + end + else + cwd = vim.loop.cwd(); end - else - cwd = vim.loop.cwd(); + transformed_path = Path:new(transformed_path):make_relative(cwd) + end + + if vim.tbl_contains(path_display, "shorten") or path_display["shorten"] ~= nil then + transformed_path = Path:new(transformed_path):shorten(path_display["shorten"]) end - transformed_path = Path:new(transformed_path):make_relative(cwd) end - if vim.tbl_contains(path_display, "shorten") or path_display["shorten"] ~= nil then - transformed_path = Path:new(transformed_path):shorten(path_display["shorten"]) - end + return transformed_path + else + log.warn("`path_display` must be either a function or a table.", + "See `:help telescope.defaults.path_display.") + return transformed_path end - - return transformed_path end -- local x = utils.make_default_callable(function(opts)