fix(make_entry): improve filename_first support (#3140)

Few pickers with entry makers that relied on `entry_display.create` were
not properly passing the highlight table returned by `transform_path`.
This made the `filename_first` `path_display` option not work as
expected for these pickers.
This commit is contained in:
James Trew
2024-05-26 21:50:31 -04:00
committed by GitHub
parent 349660c0d3
commit 4c96370cf9
2 changed files with 34 additions and 12 deletions

View File

@@ -132,12 +132,12 @@ diagnostics.get = function(opts)
if opts.bufnr ~= 0 then if opts.bufnr ~= 0 then
opts.bufnr = nil opts.bufnr = nil
end end
if opts.bufnr == nil then
opts.path_display = vim.F.if_nil(opts.path_display, {})
end
if type(opts.bufnr) == "string" then if type(opts.bufnr) == "string" then
opts.bufnr = tonumber(opts.bufnr) opts.bufnr = tonumber(opts.bufnr)
end end
if opts.bufnr ~= nil then
opts.path_display = vim.F.if_nil(opts.path_display, "hidden")
end
local locations = diagnostics_to_tbl(opts) local locations = diagnostics_to_tbl(opts)
@@ -157,7 +157,6 @@ diagnostics.get = function(opts)
return return
end end
opts.path_display = vim.F.if_nil(opts.path_display, "hidden")
pickers pickers
.new(opts, { .new(opts, {
prompt_title = opts.bufnr == nil and "Workspace Diagnostics" or "Document Diagnostics", prompt_title = opts.bufnr == nil and "Workspace Diagnostics" or "Document Diagnostics",

View File

@@ -184,7 +184,7 @@ do
if k == "path" then if k == "path" then
local retpath = Path:new({ t.cwd, t.value }):absolute() local retpath = Path:new({ t.cwd, t.value }):absolute()
if not vim.loop.fs_access(retpath, "R", nil) then if not vim.loop.fs_access(retpath, "R") then
retpath = t.value retpath = t.value
end end
return retpath return retpath
@@ -540,8 +540,14 @@ function make_entry.gen_from_lsp_symbols(opts)
msg, msg,
} }
else else
local display_path, path_style = utils.transform_path(opts, entry.filename)
return displayer { return displayer {
utils.transform_path(opts, entry.filename), {
display_path,
function()
return path_style
end,
},
entry.symbol_name, entry.symbol_name,
{ entry.symbol_type:lower(), type_highlight[entry.symbol_type] }, { entry.symbol_type:lower(), type_highlight[entry.symbol_type] },
msg, msg,
@@ -1043,7 +1049,7 @@ function make_entry.gen_from_ctags(opts)
} }
local make_display = function(entry) local make_display = function(entry)
local filename = utils.transform_path(opts, entry.filename) local display_path, path_style = utils.transform_path(opts, entry.filename)
local scode local scode
if opts.show_line then if opts.show_line then
@@ -1057,7 +1063,12 @@ function make_entry.gen_from_ctags(opts)
} }
else else
return displayer { return displayer {
filename, {
display_path,
function()
return path_style
end,
},
entry.tag, entry.tag,
scode, scode,
} }
@@ -1073,7 +1084,7 @@ function make_entry.gen_from_ctags(opts)
if k == "path" then if k == "path" then
local retpath = Path:new({ t.filename }):absolute() local retpath = Path:new({ t.filename }):absolute()
if not vim.loop.fs_access(retpath, "R", nil) then if not vim.loop.fs_access(retpath, "R") then
retpath = t.filename retpath = t.filename
end end
return retpath return retpath
@@ -1174,7 +1185,7 @@ function make_entry.gen_from_diagnostics(opts)
} }
local make_display = function(entry) local make_display = function(entry)
local filename = utils.transform_path(opts, entry.filename) local display_path, path_style = utils.transform_path(opts, entry.filename)
-- add styling of entries -- add styling of entries
local pos = string.format("%4d:%2d", entry.lnum, entry.col) local pos = string.format("%4d:%2d", entry.lnum, entry.col)
@@ -1187,7 +1198,12 @@ function make_entry.gen_from_diagnostics(opts)
return displayer { return displayer {
line_info, line_info,
entry.text, entry.text,
filename, {
display_path,
function()
return path_style
end,
},
} }
end end
@@ -1345,11 +1361,18 @@ function make_entry.gen_from_git_status(opts)
local status_x = git_abbrev[x] or {} local status_x = git_abbrev[x] or {}
local status_y = git_abbrev[y] or {} local status_y = git_abbrev[y] or {}
local display_path, path_style = utils.transform_path(opts, entry.path)
local empty_space = " " local empty_space = " "
return displayer { return displayer {
{ status_x.icon or empty_space, status_x.hl }, { status_x.icon or empty_space, status_x.hl },
{ status_y.icon or empty_space, status_y.hl }, { status_y.icon or empty_space, status_y.hl },
utils.transform_path(opts, entry.path), {
display_path,
function()
return path_style
end,
},
} }
end end