refactor: move from telescope.path to plenary.path (#473)
This will deprecate telescope.path, we will remove it soon. Please move over to plenary.path Co-authored-by: Simon Hauser <Simon-Hauser@outlook.de>
This commit is contained in:
@@ -47,10 +47,9 @@ files.live_grep = function(opts)
|
||||
end, vim.api.nvim_list_bufs())
|
||||
if not next(bufnrs) then return end
|
||||
|
||||
local tele_path = require'telescope.path'
|
||||
for _, bufnr in ipairs(bufnrs) do
|
||||
local file = vim.api.nvim_buf_get_name(bufnr)
|
||||
table.insert(filelist, tele_path.make_relative(file, opts.cwd))
|
||||
table.insert(filelist, Path:new(file):make_relative(opts.cwd))
|
||||
end
|
||||
elseif search_dirs then
|
||||
for i, path in ipairs(search_dirs) do
|
||||
@@ -242,6 +241,10 @@ end
|
||||
files.file_browser = function(opts)
|
||||
opts = opts or {}
|
||||
|
||||
local is_dir = function(value)
|
||||
return value:sub(-1, -1) == os_sep
|
||||
end
|
||||
|
||||
opts.depth = opts.depth or 1
|
||||
opts.cwd = opts.cwd and vim.fn.expand(opts.cwd) or vim.loop.cwd()
|
||||
opts.new_finder = opts.new_finder or function(path)
|
||||
@@ -258,18 +261,53 @@ files.file_browser = function(opts)
|
||||
})
|
||||
table.insert(data, 1, '..' .. os_sep)
|
||||
|
||||
return finders.new_table {
|
||||
results = data,
|
||||
entry_maker = (function()
|
||||
local tele_path = require'telescope.path'
|
||||
local gen = make_entry.gen_from_file(opts)
|
||||
return function(entry)
|
||||
local tmp = gen(entry)
|
||||
tmp.ordinal = tele_path.make_relative(entry, opts.cwd)
|
||||
return tmp
|
||||
local maker = function()
|
||||
local mt = {}
|
||||
mt.cwd = opts.cwd
|
||||
mt.display = function(entry)
|
||||
local hl_group
|
||||
local display = utils.transform_path(opts, entry.value)
|
||||
if is_dir(entry.value) then
|
||||
display = display .. os_sep
|
||||
if not opts.disable_devicons then
|
||||
display = (opts.dir_icon or "") .. " " .. display
|
||||
hl_group = "Default"
|
||||
end
|
||||
else
|
||||
display, hl_group = utils.transform_devicons(entry.value, display, opts.disable_devicons)
|
||||
end
|
||||
end)()
|
||||
}
|
||||
|
||||
if hl_group then
|
||||
return display, { { {1, 3}, hl_group } }
|
||||
else
|
||||
return display
|
||||
end
|
||||
end
|
||||
|
||||
mt.__index = function(t, k)
|
||||
local raw = rawget(mt, k)
|
||||
if raw then return raw end
|
||||
|
||||
if k == "path" then
|
||||
local retpath = Path:new({t.cwd, t.value}):absolute()
|
||||
if not vim.loop.fs_access(retpath, "R", nil) then
|
||||
retpath = t.value
|
||||
end
|
||||
if is_dir(t.value) then retpath = retpath .. os_sep end
|
||||
return retpath
|
||||
end
|
||||
|
||||
return rawget(t, rawget({ value = 1 }, k))
|
||||
end
|
||||
|
||||
return function(line)
|
||||
local tbl = {line}
|
||||
tbl.ordinal = Path:new(line):make_relative(opts.cwd)
|
||||
return setmetatable(tbl, mt)
|
||||
end
|
||||
end
|
||||
|
||||
return finders.new_table { results = data, entry_maker = maker() }
|
||||
end
|
||||
|
||||
pickers.new(opts, {
|
||||
@@ -279,7 +317,7 @@ files.file_browser = function(opts)
|
||||
sorter = conf.file_sorter(opts),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
action_set.select:replace_if(function()
|
||||
return action_state.get_selected_entry().path:sub(-1) == os_sep
|
||||
return is_dir(action_state.get_selected_entry().path)
|
||||
end, function()
|
||||
local new_cwd = vim.fn.expand(action_state.get_selected_entry().path:sub(1, -2))
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
@@ -299,7 +337,7 @@ files.file_browser = function(opts)
|
||||
end
|
||||
|
||||
local fpath = current_picker.cwd .. os_sep .. file
|
||||
if string.sub(fpath, -1) ~= os_sep then
|
||||
if not is_dir(fpath) then
|
||||
actions.close(prompt_bufnr)
|
||||
Path:new(fpath):touch({ parents = true })
|
||||
vim.cmd(string.format(':e %s', fpath))
|
||||
|
||||
@@ -101,6 +101,7 @@ builtin.fd = builtin.find_files
|
||||
---@param opts table: options to pass to the picker
|
||||
---@field cwd string: directory path to browse (default is cwd)
|
||||
---@field depth number: file tree depth to display (default is 1)
|
||||
---@field dir_icon string: change the icon for a directory. default:
|
||||
builtin.file_browser = require('telescope.builtin.files').file_browser
|
||||
|
||||
--- Lists function names, variables, and other symbols from treesitter queries
|
||||
|
||||
@@ -3,7 +3,7 @@ local action_set = require('telescope.actions.set')
|
||||
local action_state = require('telescope.actions.state')
|
||||
local finders = require('telescope.finders')
|
||||
local make_entry = require('telescope.make_entry')
|
||||
local path = require('telescope.path')
|
||||
local Path = require('plenary.path')
|
||||
local pickers = require('telescope.pickers')
|
||||
local previewers = require('telescope.previewers')
|
||||
local sorters = require('telescope.sorters')
|
||||
@@ -135,7 +135,7 @@ internal.symbols = function(opts)
|
||||
|
||||
local results = {}
|
||||
for _, source in ipairs(sources) do
|
||||
local data = vim.fn.json_decode(path.read_file(source))
|
||||
local data = vim.fn.json_decode(Path:new(source):read())
|
||||
for _, entry in ipairs(data) do
|
||||
table.insert(results, entry)
|
||||
end
|
||||
@@ -346,8 +346,9 @@ end
|
||||
|
||||
internal.vim_options = function(opts)
|
||||
-- Load vim options.
|
||||
local vim_opts = loadfile(utils.data_directory() .. path.separator .. 'options' ..
|
||||
path.separator .. 'options.lua')().options
|
||||
local vim_opts = loadfile(
|
||||
Path:new({utils.data_directory(), 'options', 'options.lua'}):absolute()
|
||||
)().options
|
||||
|
||||
pickers.new(opts, {
|
||||
prompt = 'options',
|
||||
@@ -449,7 +450,7 @@ internal.help_tags = function(opts)
|
||||
local delimiter = string.char(9)
|
||||
for _, lang in ipairs(langs) do
|
||||
for _, file in ipairs(tag_files[lang] or {}) do
|
||||
local lines = vim.split(path.read_file(file), '\n', true)
|
||||
local lines = vim.split(Path:new(file):read(), '\n', true)
|
||||
for _, line in ipairs(lines) do
|
||||
-- TODO: also ignore tagComment starting with ';'
|
||||
if not line:match'^!_TAG_' then
|
||||
|
||||
Reference in New Issue
Block a user