Skip to content

Commit

Permalink
Clean up utils.transform_path and unused path options.
Browse files Browse the repository at this point in the history
  • Loading branch information
caojoshua committed Jun 1, 2021
1 parent 478a642 commit 87b9b27
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ require('telescope').setup{
layout_strategy = "horizontal",
layout_defaults = {},
file_ignore_patterns = {},
shorten_path = true,
winblend = 0,
width = 0.75,
preview_cutoff = 120,
Expand All @@ -118,6 +117,7 @@ require('telescope').setup{
borderchars = { '─', '│', '─', '│', '╭', '╮', '╯', '╰'},
color_devicons = true,
use_less = true,
path_display = {}
}
}
EOF
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ 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,
width = 0.75,
preview_cutoff = 120,
Expand All @@ -167,6 +166,7 @@ require('telescope').setup{
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 @@ -213,6 +213,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) |
| `scroll_strategy` | How to behave when the when there are no more item next/prev | cycle, nil |
| `file_previewer` | What telescope previewer to use for files. | [Previewers](#previewers) |
| `grep_previewer` | What telescope previewer to use for grep and similar | [Previewers](#previewers) |
Expand All @@ -233,7 +234,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 |
| `file_ignore_patterns` | Pattern to be ignored `{ "scratch/.*", "%.env" }` | dict |
| `shorten_path` | Whether to shorten paths or not. | boolean |

## Mappings

Expand Down
33 changes: 0 additions & 33 deletions doc/telescope.txt
Original file line number Diff line number Diff line change
Expand Up @@ -502,11 +502,6 @@ builtin.tags({opts}) *builtin.tags()*
{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
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()*
Lists all of the tags for the currently open buffer, with a preview
Expand Down Expand Up @@ -799,13 +794,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 @@ -822,10 +810,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 @@ -887,12 +871,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)


builtin.lsp_dynamic_workspace_symbols({opts})*builtin.lsp_dynamic_workspace_symbols()*
Expand All @@ -905,10 +884,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 @@ -920,10 +895,6 @@ builtin.lsp_document_diagnostics({opts}) *builtin.lsp_document_diagnostics()*
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_workspace_diagnostics({opts})*builtin.lsp_workspace_diagnostics()*
Lists LSP diagnostics for the current workspace if supported, otherwise
Expand All @@ -936,10 +907,6 @@ builtin.lsp_workspace_diagnostics({opts})*builtin.lsp_workspace_diagnostics()*
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)



================================================================================
Expand Down
1 change: 0 additions & 1 deletion lua/telescope/builtin/files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ 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,
}, opts))
end

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)

local objs = {}
Expand Down
5 changes: 2 additions & 3 deletions lua/telescope/builtin/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,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 @@ -320,7 +319,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 @@ -337,7 +336,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
4 changes: 1 addition & 3 deletions lua/telescope/make_entry.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ end

function make_entry.gen_from_quickfix(opts)
opts = opts or {}
opts.tail_path = get_default(opts.tail_path, true)

local displayer = entry_display.create {
separator = "",
Expand Down Expand Up @@ -894,7 +893,6 @@ end

function make_entry.gen_from_lsp_diagnostics(opts)
opts = opts or {}
opts.tail_path = get_default(opts.tail_path, true)

local signs
if not opts.no_sign then
Expand All @@ -915,7 +913,7 @@ function make_entry.gen_from_lsp_diagnostics(opts)
{ remaining = true }
}
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 {
separator = "",
items = layout
Expand Down
37 changes: 16 additions & 21 deletions lua/telescope/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ utils.reversed_ipairs = function(t)
return reversedipairsiter, t, #t + 1
end

utils.contains = function(t, val)
for _, tval in pairs(t) do
if tval == val then
return true
end
end
return false
end

utils.default_table_mt = {
__index = function(t, k)
local obj = {}
Expand Down Expand Up @@ -156,27 +147,31 @@ utils.path_tail = (function()
end
end)()

utils.transform_path = function(opts, path)
local config = require('telescope.config').values
local path_display = utils.get_default(opts.path_display, config.path_display)
utils.is_path_hidden = function(opts)
local path_display = utils.get_default(opts.path_display, require('telescope.config').values.path_display)

if path == nil or path_display == nil or type(path_display) ~= "table" or
utils.contains(path_display, "hidden") or path_display == "hidden" then
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)
if utils.is_path_hidden(opts) then
return ''
end

local path_display = utils.get_default(opts.path_display, require('telescope.config').values.path_display)
local transformed_path = path

if utils.contains(path_display, "tail") then
if vim.tbl_contains(path_display, "tail") then
transformed_path = utils.path_tail(transformed_path)
else
-- TODO: explicitly make paths absolute when the option is set
if not utils.contains(path_display, "absolute") then
local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
transformed_path = pathlib.make_relative(transformed_path, cwd)
end
-- TODO: absolute/relative paths. we can't call vimL functions in lua loop callback.
-- if not vim.tbl_contains(path_display, "absolute") then
-- local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
-- transformed_path = pathlib.make_relative(transformed_path, cwd)
-- end

if utils.contains(path_display, "shorten") then
if vim.tbl_contains(path_display, "shorten") then
transformed_path = pathlib.shorten(transformed_path)
end
end
Expand Down

0 comments on commit 87b9b27

Please sign in to comment.