summaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authorLuke Kershaw <35707277+l-kershaw@users.noreply.github.com>2021-09-19 19:38:00 +0100
committerGitHub <noreply@github.com>2021-09-19 20:38:00 +0200
commitf0db7d3a5997cbd7e60638a071c1b661a854dfc6 (patch)
tree77850c0c236a0db2010ce817ed92296308613083 /lua
parente53cf55225e30932237ed7bba5aa45c09eb08e87 (diff)
feat: `truncate` option for `path_display` (#1254)
Diffstat (limited to 'lua')
-rw-r--r--lua/telescope/config.lua2
-rw-r--r--lua/telescope/make_entry.lua2
-rw-r--r--lua/telescope/utils.lua14
3 files changed, 18 insertions, 0 deletions
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