Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: highlighting of path coordinates #3153

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions lua/telescope/make_entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ do
cwd = utils.path_expand(opts.cwd or vim.loop.cwd()),

display = function(entry)
local display_filename, path_style = utils.transform_path(opts, entry.filename)
local display_filename, style = utils.transform_path(opts, entry.filename)

local coordinates = ":"
if not disable_coordinates then
Expand All @@ -328,18 +328,24 @@ do
end
end

-- Adds styling to the coordinates
style = utils.merge_styles(
{ { { #display_filename, #display_filename + #coordinates }, "TelescopeResultsLineNr" } },
style,
0
)

local display, hl_group, icon = utils.transform_devicons(
entry.filename,
string.format(display_string, display_filename, coordinates, entry.text),
disable_devicons
)

if hl_group then
local style = { { { 0, #icon }, hl_group } }
style = utils.merge_styles(style, path_style, #icon + 1)
style = utils.merge_styles({ { { 0, #icon }, hl_group } }, style, #icon + 1)
return display, style
else
return display, path_style
return display, style
end
end,

Expand Down Expand Up @@ -458,22 +464,29 @@ function make_entry.gen_from_quickfix(opts)
local hidden = utils.is_path_hidden(opts)

local make_display = function(entry)
local display_filename, path_style = utils.transform_path(opts, entry.filename)
local display_filename, 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)
end

-- Adds styling to the coordinates
style = utils.merge_styles({ { { #display_filename, #display_string }, "TelescopeResultsLineNr" } }, style, 0)

if show_line then
local text = entry.text
if opts.trim_text then
text = vim.trim(text)
end
text = text:gsub(".* | ", "")

-- Accounts for the added ":" after the display_string
style = utils.merge_styles({ { { #display_string, #display_string + 1 }, "TelescopeResultsLineNr" } }, style, 0)

display_string = display_string .. ":" .. text
end

return display_string, path_style
return display_string, style
end

local get_filename = get_filename_fn()
Expand Down Expand Up @@ -607,17 +620,25 @@ 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, path_style = utils.transform_path(opts, entry.filename)
local display_bufname, style = utils.transform_path(opts, entry.filename)
local coordinates = ":" .. entry.lnum
local icon, hl_group = utils.get_devicons(entry.filename, disable_devicons)

-- Adds styling to the coordinates
style = utils.merge_styles(
{ { { #display_bufname, #display_bufname + #coordinates }, "TelescopeResultsLineNr" } },
style,
0
)

return displayer {
{ entry.bufnr, "TelescopeResultsNumber" },
{ entry.indicator, "TelescopeResultsComment" },
{ icon, hl_group },
{
display_bufname .. ":" .. entry.lnum,
display_bufname .. coordinates,
function()
return path_style
return style
end,
},
}
Expand Down