summaryrefslogtreecommitdiff
path: root/lua/telescope/make_entry.lua
diff options
context:
space:
mode:
authorcaojoshua <33404808+caojoshua@users.noreply.github.com>2021-07-08 01:30:44 -0700
committerGitHub <noreply@github.com>2021-07-08 10:30:44 +0200
commitd5a8e48aa632508f5d7d6d428244eaf150adad25 (patch)
tree7d0e7ccdfb9f4c01713c08e42bcb4a6993076a0f /lua/telescope/make_entry.lua
parent38907ce7d74f26d123bfbb8ecf55bc9616b5ece5 (diff)
Consistent filepath display and code cleanup. (#839)
BREAKING CHANGE: see :help telescope.changelog-839 for more information Co-authored-by: Simon Hauser <Simon-Hauser@outlook.de>
Diffstat (limited to 'lua/telescope/make_entry.lua')
-rw-r--r--lua/telescope/make_entry.lua104
1 files changed, 26 insertions, 78 deletions
diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua
index c451805..cfe6509 100644
--- a/lua/telescope/make_entry.lua
+++ b/lua/telescope/make_entry.lua
@@ -5,8 +5,6 @@ local strings = require('plenary.strings')
local Path = require('plenary.path')
-local get_default = utils.get_default
-
local treesitter_type_highlight = {
["associated"] = "TSConstant",
["constant"] = "TSConstant",
@@ -68,17 +66,13 @@ do
local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
local disable_devicons = opts.disable_devicons
- local shorten_path = opts.shorten_path
local mt_file_entry = {}
mt_file_entry.cwd = cwd
mt_file_entry.display = function(entry)
local hl_group
- local display = path.make_relative(entry.value, cwd)
- if shorten_path then
- display = utils.path_shorten(display)
- end
+ local display = utils.transform_path(opts, entry.value)
display, hl_group = utils.transform_devicons(entry.value, display, disable_devicons)
@@ -136,7 +130,6 @@ do
end
--- Special options:
- --- - shorten_path: make the path appear short
--- - disable_coordinates: Don't show the line & row numbers
--- - only_sort_text: Only sort via the text. Ignore filename and other items
function make_entry.gen_from_vimgrep(opts)
@@ -145,7 +138,6 @@ do
opts = opts or {}
local disable_devicons = opts.disable_devicons
- local shorten_path = opts.shorten_path
local disable_coordinates = opts.disable_coordinates
local only_sort_text = opts.only_sort_text
@@ -188,12 +180,7 @@ do
cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd()),
display = function(entry)
- local display_filename
- if shorten_path then
- display_filename = utils.path_shorten(entry.filename)
- else
- display_filename = entry.filename
- end
+ local display_filename = utils.transform_path(opts, entry.filename)
local coordinates = ""
if not disable_coordinates then
@@ -290,7 +277,6 @@ end
function make_entry.gen_from_quickfix(opts)
opts = opts or {}
- opts.tail_path = get_default(opts.tail_path, true)
local displayer = entry_display.create {
separator = "▏",
@@ -302,15 +288,7 @@ function make_entry.gen_from_quickfix(opts)
}
local make_display = function(entry)
- local filename
- if not opts.hide_filename then
- filename = entry.filename
- if opts.tail_path then
- filename = utils.path_tail(filename)
- elseif opts.shorten_path then
- filename = utils.path_shorten(filename)
- end
- end
+ local filename = utils.transform_path(opts, entry.filename)
local line_info = {table.concat({entry.lnum, entry.col}, ":"), "TelescopeResultsLineNr"}
@@ -379,17 +357,7 @@ function make_entry.gen_from_lsp_symbols(opts)
)[1] or ''
msg = vim.trim(msg)
else
- local filename = ""
- opts.tail_path = get_default(opts.tail_path, true)
-
- if not opts.hide_filename then -- hide the filename entirely
- filename = entry.filename
- if opts.tail_path then
- filename = utils.path_tail(filename)
- elseif opts.shorten_path then
- filename = utils.path_shorten(filename)
- end
- end
+ local filename = utils.transform_path(opts, entry.filename)
if opts.show_line then -- show inline line info
filename = filename .. " [" ..entry.lnum .. ":" .. entry.col .. "]"
@@ -463,12 +431,7 @@ function make_entry.gen_from_buffer(opts)
local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
local make_display = function(entry)
- local display_bufname
- if opts.shorten_path then
- display_bufname = path.shorten(entry.filename)
- else
- display_bufname = entry.filename
- end
+ local display_bufname = utils.transform_path(opts, entry.filename)
local icon, hl_group = utils.get_devicons(entry.filename, disable_devicons)
@@ -855,12 +818,15 @@ function make_entry.gen_from_ctags(opts)
local current_file = path.normalize(vim.fn.expand('%'), cwd)
local display_items = {
- { width = 30 },
{ remaining = true },
}
+ local hidden = utils.is_path_hidden(opts)
+ if not hidden then
+ table.insert(display_items, 1, { width = 30 })
+ end
if opts.show_line then
- table.insert(display_items, 2, { width = 30 })
+ table.insert(display_items, 1, { width = 30 })
end
local displayer = entry_display.create {
@@ -869,25 +835,25 @@ function make_entry.gen_from_ctags(opts)
}
local make_display = function(entry)
- local filename
- if not opts.hide_filename then
- if opts.shorten_path then
- filename = path.shorten(entry.filename)
- else
- filename = entry.filename
- end
- end
+ local filename = utils.transform_path(opts, entry.filename)
local scode
if opts.show_line then
scode = entry.scode
end
- return displayer {
- filename,
- entry.tag,
- scode,
- }
+ if hidden then
+ return displayer {
+ entry.tag,
+ scode,
+ }
+ else
+ return displayer {
+ filename,
+ entry.tag,
+ scode,
+ }
+ end
end
return function(line)
@@ -932,7 +898,6 @@ end
function make_entry.gen_from_lsp_diagnostics(opts)
opts = opts or {}
- opts.tail_path = utils.get_default(opts.tail_path, true)
local lsp_type_diagnostic = vim.lsp.protocol.DiagnosticSeverity
local signs
@@ -956,22 +921,14 @@ function make_entry.gen_from_lsp_diagnostics(opts)
{ remaining = true }
}
local line_width = utils.get_default(opts.line_width, 45)
- if not opts.hide_filename then table.insert(layout, 2, {width = line_width}) end
+ if not utils.is_path_hidden(opts) then table.insert(layout, 2, {width = line_width}) end
local displayer = entry_display.create {
separator = "▏",
items = layout
}
local make_display = function(entry)
- local filename
- if not opts.hide_filename then
- filename = entry.filename
- if opts.tail_path then
- filename = utils.path_tail(filename)
- elseif opts.shorten_path then
- filename = utils.path_shorten(filename)
- end
- end
+ local filename = utils.transform_path(opts, entry.filename)
-- add styling of entries
local pos = string.format("%4d:%2d", entry.lnum, entry.col)
@@ -1156,7 +1113,6 @@ end
function make_entry.gen_from_jumplist(opts)
opts = opts or {}
- opts.tail_path = get_default(opts.tail_path, true)
local displayer = entry_display.create {
separator = "▏",
@@ -1167,15 +1123,7 @@ function make_entry.gen_from_jumplist(opts)
}
local make_display = function(entry)
- local filename
- if not opts.hide_filename then
- filename = entry.filename
- if opts.tail_path then
- filename = utils.path_tail(filename)
- elseif opts.shorten_path then
- filename = utils.path_shorten(filename)
- end
- end
+ local filename = utils.transform_path(opts, entry.filename)
local line_info = {table.concat({entry.lnum, entry.col}, ":"), "TelescopeResultsLineNr"}