Skip to content

Commit

Permalink
Revert "feat: fd file and folder finders (nvim-telescope#26)" (nvim-t…
Browse files Browse the repository at this point in the history
…elescope#33)

This reverts commit 9719822.
  • Loading branch information
fdschmidt93 committed Dec 21, 2021
1 parent 9719822 commit de3d791
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 124 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ use { "nvim-telescope/telescope-file-browser.nvim" }
Plug "nvim-telescope/telescope-file-browser.nvim"
```

### Optional Dependencies

`telescope-file-browser` optionally levers [fd](https://github.com/sharkdp/fd) if installed primarily for more async but also generally faster file and folder browsing, which is most noticeable in larger repositories.

# Setup and Configuration

You configure the `telescope-file-browser` like any other `telescope.nvim` picker. See `:h telescope-file-browser.picker` for the full set of options dedicated to the picker. In addition, you of course can map `theme` and `mappings` as you are accustomed to from `telescope.nvim`.
Expand Down
57 changes: 0 additions & 57 deletions doc/telescope-file-browser.txt
Original file line number Diff line number Diff line change
Expand Up @@ -245,60 +245,3 @@ fb_actions.select_all({prompt_bufnr}) *fb_actions.select_all()*



================================================================================
*telescope-file-browser.finders*

The file browser finders power the picker with both a file and folder browser.

fb_finders.browse_files({opts}) *fb_finders.browse_files()*
Returns a finder that is populated with files and folders in `path`. Notes:
- Uses `fd` if available for more async-ish browsing and speed-ups


Parameters: ~
{opts} (table) options to pass to the finder

Fields: ~
{path} (string) root dir to browse from
{depth} (number) file tree depth to display (default: 1)
{hidden} (boolean) determines whether to show hidden files or not
(default: false)


fb_finders.browse_folders({opts}) *fb_finders.browse_folders()*
Returns a finder that is populated with (sub-)folders of `cwd`. Notes:
- Uses `fd` if available for more async-ish browsing and speed-ups


Parameters: ~
{opts} (table) options to pass to the finder

Fields: ~
{cwd} (string) root dir to browse from
{depth} (number) file tree depth to display (default: 1)
{hidden} (boolean) determines whether to show hidden files or not
(default: false)


fb_finders.finder({opts}) *fb_finders.finder()*
Returns a finder that combines |fb_finders.browse_files| and
|fb_finders.browse_folders| into a unified finder.


Parameters: ~
{opts} (table) options to pass to the picker

Fields: ~
{path} (string) root dir to file_browse from (default:
vim.loop.cwd())
{cwd} (string) root dir (default: vim.loop.cwd())
{files} (boolean) start in file (true) or folder (false) browser
(default: true)
{depth} (number) file tree depth to display (default: 1)
{dir_icon} (string) change the icon for a directory. (default: )
{hidden} (boolean) determines whether to show hidden files or not
(default: false)



vim:tw=78:ts=8:ft=help:norl:
93 changes: 31 additions & 62 deletions lua/telescope/_extensions/file_browser/finders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

local fb_make_entry = require "telescope._extensions.file_browser.make_entry"

local async_oneshot_finder = require "telescope.finders.async_oneshot_finder"
local finders = require "telescope.finders"

local scan = require "plenary.scandir"
Expand All @@ -18,82 +17,52 @@ local os_sep = Path.path.sep
local fb_finders = {}

--- Returns a finder that is populated with files and folders in `path`.
--- Notes:
--- - Uses `fd` if available for more async-ish browsing and speed-ups
---@param opts table: options to pass to the finder
---@field path string: root dir to browse from
---@field depth number: file tree depth to display (default: 1)
---@field hidden boolean: determines whether to show hidden files or not (default: false)
fb_finders.browse_files = function(opts)
opts = opts or {}
-- TODO(fdschmidt93): better separation?
if vim.fn.executable "fd" == 1 then
local args = { "-a" }
if opts.hidden then
table.insert(args, "-H")
end
if type(opts.depth) == "number" then
table.insert(args, "--maxdepth")
table.insert(args, opts.depth)
end
local entry_maker = opts.entry_maker { cwd = opts.path }
return async_oneshot_finder {
fn_command = function()
return { command = "fd", args = args }
end,
entry_maker = entry_maker,
results = { entry_maker(Path:new(opts.path):parent():absolute()) },
cwd = opts.path,
}
else
local data = scan.scan_dir(opts.path, {
add_dirs = opts.add_dirs,
depth = opts.depth,
hidden = opts.hidden,
})
if opts.path ~= os_sep then
table.insert(data, 1, Path:new(opts.path):parent():absolute())
end
-- returns copy with properly set cwd for entry maker
return finders.new_table { results = data, entry_maker = opts.entry_maker { cwd = opts.path } }
local data = scan.scan_dir(opts.path, {
add_dirs = opts.add_dirs,
depth = opts.depth,
hidden = opts.hidden,
respect_gitignore = opts.respect_gitignore,
})
if opts.path ~= os_sep then
table.insert(data, 1, Path:new(opts.path):parent():absolute())
end
-- returns copy with properly set cwd for entry maker
return finders.new_table { results = data, entry_maker = opts.entry_maker { cwd = opts.path } }
end

--- Returns a finder that is populated with (sub-)folders of `cwd`.
--- Notes:
--- - Uses `fd` if available for more async-ish browsing and speed-ups
---@param opts table: options to pass to the finder
---@field cwd string: root dir to browse from
---@field depth number: file tree depth to display (default: 1)
---@field hidden boolean: determines whether to show hidden files or not (default: false)
fb_finders.browse_folders = function(opts)
-- TODO(fdschmidt93): better separation?
if vim.fn.executable "fd" == 1 then
local args = { "-t", "d", "-a" }
if opts.hidden then
table.insert(args, "-H")
end
if not opts.respect_gitignore then
table.insert(args, "--no-ignore-vcs")
end
local entry_maker = opts.entry_maker { cwd = opts.cwd }
return async_oneshot_finder {
fn_command = function()
return { command = "fd", args = args }
end,
entry_maker = entry_maker,
results = { entry_maker(opts.cwd) },
cwd = opts.cwd,
}
else
local data = scan.scan_dir(opts.cwd, {
hidden = opts.hidden,
only_dirs = true,
respect_gitignore = opts.respect_gitignore,
})
table.insert(data, 1, opts.cwd)
return finders.new_table { results = data, entry_maker = opts.entry_maker { cwd = opts.cwd } }
end
-- TODO(fdschmidt93): how to add current folder in `fd`
-- if vim.fn.executable "fd" == 1 then
-- local cmd = { "fd", "-t", "d", "-a" }
-- if opts.hidden then
-- table.insert(cmd, "-H")
-- end
-- if not opts.respect_gitignore then
-- table.insert(cmd, "-I")
-- end
-- return finders.new_oneshot_job(
-- cmd,
-- { entry_maker = opts.entry_maker { cwd = opts.cwd, fd_finder = true }, cwd = opts.cwd }
-- )
-- else
local data = scan.scan_dir(opts.cwd, {
hidden = opts.hidden,
only_dirs = true,
respect_gitignore = opts.respect_gitignore,
})
table.insert(data, 1, opts.cwd)
return finders.new_table { results = data, entry_maker = opts.entry_maker { cwd = opts.cwd } }
end

--- Returns a finder that combines |fb_finders.browse_files| and |fb_finders.browse_folders| into a unified finder.
Expand Down
2 changes: 1 addition & 1 deletion scripts/gendocs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ docs.test = function()
"./lua/telescope/_extensions/file_browser.lua",
"./lua/telescope/_extensions/file_browser/picker.lua",
"./lua/telescope/_extensions/file_browser/actions.lua",
"./lua/telescope/_extensions/file_browser/finders.lua",
"./lua/telescope/_extensions/file_browser/finder.lua",
}

local output_file = "./doc/telescope-file-browser.txt"
Expand Down

0 comments on commit de3d791

Please sign in to comment.