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>
This commit is contained in:
caojoshua
2021-07-08 01:30:44 -07:00
committed by GitHub
parent 38907ce7d7
commit d5a8e48aa6
11 changed files with 165 additions and 137 deletions

View File

@@ -156,12 +156,12 @@ require('telescope').setup{
file_sorter = require'telescope.sorters'.get_fuzzy_file, file_sorter = require'telescope.sorters'.get_fuzzy_file,
file_ignore_patterns = {}, file_ignore_patterns = {},
generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter, generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter,
shorten_path = true,
winblend = 0, winblend = 0,
border = {}, border = {},
borderchars = { '─', '│', '─', '│', '╭', '╮', '╯', '╰' }, borderchars = { '─', '│', '─', '│', '╭', '╮', '╯', '╰' },
color_devicons = true, color_devicons = true,
use_less = true, use_less = true,
path_display = {},
set_env = { ['COLORTERM'] = 'truecolor' }, -- default = nil, set_env = { ['COLORTERM'] = 'truecolor' }, -- default = nil,
file_previewer = require'telescope.previewers'.vim_buffer_cat.new, file_previewer = require'telescope.previewers'.vim_buffer_cat.new,
grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new, grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new,
@@ -204,6 +204,7 @@ EOF
| `color_devicons` | Whether to color devicons or not | boolean | | `color_devicons` | Whether to color devicons or not | boolean |
| `use_less` | Whether to use less with bat or less/cat if bat not installed | boolean | | `use_less` | Whether to use less with bat or less/cat if bat not installed | boolean |
| `set_env` | Set environment variables for previewer | dict | | `set_env` | Set environment variables for previewer | dict |
| `path_display` | How file paths are displayed | [supported settings](https://github.com/nvim-telescope/telescope.nvim/wiki/Path-Display-Configuration) |
| `file_previewer` | What telescope previewer to use for files. | [Previewers](#previewers) | | `file_previewer` | What telescope previewer to use for files. | [Previewers](#previewers) |
| `grep_previewer` | What telescope previewer to use for grep and similar | [Previewers](#previewers) | | `grep_previewer` | What telescope previewer to use for grep and similar | [Previewers](#previewers) |
| `qflist_previewer` | What telescope previewer to use for qflist | [Previewers](#previewers) | | `qflist_previewer` | What telescope previewer to use for qflist | [Previewers](#previewers) |
@@ -223,7 +224,6 @@ EOF
| `vimgrep_arguments` | The command line argument for grep search ... TODO. | dict | | `vimgrep_arguments` | The command line argument for grep search ... TODO. | dict |
| `selection_strategy` | What happens to the selection if the list changes. | follow/reset/row/closest | | `selection_strategy` | What happens to the selection if the list changes. | follow/reset/row/closest |
| `file_ignore_patterns` | Pattern to be ignored `{ "scratch/.*", "%.env" }` | dict | | `file_ignore_patterns` | Pattern to be ignored `{ "scratch/.*", "%.env" }` | dict |
| `shorten_path` | Whether to shorten paths or not. | boolean |
### Customize Default Builtin behavior ### Customize Default Builtin behavior

View File

@@ -114,13 +114,15 @@ telescope.setup({opts}) *telescope.setup()*
Into your config. Into your config.
otherwise, just set the mapping to the function that you want it to be. otherwise, just set the mapping to the function that you want it to
be.
..., ...,
["<C-i>"] = require('telescope.actions').select_default, ["<C-i>"] = require('telescope.actions').select_default,
..., ...,
If the function you want is part of `telescope.actions`, then you can simply give a string. If the function you want is part of `telescope.actions`, then you can
simply give a string.
For example, the previous option is equivalent to: For example, the previous option is equivalent to:
..., ...,
@@ -136,6 +138,21 @@ telescope.setup({opts}) *telescope.setup()*
..., ...,
*telescope.defaults.path_display*
path_display: ~
Determines how file paths are displayed
path_display can be set to an array with a combination of:
- "hidden" hide file names
- "tail" only display the file name, and not the path
- "absolute" display absolute paths
- "shorten" only display the first character of each directory in
the path
path_display can also be set to 'hidden' string to hide file names
Default: {}
*telescope.defaults.prompt_prefix* *telescope.defaults.prompt_prefix*
prompt_prefix: ~ prompt_prefix: ~
Will be shown in front of the prompt. Will be shown in front of the prompt.
@@ -728,14 +745,9 @@ builtin.tags({opts}) *builtin.tags()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Fields: ~ Fields: ~
{ctags_file} (string) specify a particular ctags file to use {ctags_file} (string) specify a particular ctags file to use
{show_line} (boolean) if true, shows the content of the line the {show_line} (boolean) if true, shows the content of the line the tag
tag is found on in the picker (default is is found on in the picker (default is true)
true)
{shorten_path} (boolean) if true, makes file paths shown in picker
use one letter for folders (default is true)
{hide_filename} (boolean) if true, hides the name of the file in the
current picker (default is false)
builtin.current_buffer_tags({opts}) *builtin.current_buffer_tags()* builtin.current_buffer_tags({opts}) *builtin.current_buffer_tags()*
@@ -1045,12 +1057,6 @@ builtin.tagstack({opts}) *builtin.tagstack()*
Parameters: ~ Parameters: ~
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Fields: ~
{shorten_path} (boolean) if true, makes file paths shown in picker
use one letter for folders (default is true)
{hide_filename} (boolean) if true, hides the name of the file in the
current picker (default is true)
builtin.jumplist({opts}) *builtin.jumplist()* builtin.jumplist({opts}) *builtin.jumplist()*
Lists items from Vim's jumplist, jumps to location on `<cr>` Lists items from Vim's jumplist, jumps to location on `<cr>`
@@ -1068,10 +1074,6 @@ builtin.lsp_references({opts}) *builtin.lsp_references()*
Parameters: ~ Parameters: ~
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Fields: ~
{shorten_path} (boolean) if true, makes file paths shown in picker use
one letter for folders (default is false)
builtin.lsp_definitions({opts}) *builtin.lsp_definitions()* builtin.lsp_definitions({opts}) *builtin.lsp_definitions()*
Goto the definition of the word under the cursor, if there's only one, Goto the definition of the word under the cursor, if there's only one,
@@ -1134,13 +1136,7 @@ builtin.lsp_workspace_symbols({opts}) *builtin.lsp_workspace_symbols()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Fields: ~ Fields: ~
{shorten_path} (boolean) if true, makes file paths shown in
picker use one letter for folders
(default is false)
{ignore_filename} (string) file(s) to ignore {ignore_filename} (string) file(s) to ignore
{hide_filename} (boolean) if true, hides the name of the file
in the current picker (default is
false)
{symbols} (string|table) filter results by symbol kind(s) {symbols} (string|table) filter results by symbol kind(s)
@@ -1154,10 +1150,6 @@ builtin.lsp_dynamic_workspace_symbols({opts})*builtin.lsp_dynamic_workspace_symb
Parameters: ~ Parameters: ~
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Fields: ~
{hide_filename} (boolean) if true, hides the name of the file in the
current picker (default is false)
builtin.lsp_document_diagnostics({opts}) *builtin.lsp_document_diagnostics()* builtin.lsp_document_diagnostics({opts}) *builtin.lsp_document_diagnostics()*
Lists LSP diagnostics for the current buffer Lists LSP diagnostics for the current buffer
@@ -1173,9 +1165,6 @@ builtin.lsp_document_diagnostics({opts}) *builtin.lsp_document_diagnostics()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Fields: ~ Fields: ~
{hide_filename} (boolean) if true, hides the name of the file
in the current picker (default is
false)
{severity} (string|number) filter diagnostics by severity name {severity} (string|number) filter diagnostics by severity name
(string) or id (number) (string) or id (number)
{severity_limit} (string|number) keep diagnostics equal or more severe {severity_limit} (string|number) keep diagnostics equal or more severe
@@ -1205,9 +1194,6 @@ builtin.lsp_workspace_diagnostics({opts})*builtin.lsp_workspace_diagnostics()*
{opts} (table) options to pass to the picker {opts} (table) options to pass to the picker
Fields: ~ Fields: ~
{hide_filename} (boolean) if true, hides the name of the file
in the current picker (default is
false)
{severity} (string|number) filter diagnostics by severity name {severity} (string|number) filter diagnostics by severity name
(string) or id (number) (string) or id (number)
{severity_limit} (string|number) keep diagnostics equal or more severe {severity_limit} (string|number) keep diagnostics equal or more severe

View File

@@ -47,5 +47,43 @@ better.
You should get error messages when you try and use any of the above keys now. You should get error messages when you try and use any of the above keys now.
*telescope.changelog-839*
Date: July 7, 2021
PR: https://github.com/nvim-telescope/telescope.nvim/pull/839
Small breaking change regarding `shorten_path` and `hide_filename`.
This allows to configure path displays on a global level and offers a way for
extension developers to make use of the same configuration, offering a better
overall experience.
The new way to configure to configure path displays is with:
`path_display`: It is a table and accepts multiple values:
- "hidden" hide file names
- "tail" only display the file name, and not the path
- "absolute" display absolute paths
- "shorten" only display the first character of each directory in
the path
see |telescope.defaults.path_display|
Example would be for a global configuration:
require("telescope").setup{
defaults = {
path_display = {
"shorten_path",
"absolute",
},
}
}
You can also still pass this to a single builtin call:
require("telescope.builtin").find_files {
path_display = { "shorten_path" }
}
For extension developers there is a new util function that can be used to
display a path:
local filename = utils.transform_path(opts, entry.filename)
vim:tw=78:ts=8:ft=help:norl: vim:tw=78:ts=8:ft=help:norl:

View File

@@ -492,7 +492,7 @@ files.current_buffer_tags = function(opts)
return files.tags(vim.tbl_extend("force", { return files.tags(vim.tbl_extend("force", {
prompt_title = 'Current Buffer Tags', prompt_title = 'Current Buffer Tags',
only_current_file = true, only_current_file = true,
hide_filename = true, path_display = 'hidden',
}, opts)) }, opts))
end end

View File

@@ -118,8 +118,6 @@ builtin.current_buffer_fuzzy_find = require('telescope.builtin.files').current_b
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field ctags_file string: specify a particular ctags file to use ---@field ctags_file string: specify a particular ctags file to use
---@field show_line boolean: if true, shows the content of the line the tag is found on in the picker (default is true) ---@field show_line boolean: if true, shows the content of the line the tag is found on in the picker (default is true)
---@field shorten_path boolean: if true, makes file paths shown in picker use one letter for folders (default is true)
---@field hide_filename boolean: if true, hides the name of the file in the current picker (default is false)
builtin.tags = require('telescope.builtin.files').tags builtin.tags = require('telescope.builtin.files').tags
--- Lists all of the tags for the currently open buffer, with a preview --- Lists all of the tags for the currently open buffer, with a preview
@@ -289,8 +287,6 @@ builtin.spell_suggest = require('telescope.builtin.internal').spell_suggest
--- Lists the tag stack for the current window, jumps to tag on `<cr>` --- Lists the tag stack for the current window, jumps to tag on `<cr>`
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field shorten_path boolean: if true, makes file paths shown in picker use one letter for folders (default is true)
---@field hide_filename boolean: if true, hides the name of the file in the current picker (default is true)
builtin.tagstack = require('telescope.builtin.internal').tagstack builtin.tagstack = require('telescope.builtin.internal').tagstack
--- Lists items from Vim's jumplist, jumps to location on `<cr>` --- Lists items from Vim's jumplist, jumps to location on `<cr>`
@@ -305,7 +301,6 @@ builtin.jumplist = require('telescope.builtin.internal').jumplist
--- Lists LSP references for word under the cursor, jumps to reference on `<cr>` --- Lists LSP references for word under the cursor, jumps to reference on `<cr>`
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field shorten_path boolean: if true, makes file paths shown in picker use one letter for folders (default is false)
builtin.lsp_references = require('telescope.builtin.lsp').references builtin.lsp_references = require('telescope.builtin.lsp').references
--- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope --- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope
@@ -336,9 +331,7 @@ builtin.lsp_document_symbols = require('telescope.builtin.lsp').document_symbols
--- - Default keymaps: --- - Default keymaps:
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`) --- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field shorten_path boolean: if true, makes file paths shown in picker use one letter for folders (default is false)
---@field ignore_filename string: file(s) to ignore ---@field ignore_filename string: file(s) to ignore
---@field hide_filename boolean: if true, hides the name of the file in the current picker (default is false)
---@field symbols string|table: filter results by symbol kind(s) ---@field symbols string|table: filter results by symbol kind(s)
builtin.lsp_workspace_symbols = require('telescope.builtin.lsp').workspace_symbols builtin.lsp_workspace_symbols = require('telescope.builtin.lsp').workspace_symbols
@@ -346,7 +339,6 @@ builtin.lsp_workspace_symbols = require('telescope.builtin.lsp').workspace_symbo
--- - Default keymaps: --- - Default keymaps:
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`) --- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field hide_filename boolean: if true, hides the name of the file in the current picker (default is false)
builtin.lsp_dynamic_workspace_symbols = require('telescope.builtin.lsp').dynamic_workspace_symbols builtin.lsp_dynamic_workspace_symbols = require('telescope.builtin.lsp').dynamic_workspace_symbols
--- Lists LSP diagnostics for the current buffer --- Lists LSP diagnostics for the current buffer
@@ -355,7 +347,6 @@ builtin.lsp_dynamic_workspace_symbols = require('telescope.builtin.lsp').dynamic
--- - Default keymaps: --- - Default keymaps:
--- - `<C-l>`: show autocompletion menu to prefilter your query with the diagnostic you want to see (i.e. `:warning:`) --- - `<C-l>`: show autocompletion menu to prefilter your query with the diagnostic you want to see (i.e. `:warning:`)
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field hide_filename boolean: if true, hides the name of the file in the current picker (default is false)
---@field severity string|number: filter diagnostics by severity name (string) or id (number) ---@field severity string|number: filter diagnostics by severity name (string) or id (number)
---@field severity_limit string|number: keep diagnostics equal or more severe wrt severity name (string) or id (number) ---@field severity_limit string|number: keep diagnostics equal or more severe wrt severity name (string) or id (number)
---@field severity_bound string|number: keep diagnostics equal or less severe wrt severity name (string) or id (number) ---@field severity_bound string|number: keep diagnostics equal or less severe wrt severity name (string) or id (number)
@@ -369,7 +360,6 @@ builtin.lsp_document_diagnostics = require('telescope.builtin.lsp').diagnostics
--- - Default keymaps: --- - Default keymaps:
--- - `<C-l>`: show autocompletion menu to prefilter your query with the diagnostic you want to see (i.e. `:warning:`) --- - `<C-l>`: show autocompletion menu to prefilter your query with the diagnostic you want to see (i.e. `:warning:`)
---@param opts table: options to pass to the picker ---@param opts table: options to pass to the picker
---@field hide_filename boolean: if true, hides the name of the file in the current picker (default is false)
---@field severity string|number: filter diagnostics by severity name (string) or id (number) ---@field severity string|number: filter diagnostics by severity name (string) or id (number)
---@field severity_limit string|number: keep diagnostics equal or more severe wrt severity name (string) or id (number) ---@field severity_limit string|number: keep diagnostics equal or more severe wrt severity name (string) or id (number)
---@field severity_bound string|number: keep diagnostics equal or less severe wrt severity name (string) or id (number) ---@field severity_bound string|number: keep diagnostics equal or less severe wrt severity name (string) or id (number)

View File

@@ -19,7 +19,7 @@ local internal = {}
-- vim.fn.setreg("+", "nnoremap $TODO :lua require('telescope.builtin').<whatever>()<CR>") -- vim.fn.setreg("+", "nnoremap $TODO :lua require('telescope.builtin').<whatever>()<CR>")
-- TODO: Can we just do the names instead? -- TODO: Can we just do the names instead?
internal.builtin = function(opts) internal.builtin = function(opts)
opts.hide_filename = utils.get_default(opts.hide_filename, true) opts.path_display = utils.get_default(opts.path_display, "hidden")
opts.ignore_filename = utils.get_default(opts.ignore_filename, true) opts.ignore_filename = utils.get_default(opts.ignore_filename, true)
opts.include_extensions = utils.get_default(opts.include_extensions, false) opts.include_extensions = utils.get_default(opts.include_extensions, false)

View File

@@ -15,8 +15,6 @@ local conf = require('telescope.config').values
local lsp = {} local lsp = {}
lsp.references = function(opts) lsp.references = function(opts)
opts.shorten_path = utils.get_default(opts.shorten_path, true)
local params = vim.lsp.util.make_position_params() local params = vim.lsp.util.make_position_params()
params.context = { includeDeclaration = true } params.context = { includeDeclaration = true }
@@ -250,8 +248,6 @@ lsp.range_code_actions = function(opts)
end end
lsp.workspace_symbols = function(opts) lsp.workspace_symbols = function(opts)
opts.shorten_path = utils.get_default(opts.shorten_path, true)
local params = {query = opts.query or ''} local params = {query = opts.query or ''}
local results_lsp, err = vim.lsp.buf_request_sync(0, "workspace/symbol", params, opts.timeout or 10000) local results_lsp, err = vim.lsp.buf_request_sync(0, "workspace/symbol", params, opts.timeout or 10000)
if err then if err then
@@ -283,7 +279,6 @@ lsp.workspace_symbols = function(opts)
end end
opts.ignore_filename = utils.get_default(opts.ignore_filename, false) opts.ignore_filename = utils.get_default(opts.ignore_filename, false)
opts.hide_filename = utils.get_default(opts.hide_filename, false)
pickers.new(opts, { pickers.new(opts, {
prompt_title = 'LSP Workspace Symbols', prompt_title = 'LSP Workspace Symbols',
@@ -337,7 +332,7 @@ lsp.diagnostics = function(opts)
return return
end end
opts.hide_filename = utils.get_default(opts.hide_filename, true) opts.path_display = utils.get_default(opts.path_display, 'hidden')
pickers.new(opts, { pickers.new(opts, {
prompt_title = 'LSP Document Diagnostics', prompt_title = 'LSP Document Diagnostics',
finder = finders.new_table { finder = finders.new_table {
@@ -354,7 +349,7 @@ end
lsp.workspace_diagnostics = function(opts) lsp.workspace_diagnostics = function(opts)
opts = utils.get_default(opts, {}) opts = utils.get_default(opts, {})
opts.hide_filename = utils.get_default(opts.hide_filename, false) opts.path_display = utils.get_default(opts.path_display, {})
opts.prompt_title = 'LSP Workspace Diagnostics' opts.prompt_title = 'LSP Workspace Diagnostics'
opts.get_all = true opts.get_all = true
lsp.diagnostics(opts) lsp.diagnostics(opts)

View File

@@ -177,6 +177,21 @@ local telescope_defaults = {
Default: true]] Default: true]]
}, },
path_display = { {}, [[
Determines how file paths are displayed
path_display can be set to an array with a combination of:
- "hidden" hide file names
- "tail" only display the file name, and not the path
- "absolute" display absolute paths
- "shorten" only display the first character of each directory in
the path
path_display can also be set to 'hidden' string to hide file names
Default: {}]]
},
borderchars = { { "", "", "", "", "", "", "", "" } }, borderchars = { { "", "", "", "", "", "", "", "" } },
get_status_text = { get_status_text = {
@@ -247,13 +262,15 @@ local telescope_defaults = {
Into your config. Into your config.
otherwise, just set the mapping to the function that you want it to be. otherwise, just set the mapping to the function that you want it to
be.
..., ...,
["<C-i>"] = require('telescope.actions').select_default, ["<C-i>"] = require('telescope.actions').select_default,
..., ...,
If the function you want is part of `telescope.actions`, then you can simply give a string. If the function you want is part of `telescope.actions`, then you can
simply give a string.
For example, the previous option is equivalent to: For example, the previous option is equivalent to:
..., ...,

View File

@@ -8,6 +8,20 @@ deprecated.picker_window_options = function(opts)
-- Deprecated: PR:922, 2021/06/25 -- Deprecated: PR:922, 2021/06/25
-- Can be removed in a few weeks. -- Can be removed in a few weeks.
if opts.shorten_path then
table.insert(messages,
"'opts.shorten_path' is no longer valid. Please use 'opts.path_display' instead. " ..
"Please See ':help telescope.changelog-839'"
)
end
if opts.hide_filename then
table.insert(messages,
"'opts.hide_filename' is no longer valid. Please use 'opts.path_display' instead. " ..
"Please See ':help telescope.changelog-839'"
)
end
if opts.width then if opts.width then
table.insert(messages, "'opts.width' is no longer valid. Please use 'layout_config.width' instead") table.insert(messages, "'opts.width' is no longer valid. Please use 'layout_config.width' instead")
end end

View File

@@ -5,8 +5,6 @@ local strings = require('plenary.strings')
local Path = require('plenary.path') local Path = require('plenary.path')
local get_default = utils.get_default
local treesitter_type_highlight = { local treesitter_type_highlight = {
["associated"] = "TSConstant", ["associated"] = "TSConstant",
["constant"] = "TSConstant", ["constant"] = "TSConstant",
@@ -68,17 +66,13 @@ do
local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd()) local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
local disable_devicons = opts.disable_devicons local disable_devicons = opts.disable_devicons
local shorten_path = opts.shorten_path
local mt_file_entry = {} local mt_file_entry = {}
mt_file_entry.cwd = cwd mt_file_entry.cwd = cwd
mt_file_entry.display = function(entry) mt_file_entry.display = function(entry)
local hl_group local hl_group
local display = path.make_relative(entry.value, cwd) local display = utils.transform_path(opts, entry.value)
if shorten_path then
display = utils.path_shorten(display)
end
display, hl_group = utils.transform_devicons(entry.value, display, disable_devicons) display, hl_group = utils.transform_devicons(entry.value, display, disable_devicons)
@@ -136,7 +130,6 @@ do
end end
--- Special options: --- Special options:
--- - shorten_path: make the path appear short
--- - disable_coordinates: Don't show the line & row numbers --- - disable_coordinates: Don't show the line & row numbers
--- - only_sort_text: Only sort via the text. Ignore filename and other items --- - only_sort_text: Only sort via the text. Ignore filename and other items
function make_entry.gen_from_vimgrep(opts) function make_entry.gen_from_vimgrep(opts)
@@ -145,7 +138,6 @@ do
opts = opts or {} opts = opts or {}
local disable_devicons = opts.disable_devicons local disable_devicons = opts.disable_devicons
local shorten_path = opts.shorten_path
local disable_coordinates = opts.disable_coordinates local disable_coordinates = opts.disable_coordinates
local only_sort_text = opts.only_sort_text local only_sort_text = opts.only_sort_text
@@ -188,12 +180,7 @@ do
cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd()), cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd()),
display = function(entry) display = function(entry)
local display_filename local display_filename = utils.transform_path(opts, entry.filename)
if shorten_path then
display_filename = utils.path_shorten(entry.filename)
else
display_filename = entry.filename
end
local coordinates = "" local coordinates = ""
if not disable_coordinates then if not disable_coordinates then
@@ -290,7 +277,6 @@ end
function make_entry.gen_from_quickfix(opts) function make_entry.gen_from_quickfix(opts)
opts = opts or {} opts = opts or {}
opts.tail_path = get_default(opts.tail_path, true)
local displayer = entry_display.create { local displayer = entry_display.create {
separator = "", separator = "",
@@ -302,15 +288,7 @@ function make_entry.gen_from_quickfix(opts)
} }
local make_display = function(entry) local make_display = function(entry)
local filename local filename = utils.transform_path(opts, entry.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 line_info = {table.concat({entry.lnum, entry.col}, ":"), "TelescopeResultsLineNr"} local line_info = {table.concat({entry.lnum, entry.col}, ":"), "TelescopeResultsLineNr"}
@@ -379,17 +357,7 @@ function make_entry.gen_from_lsp_symbols(opts)
)[1] or '' )[1] or ''
msg = vim.trim(msg) msg = vim.trim(msg)
else else
local filename = "" local filename = utils.transform_path(opts, entry.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
if opts.show_line then -- show inline line info if opts.show_line then -- show inline line info
filename = filename .. " [" ..entry.lnum .. ":" .. entry.col .. "]" 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 cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
local make_display = function(entry) local make_display = function(entry)
local display_bufname local display_bufname = utils.transform_path(opts, entry.filename)
if opts.shorten_path then
display_bufname = path.shorten(entry.filename)
else
display_bufname = entry.filename
end
local icon, hl_group = utils.get_devicons(entry.filename, disable_devicons) 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 current_file = path.normalize(vim.fn.expand('%'), cwd)
local display_items = { local display_items = {
{ width = 30 },
{ remaining = true }, { 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 if opts.show_line then
table.insert(display_items, 2, { width = 30 }) table.insert(display_items, 1, { width = 30 })
end end
local displayer = entry_display.create { local displayer = entry_display.create {
@@ -869,25 +835,25 @@ function make_entry.gen_from_ctags(opts)
} }
local make_display = function(entry) local make_display = function(entry)
local filename local filename = utils.transform_path(opts, entry.filename)
if not opts.hide_filename then
if opts.shorten_path then
filename = path.shorten(entry.filename)
else
filename = entry.filename
end
end
local scode local scode
if opts.show_line then if opts.show_line then
scode = entry.scode scode = entry.scode
end end
return displayer { if hidden then
filename, return displayer {
entry.tag, entry.tag,
scode, scode,
} }
else
return displayer {
filename,
entry.tag,
scode,
}
end
end end
return function(line) return function(line)
@@ -932,7 +898,6 @@ end
function make_entry.gen_from_lsp_diagnostics(opts) function make_entry.gen_from_lsp_diagnostics(opts)
opts = opts or {} opts = opts or {}
opts.tail_path = utils.get_default(opts.tail_path, true)
local lsp_type_diagnostic = vim.lsp.protocol.DiagnosticSeverity local lsp_type_diagnostic = vim.lsp.protocol.DiagnosticSeverity
local signs local signs
@@ -956,22 +921,14 @@ function make_entry.gen_from_lsp_diagnostics(opts)
{ remaining = true } { remaining = true }
} }
local line_width = utils.get_default(opts.line_width, 45) 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 { local displayer = entry_display.create {
separator = "", separator = "",
items = layout items = layout
} }
local make_display = function(entry) local make_display = function(entry)
local filename local filename = utils.transform_path(opts, entry.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
-- 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)
@@ -1156,7 +1113,6 @@ end
function make_entry.gen_from_jumplist(opts) function make_entry.gen_from_jumplist(opts)
opts = opts or {} opts = opts or {}
opts.tail_path = get_default(opts.tail_path, true)
local displayer = entry_display.create { local displayer = entry_display.create {
separator = "", separator = "",
@@ -1167,15 +1123,7 @@ function make_entry.gen_from_jumplist(opts)
} }
local make_display = function(entry) local make_display = function(entry)
local filename local filename = utils.transform_path(opts, entry.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 line_info = {table.concat({entry.lnum, entry.col}, ":"), "TelescopeResultsLineNr"} local line_info = {table.concat({entry.lnum, entry.col}, ":"), "TelescopeResultsLineNr"}

View File

@@ -275,6 +275,46 @@ utils.path_tail = (function()
end end
end)() end)()
utils.is_path_hidden = function(opts, path_display)
path_display = path_display or utils.get_default(opts.path_display, require('telescope.config').values.path_display)
return path_display == nil or path_display == "hidden" or
type(path_display) ~= "table" or vim.tbl_contains(path_display, "hidden")
end
utils.transform_path = function(opts, path)
local path_display = utils.get_default(opts.path_display, require('telescope.config').values.path_display)
if utils.is_path_hidden(nil, path_display) then
return ''
end
local transformed_path = path
if vim.tbl_contains(path_display, "tail") then
transformed_path = utils.path_tail(transformed_path)
else
if not vim.tbl_contains(path_display, "absolute") then
local cwd
if opts.cwd then
cwd = opts.cwd
if not vim.in_fast_event() then
cwd = vim.fn.expand(opts.cwd)
end
else
cwd = vim.loop.cwd();
end
transformed_path = pathlib.make_relative(transformed_path, cwd)
end
if vim.tbl_contains(path_display, "shorten") then
transformed_path = pathlib.shorten(transformed_path)
end
end
return transformed_path
end
-- local x = utils.make_default_callable(function(opts) -- local x = utils.make_default_callable(function(opts)
-- return function() -- return function()
-- print(opts.example, opts.another) -- print(opts.example, opts.another)