feat(entry_maker): add 'filename_first' option for path_display (#3010)

* Initial commit

* Fixes issue with find_files where devicons where disabled

* Fixes issue with vimgrep where devicons where disabled

* Fixes trailing space for path with only a file name

* Adds test for reverse path_display

* Refactors reverse to filename_first

* Adds tests

* Fixes highlighting

* Fixes linting issues

* Uses trim function

* Fixes issue with highlighting

* Moves local function to utils

* Removes redundant code

* Adds highlighting for gen_from_buffer

* fix formatting

---------

Co-authored-by: alycklama <>
Co-authored-by: James Trew <j.trew10@gmail.com>
This commit is contained in:
Anton
2024-04-20 06:21:35 +02:00
committed by GitHub
parent 10d57f38f5
commit a4432dfb9b
5 changed files with 155 additions and 40 deletions

View File

@@ -158,14 +158,16 @@ do
mt_file_entry.cwd = cwd
mt_file_entry.display = function(entry)
local hl_group, icon
local display = utils.transform_path(opts, entry.value)
local display, path_style = utils.transform_path(opts, entry.value)
display, hl_group, icon = utils.transform_devicons(entry.value, display, disable_devicons)
if hl_group then
return display, { { { 0, #icon }, hl_group } }
local style = { { { 0, #icon + 1 }, hl_group } }
style = utils.merge_styles(style, path_style, #icon + 1)
return display, style
else
return display
return display, path_style
end
end
@@ -313,7 +315,7 @@ do
cwd = utils.path_expand(opts.cwd or vim.loop.cwd()),
display = function(entry)
local display_filename = utils.transform_path(opts, entry.filename)
local display_filename, path_style = utils.transform_path(opts, entry.filename)
local coordinates = ":"
if not disable_coordinates then
@@ -333,9 +335,11 @@ do
)
if hl_group then
return display, { { { 0, #icon }, hl_group } }
local style = { { { 0, #icon }, hl_group } }
style = utils.merge_styles(style, path_style, #icon + 1)
return display, style
else
return display
return display, path_style
end
end,
@@ -454,7 +458,7 @@ function make_entry.gen_from_quickfix(opts)
local hidden = utils.is_path_hidden(opts)
local make_display = function(entry)
local display_filename = utils.transform_path(opts, entry.filename)
local display_filename, path_style = utils.transform_path(opts, entry.filename)
local display_string = string.format("%s:%d:%d", display_filename, entry.lnum, entry.col)
if hidden then
display_string = string.format("%4d:%2d", entry.lnum, entry.col)
@@ -469,7 +473,7 @@ function make_entry.gen_from_quickfix(opts)
display_string = display_string .. ":" .. text
end
return display_string
return display_string, path_style
end
local get_filename = get_filename_fn()
@@ -597,14 +601,19 @@ function make_entry.gen_from_buffer(opts)
local make_display = function(entry)
-- bufnr_width + modes + icon + 3 spaces + : + lnum
opts.__prefix = opts.bufnr_width + 4 + icon_width + 3 + 1 + #tostring(entry.lnum)
local display_bufname = utils.transform_path(opts, entry.filename)
local display_bufname, path_style = utils.transform_path(opts, entry.filename)
local icon, hl_group = utils.get_devicons(entry.filename, disable_devicons)
return displayer {
{ entry.bufnr, "TelescopeResultsNumber" },
{ entry.indicator, "TelescopeResultsComment" },
{ icon, hl_group },
display_bufname .. ":" .. entry.lnum,
{
display_bufname .. ":" .. entry.lnum,
function()
return path_style
end,
},
}
end