From edc6f55ba2565930310542b3023f00e88dd3e6a8 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 22 May 2022 11:32:55 +0200 Subject: docs: document limitations of file_ignore_patterns and transform_path (#1955) --- lua/telescope/utils.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lua/telescope/utils.lua') diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 2a8de58..7692409 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -1,3 +1,10 @@ +---@tag telescope.utils +---@config { ["module"] = "telescope.utils" } + +---@brief [[ +--- Utilities for writing telescope pickers +---@brief ]] + local Path = require "plenary.path" local Job = require "plenary.job" @@ -210,6 +217,16 @@ local calc_result_length = function(truncate_len) return type(truncate_len) == "number" and len - truncate_len or len end +--- Transform path is a util function that formats a path based on path_display +--- found in `opts` or the default value from config. +--- It is meant to be used in make_entry to have a uniform interface for +--- builtins as well as extensions utilizing the same user configuration +--- Note: It is only supported inside `make_entry`/`make_display` the use of +--- this function outside of telescope might yield to undefined behavior and will +--- not be addressed by us +---@param opts table: The opts the users passed into the picker. Might contains a path_display key +---@param path string: The path that should be formated +---@return string: The transformed path ready to be displayed utils.transform_path = function(opts, path) if path == nil then return -- cgit v1.2.3 From 83b6cadb2c61b6eee6a8f0ec8bb4599c89b6ab57 Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Sun, 22 May 2022 12:53:37 +0200 Subject: break: deprecate utils.get_default utils.if_nil (#1545) --- lua/telescope/utils.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lua/telescope/utils.lua') diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 7692409..07800b2 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -20,6 +20,7 @@ utils.get_separator = function() end utils.if_nil = function(x, was_nil, was_not_nil) + log.error "telescope.utils.if_nil is deprecated and will be removed. Please use vim.F.if_nil" if x == nil then return was_nil else @@ -28,6 +29,7 @@ utils.if_nil = function(x, was_nil, was_not_nil) end utils.get_default = function(x, default) + log.error "telescope.utils.get_default is deprecated and will be removed. Please use vim.F.if_nil" return utils.if_nil(x, default, x) end @@ -198,7 +200,7 @@ utils.path_tail = (function() end)() utils.is_path_hidden = function(opts, path_display) - path_display = path_display or utils.get_default(opts.path_display, require("telescope.config").values.path_display) + path_display = path_display or vim.F.if_nil(opts.path_display, require("telescope.config").values.path_display) return path_display == nil or path_display == "hidden" @@ -235,7 +237,7 @@ utils.transform_path = function(opts, path) return path end - local path_display = utils.get_default(opts.path_display, require("telescope.config").values.path_display) + local path_display = vim.F.if_nil(opts.path_display, require("telescope.config").values.path_display) local transformed_path = path -- cgit v1.2.3 From 1ba967f84e8416de9a3423bd693ec77744df8bff Mon Sep 17 00:00:00 2001 From: Simon Hauser Date: Thu, 30 Jun 2022 14:29:46 +0200 Subject: fix: truncate for builtin.buffers fix #2022 --- lua/telescope/utils.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lua/telescope/utils.lua') diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index 07800b2..356d102 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -276,7 +276,10 @@ utils.transform_path = function(opts, path) if opts.__length == nil then opts.__length = calc_result_length(path_display.truncate) end - transformed_path = truncate(transformed_path, opts.__length, nil, -1) + if opts.__prefix == nil then + opts.__prefix = 0 + end + transformed_path = truncate(transformed_path, opts.__length - opts.__prefix, nil, -1) end end -- cgit v1.2.3