diff --git a/doc/telescope.txt b/doc/telescope.txt index 02faabe..e479d1e 100644 --- a/doc/telescope.txt +++ b/doc/telescope.txt @@ -191,6 +191,8 @@ telescope.setup({opts}) *telescope.setup()* the difference between the displayed paths - "shorten" only display the first character of each directory in the path + - "truncate" truncates the start of the path when the whole path will + not fit You can also specify the number of characters of each directory name to keep by setting `path_display.shorten = num`. diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index 554d801..7a54ec3 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -256,6 +256,8 @@ append( the difference between the displayed paths - "shorten" only display the first character of each directory in the path + - "truncate" truncates the start of the path when the whole path will + not fit You can also specify the number of characters of each directory name to keep by setting `path_display.shorten = num`. diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index bf0287c..917b6f8 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -330,6 +330,7 @@ end function make_entry.gen_from_lsp_symbols(opts) opts = opts or {} + local bufnr = opts.bufnr or vim.api.nvim_get_current_buf() local display_items = { @@ -932,6 +933,7 @@ end function make_entry.gen_from_lsp_diagnostics(opts) opts = opts or {} + local lsp_type_diagnostic = vim.lsp.protocol.DiagnosticSeverity local signs diff --git a/lua/telescope/utils.lua b/lua/telescope/utils.lua index cddeea5..f145184 100644 --- a/lua/telescope/utils.lua +++ b/lua/telescope/utils.lua @@ -3,6 +3,9 @@ local Job = require "plenary.job" local log = require "telescope.log" +local truncate = require("plenary.strings").truncate +local get_status = require("telescope.state").get_status + local utils = {} utils.get_separator = function() @@ -326,6 +329,11 @@ local is_uri = function(filename) return string.match(filename, "^%w+://") ~= nil end +local calc_result_length = function() + local status = get_status(vim.api.nvim_get_current_buf()) + return vim.api.nvim_win_get_width(status.results_win) - status.picker.selection_caret:len() - 2 +end + utils.transform_path = function(opts, path) if is_uri(path) then return path @@ -361,6 +369,12 @@ utils.transform_path = function(opts, path) if vim.tbl_contains(path_display, "shorten") or path_display["shorten"] ~= nil then transformed_path = Path:new(transformed_path):shorten(path_display["shorten"]) end + if vim.tbl_contains(path_display, "truncate") or path_display.truncate then + if opts.__length == nil then + opts.__length = calc_result_length() + end + transformed_path = truncate(transformed_path, opts.__length, nil, -1) + end end return transformed_path