Revert "expand paths more smartly (#2599)" (#2615)

This reverts commit f52ea4061d.
This commit is contained in:
James Trew
2023-07-21 21:50:44 -04:00
committed by GitHub
parent f52ea4061d
commit 7bb2fcecdc
8 changed files with 24 additions and 30 deletions

View File

@@ -5,7 +5,6 @@ local log = require "plenary.log"
local async = require "plenary.async" local async = require "plenary.async"
local channel = require("plenary.async").control.channel local channel = require("plenary.async").control.channel
local utils = require "telescope.utils"
local M = {} local M = {}
@@ -22,7 +21,7 @@ function AsyncJob.new(opts)
self.stderr = opts.stderr or M.NullPipe() self.stderr = opts.stderr or M.NullPipe()
if opts.cwd and opts.cwd ~= "" then if opts.cwd and opts.cwd ~= "" then
self.uv_opts.cwd = utils.smart_path_expand(opts.cwd) self.uv_opts.cwd = vim.fn.expand(vim.fn.escape(opts.cwd, "$"))
-- this is a "illegal" hack for windows. E.g. If the git command returns `/` rather than `\` as delimiter, -- this is a "illegal" hack for windows. E.g. If the git command returns `/` rather than `\` as delimiter,
-- vim.fn.expand might just end up returning an empty string. Weird -- vim.fn.expand might just end up returning an empty string. Weird
-- Because empty string is not allowed in libuv the job will not spawn. Solution is we just set it to opts.cwd -- Because empty string is not allowed in libuv the job will not spawn. Solution is we just set it to opts.cwd

View File

@@ -73,7 +73,7 @@ function histories.History:new(opts)
if conf.history.limit then if conf.history.limit then
obj.limit = conf.history.limit obj.limit = conf.history.limit
end end
obj.path = utils.smart_path_expand(conf.history.path) obj.path = vim.fn.expand(conf.history.path)
obj.content = {} obj.content = {}
obj.index = 1 obj.index = 1
obj.cycle_wrap = conf.history.cycle_wrap obj.cycle_wrap = conf.history.cycle_wrap

View File

@@ -96,12 +96,12 @@ files.live_grep = function(opts)
local vimgrep_arguments = opts.vimgrep_arguments or conf.vimgrep_arguments local vimgrep_arguments = opts.vimgrep_arguments or conf.vimgrep_arguments
local search_dirs = opts.search_dirs local search_dirs = opts.search_dirs
local grep_open_files = opts.grep_open_files local grep_open_files = opts.grep_open_files
opts.cwd = utils.smart_path_expand(opts.cwd or vim.loop.cwd()) opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd()
local filelist = get_open_filelist(grep_open_files, opts.cwd) local filelist = get_open_filelist(grep_open_files, opts.cwd)
if search_dirs then if search_dirs then
for i, path in ipairs(search_dirs) do for i, path in ipairs(search_dirs) do
search_dirs[i] = utils.smart_path_expand(path) search_dirs[i] = vim.fn.expand(path)
end end
end end
@@ -166,7 +166,7 @@ files.live_grep = function(opts)
end end
files.grep_string = function(opts) files.grep_string = function(opts)
opts.cwd = utils.smart_path_expand(opts.cwd or vim.loop.cwd()) opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd()
local vimgrep_arguments = vim.F.if_nil(opts.vimgrep_arguments, conf.vimgrep_arguments) local vimgrep_arguments = vim.F.if_nil(opts.vimgrep_arguments, conf.vimgrep_arguments)
local word local word
local visual = vim.fn.mode() == "v" local visual = vim.fn.mode() == "v"
@@ -225,7 +225,7 @@ files.grep_string = function(opts)
end end
elseif opts.search_dirs then elseif opts.search_dirs then
for _, path in ipairs(opts.search_dirs) do for _, path in ipairs(opts.search_dirs) do
table.insert(args, utils.smart_path_expand(path)) table.insert(args, vim.fn.expand(path))
end end
end end
@@ -278,7 +278,7 @@ files.find_files = function(opts)
if search_dirs then if search_dirs then
for k, v in pairs(search_dirs) do for k, v in pairs(search_dirs) do
search_dirs[k] = utils.smart_path_expand(v) search_dirs[k] = vim.fn.expand(v)
end end
end end
@@ -355,7 +355,7 @@ files.find_files = function(opts)
end end
if opts.cwd then if opts.cwd then
opts.cwd = utils.smart_path_expand(opts.cwd) opts.cwd = vim.fn.expand(opts.cwd)
end end
opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts) opts.entry_maker = opts.entry_maker or make_entry.gen_from_file(opts)
@@ -444,7 +444,7 @@ end
files.current_buffer_fuzzy_find = function(opts) files.current_buffer_fuzzy_find = function(opts)
-- All actions are on the current buffer -- All actions are on the current buffer
local filename = utils.smart_path_expand(vim.api.nvim_buf_get_name(opts.bufnr)) local filename = vim.fn.expand(vim.api.nvim_buf_get_name(opts.bufnr))
local filetype = vim.api.nvim_buf_get_option(opts.bufnr, "filetype") local filetype = vim.api.nvim_buf_get_option(opts.bufnr, "filetype")
local lines = vim.api.nvim_buf_get_lines(opts.bufnr, 0, -1, false) local lines = vim.api.nvim_buf_get_lines(opts.bufnr, 0, -1, false)
@@ -548,7 +548,7 @@ files.tags = function(opts)
local tagfiles = opts.ctags_file and { opts.ctags_file } or vim.fn.tagfiles() local tagfiles = opts.ctags_file and { opts.ctags_file } or vim.fn.tagfiles()
for i, ctags_file in ipairs(tagfiles) do for i, ctags_file in ipairs(tagfiles) do
tagfiles[i] = utils.smart_path_expand(ctags_file, true) tagfiles[i] = vim.fn.expand(ctags_file, true)
end end
if vim.tbl_isempty(tagfiles) then if vim.tbl_isempty(tagfiles) then
utils.notify("builtin.tags", { utils.notify("builtin.tags", {

View File

@@ -7,7 +7,6 @@ This file is still WIP, so expect some changes if you're trying to consume these
This will provide standard mechanism for accessing information from an entry. This will provide standard mechanism for accessing information from an entry.
--============================================================================= ]] --============================================================================= ]]
local utils = require "telescope.utils"
local from_entry = {} local from_entry = {}
@@ -31,7 +30,7 @@ function from_entry.path(entry, validate, escape)
-- TODO(conni2461): we are not going to return the expanded path because -- TODO(conni2461): we are not going to return the expanded path because
-- this would lead to cache misses in the perviewer. -- this would lead to cache misses in the perviewer.
-- Requires overall refactoring in previewer interface -- Requires overall refactoring in previewer interface
local expanded = utils.smart_path_expand(path) local expanded = vim.fn.expand(vim.fn.escape(path, "$?*[]"))
if (vim.fn.filereadable(expanded) + vim.fn.isdirectory(expanded)) == 0 then if (vim.fn.filereadable(expanded) + vim.fn.isdirectory(expanded)) == 0 then
return return
end end

View File

@@ -149,7 +149,7 @@ do
function make_entry.gen_from_file(opts) function make_entry.gen_from_file(opts)
opts = opts or {} opts = opts or {}
local cwd = utils.smart_path_expand(opts.cwd or vim.loop.cwd()) local cwd = vim.fn.expand(opts.cwd or vim.loop.cwd())
local disable_devicons = opts.disable_devicons local disable_devicons = opts.disable_devicons
@@ -310,7 +310,7 @@ do
local display_string = "%s%s%s" local display_string = "%s%s%s"
mt_vimgrep_entry = { mt_vimgrep_entry = {
cwd = utils.smart_path_expand(opts.cwd or vim.loop.cwd()), cwd = vim.fn.expand(opts.cwd or vim.loop.cwd()),
display = function(entry) display = function(entry)
local display_filename = utils.transform_path(opts, entry.filename) local display_filename = utils.transform_path(opts, entry.filename)
@@ -605,7 +605,7 @@ function make_entry.gen_from_buffer(opts)
}, },
} }
local cwd = utils.smart_path_expand(opts.cwd or vim.loop.cwd()) local cwd = vim.fn.expand(opts.cwd or vim.loop.cwd())
local make_display = function(entry) local make_display = function(entry)
-- bufnr_width + modes + icon + 3 spaces + : + lnum -- bufnr_width + modes + icon + 3 spaces + : + lnum
@@ -1023,7 +1023,7 @@ end
function make_entry.gen_from_ctags(opts) function make_entry.gen_from_ctags(opts)
opts = opts or {} opts = opts or {}
local cwd = utils.smart_path_expand(opts.cwd or vim.loop.cwd()) local cwd = vim.fn.expand(opts.cwd or vim.loop.cwd())
local current_file = Path:new(vim.api.nvim_buf_get_name(opts.bufnr)):normalize(cwd) local current_file = Path:new(vim.api.nvim_buf_get_name(opts.bufnr)):normalize(cwd)
local display_items = { local display_items = {

View File

@@ -256,7 +256,7 @@ previewers.file_maker = function(filepath, bufnr, opts)
end end
if opts.bufname ~= filepath then if opts.bufname ~= filepath then
if not vim.in_fast_event() then if not vim.in_fast_event() then
filepath = utils.smart_path_expand(filepath) filepath = vim.fn.expand(filepath)
end end
vim.loop.fs_stat(filepath, function(_, stat) vim.loop.fs_stat(filepath, function(_, stat)
if not stat then if not stat then

View File

@@ -13,17 +13,17 @@ local bat_options = { "--style=plain", "--color=always", "--paging=always" }
local has_less = (vim.fn.executable "less" == 1) and conf.use_less local has_less = (vim.fn.executable "less" == 1) and conf.use_less
local get_file_stat = function(filename) local get_file_stat = function(filename)
return vim.loop.fs_stat(utils.smart_path_expand(filename)) or {} return vim.loop.fs_stat(vim.fn.expand(filename)) or {}
end end
local list_dir = (function() local list_dir = (function()
if vim.fn.has "win32" == 1 then if vim.fn.has "win32" == 1 then
return function(dirname) return function(dirname)
return { "cmd.exe", "/c", "dir", utils.smart_path_expand(dirname) } return { "cmd.exe", "/c", "dir", vim.fn.expand(dirname) }
end end
else else
return function(dirname) return function(dirname)
return { "ls", "-la", utils.smart_path_expand(dirname) } return { "ls", "-la", vim.fn.expand(dirname) }
end end
end end
end)() end)()
@@ -55,7 +55,7 @@ local bat_maker = function(filename, lnum, start, finish)
command, command,
bat_options, bat_options,
"--", "--",
utils.smart_path_expand(filename), vim.fn.expand(filename),
} }
end end
@@ -74,15 +74,15 @@ local cat_maker = function(filename, _, start, _)
if has_less then if has_less then
if start then if start then
return { "less", "-RS", string.format("+%s", start), utils.smart_path_expand(filename) } return { "less", "-RS", string.format("+%s", start), vim.fn.expand(filename) }
else else
return { "less", "-RS", utils.smart_path_expand(filename) } return { "less", "-RS", vim.fn.expand(filename) }
end end
else else
return { return {
"cat", "cat",
"--", "--",
utils.smart_path_expand(filename), vim.fn.expand(filename),
} }
end end
end end

View File

@@ -15,10 +15,6 @@ local get_status = require("telescope.state").get_status
local utils = {} local utils = {}
utils.smart_path_expand = function(path)
return path:match "^[%#<]" and vim.fn.expand(path) or vim.fn.fnameescape(path)
end
utils.get_separator = function() utils.get_separator = function()
return Path.path.sep return Path.path.sep
end end
@@ -225,7 +221,7 @@ utils.transform_path = function(opts, path)
if opts.cwd then if opts.cwd then
cwd = opts.cwd cwd = opts.cwd
if not vim.in_fast_event() then if not vim.in_fast_event() then
cwd = utils.smart_path_expand(opts.cwd) cwd = vim.fn.expand(opts.cwd)
end end
else else
cwd = vim.loop.cwd() cwd = vim.loop.cwd()