feat: truncate option for path_display (#1254)

This commit is contained in:
Luke Kershaw
2021-09-19 19:38:00 +01:00
committed by GitHub
parent e53cf55225
commit f0db7d3a59
4 changed files with 20 additions and 0 deletions

View File

@@ -191,6 +191,8 @@ telescope.setup({opts}) *telescope.setup()*
the difference between the displayed paths the difference between the displayed paths
- "shorten" only display the first character of each directory in - "shorten" only display the first character of each directory in
the path 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 You can also specify the number of characters of each directory name
to keep by setting `path_display.shorten = num`. to keep by setting `path_display.shorten = num`.

View File

@@ -256,6 +256,8 @@ append(
the difference between the displayed paths the difference between the displayed paths
- "shorten" only display the first character of each directory in - "shorten" only display the first character of each directory in
the path 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 You can also specify the number of characters of each directory name
to keep by setting `path_display.shorten = num`. to keep by setting `path_display.shorten = num`.

View File

@@ -330,6 +330,7 @@ end
function make_entry.gen_from_lsp_symbols(opts) function make_entry.gen_from_lsp_symbols(opts)
opts = opts or {} opts = opts or {}
local bufnr = opts.bufnr or vim.api.nvim_get_current_buf() local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
local display_items = { local display_items = {
@@ -932,6 +933,7 @@ end
function make_entry.gen_from_lsp_diagnostics(opts) function make_entry.gen_from_lsp_diagnostics(opts)
opts = opts or {} opts = opts or {}
local lsp_type_diagnostic = vim.lsp.protocol.DiagnosticSeverity local lsp_type_diagnostic = vim.lsp.protocol.DiagnosticSeverity
local signs local signs

View File

@@ -3,6 +3,9 @@ local Job = require "plenary.job"
local log = require "telescope.log" local log = require "telescope.log"
local truncate = require("plenary.strings").truncate
local get_status = require("telescope.state").get_status
local utils = {} local utils = {}
utils.get_separator = function() utils.get_separator = function()
@@ -326,6 +329,11 @@ local is_uri = function(filename)
return string.match(filename, "^%w+://") ~= nil return string.match(filename, "^%w+://") ~= nil
end 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) utils.transform_path = function(opts, path)
if is_uri(path) then if is_uri(path) then
return path 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 if vim.tbl_contains(path_display, "shorten") or path_display["shorten"] ~= nil then
transformed_path = Path:new(transformed_path):shorten(path_display["shorten"]) transformed_path = Path:new(transformed_path):shorten(path_display["shorten"])
end 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 end
return transformed_path return transformed_path