feat: truncate option for path_display (#1254)
This commit is contained in:
@@ -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`.
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user