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

Consistent filepath display and code cleanup. #839

Merged
merged 2 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ require('telescope').setup{
file_sorter = require'telescope.sorters'.get_fuzzy_file,
file_ignore_patterns = {},
generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter,
shorten_path = true,
winblend = 0,
border = {},
borderchars = { '─', '│', '─', '│', '╭', '╮', '╯', '╰' },
color_devicons = true,
use_less = true,
path_display = {},
set_env = { ['COLORTERM'] = 'truecolor' }, -- default = nil,
file_previewer = require'telescope.previewers'.vim_buffer_cat.new,
grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new,
Expand Down Expand Up @@ -204,6 +204,7 @@ EOF
| `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 |
| `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) |
| `grep_previewer` | What telescope previewer to use for grep and similar | [Previewers](#previewers) |
| `qflist_previewer` | What telescope previewer to use for qflist | [Previewers](#previewers) |
Expand All @@ -223,7 +224,6 @@ EOF
| `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 |
| `file_ignore_patterns` | Pattern to be ignored `{ "scratch/.*", "%.env" }` | dict |
| `shorten_path` | Whether to shorten paths or not. | boolean |

### Customize Default Builtin behavior

Expand Down
58 changes: 22 additions & 36 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ telescope.setup({opts}) *telescope.setup()*
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,
...,

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:

...,
Expand All @@ -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*
prompt_prefix: ~
Will be shown in front of the prompt.
Expand Down Expand Up @@ -728,14 +745,9 @@ builtin.tags({opts}) *builtin.tags()*
{opts} (table) options to pass to the picker

Fields: ~
{ctags_file} (string) specify a particular ctags file to use
{show_line} (boolean) if true, shows the content of the line the
tag is found on in the picker (default is
true)
{shorten_path} (boolean) if true, makes file paths shown in picker
Conni2461 marked this conversation as resolved.
Show resolved Hide resolved
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)
{ctags_file} (string) specify a particular ctags file to use
{show_line} (boolean) if true, shows the content of the line the tag
is found on in the picker (default is true)


builtin.current_buffer_tags({opts}) *builtin.current_buffer_tags()*
Expand Down Expand Up @@ -1045,12 +1057,6 @@ builtin.tagstack({opts}) *builtin.tagstack()*
Parameters: ~
{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()*
Lists items from Vim's jumplist, jumps to location on `<cr>`
Expand All @@ -1068,10 +1074,6 @@ builtin.lsp_references({opts}) *builtin.lsp_references()*
Parameters: ~
{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()*
Goto the definition of the word under the cursor, if there's only one,
Expand Down Expand Up @@ -1134,13 +1136,7 @@ builtin.lsp_workspace_symbols({opts}) *builtin.lsp_workspace_symbols()*
{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)
{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)


Expand All @@ -1154,10 +1150,6 @@ builtin.lsp_dynamic_workspace_symbols({opts})*builtin.lsp_dynamic_workspace_symb
Parameters: ~
{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()*
Lists LSP diagnostics for the current buffer
Expand All @@ -1173,9 +1165,6 @@ builtin.lsp_document_diagnostics({opts}) *builtin.lsp_document_diagnostics()*
{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)
{severity} (string|number) filter diagnostics by severity name
(string) or id (number)
{severity_limit} (string|number) keep diagnostics equal or more severe
Expand Down Expand Up @@ -1205,9 +1194,6 @@ builtin.lsp_workspace_diagnostics({opts})*builtin.lsp_workspace_diagnostics()*
{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)
{severity} (string|number) filter diagnostics by severity name
(string) or id (number)
{severity_limit} (string|number) keep diagnostics equal or more severe
Expand Down
38 changes: 38 additions & 0 deletions doc/telescope_changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,43 @@ better.

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:
2 changes: 1 addition & 1 deletion lua/telescope/builtin/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ files.current_buffer_tags = function(opts)
return files.tags(vim.tbl_extend("force", {
prompt_title = 'Current Buffer Tags',
only_current_file = true,
hide_filename = true,
Conni2461 marked this conversation as resolved.
Show resolved Hide resolved
path_display = 'hidden',
}, opts))
end

Expand Down
10 changes: 0 additions & 10 deletions lua/telescope/builtin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ builtin.current_buffer_fuzzy_find = require('telescope.builtin.files').current_b
---@param opts table: options to pass to the picker
---@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 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

--- Lists all of the tags for the currently open buffer, with a preview
Expand Down Expand Up @@ -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>`
---@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

--- Lists items from Vim's jumplist, jumps to location on `<cr>`
Expand All @@ -305,7 +301,6 @@ builtin.jumplist = require('telescope.builtin.internal').jumplist

--- Lists LSP references for word under the cursor, jumps to reference on `<cr>`
---@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

--- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope
Expand Down Expand Up @@ -336,17 +331,14 @@ builtin.lsp_document_symbols = require('telescope.builtin.lsp').document_symbols
--- - Default keymaps:
--- - `<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
---@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 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)
builtin.lsp_workspace_symbols = require('telescope.builtin.lsp').workspace_symbols

--- Dynamically lists LSP for all workspace symbols
--- - Default keymaps:
--- - `<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
---@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

--- Lists LSP diagnostics for the current buffer
Expand All @@ -355,7 +347,6 @@ builtin.lsp_dynamic_workspace_symbols = require('telescope.builtin.lsp').dynamic
--- - Default keymaps:
--- - `<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
---@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_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)
Expand All @@ -369,7 +360,6 @@ builtin.lsp_document_diagnostics = require('telescope.builtin.lsp').diagnostics
--- - Default keymaps:
--- - `<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
---@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_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)
Expand Down
2 changes: 1 addition & 1 deletion lua/telescope/builtin/internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ local internal = {}
-- vim.fn.setreg("+", "nnoremap $TODO :lua require('telescope.builtin').<whatever>()<CR>")
-- TODO: Can we just do the names instead?
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.include_extensions = utils.get_default(opts.include_extensions, false)

Expand Down
9 changes: 2 additions & 7 deletions lua/telescope/builtin/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ local conf = require('telescope.config').values
local lsp = {}

lsp.references = function(opts)
opts.shorten_path = utils.get_default(opts.shorten_path, true)

local params = vim.lsp.util.make_position_params()
params.context = { includeDeclaration = true }

Expand Down Expand Up @@ -250,8 +248,6 @@ lsp.range_code_actions = function(opts)
end

lsp.workspace_symbols = function(opts)
opts.shorten_path = utils.get_default(opts.shorten_path, true)

local params = {query = opts.query or ''}
local results_lsp, err = vim.lsp.buf_request_sync(0, "workspace/symbol", params, opts.timeout or 10000)
if err then
Expand Down Expand Up @@ -283,7 +279,6 @@ lsp.workspace_symbols = function(opts)
end

opts.ignore_filename = utils.get_default(opts.ignore_filename, false)
opts.hide_filename = utils.get_default(opts.hide_filename, false)

pickers.new(opts, {
prompt_title = 'LSP Workspace Symbols',
Expand Down Expand Up @@ -337,7 +332,7 @@ lsp.diagnostics = function(opts)
return
end

opts.hide_filename = utils.get_default(opts.hide_filename, true)
opts.path_display = utils.get_default(opts.path_display, 'hidden')
pickers.new(opts, {
prompt_title = 'LSP Document Diagnostics',
finder = finders.new_table {
Expand All @@ -354,7 +349,7 @@ end

lsp.workspace_diagnostics = function(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.get_all = true
lsp.diagnostics(opts)
Expand Down
21 changes: 19 additions & 2 deletions lua/telescope/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,21 @@ local telescope_defaults = {
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 = { { "─", "│", "─", "│", "╭", "╮", "╯", "╰" } },

get_status_text = {
Expand Down Expand Up @@ -247,13 +262,15 @@ local telescope_defaults = {
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,
...,

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:

...,
Expand Down
14 changes: 14 additions & 0 deletions lua/telescope/deprecated.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ deprecated.picker_window_options = function(opts)
-- Deprecated: PR:922, 2021/06/25
-- 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
table.insert(messages, "'opts.width' is no longer valid. Please use 'layout_config.width' instead")
end
Expand Down
Loading