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

feat(scandir): follow symlinks #509

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions lua/plenary/scandir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ local gen_search_pat = function(pattern)
end

local process_item = function(opts, name, typ, current_dir, next_dir, bp, data, giti, msp)
if opts.symlink and typ == "link" then
typ = uv.fs_stat(current_dir .. os_sep .. name).type
end

if opts.hidden or name:sub(1, 1) ~= "." then
if typ == "directory" then
local entry = current_dir .. os_sep .. name
Expand Down Expand Up @@ -146,6 +150,7 @@ end
-- opts.search_pattern (regex): regex for which files will be added, string, table of strings, or fn(e) -> bool
-- opts.on_insert(entry): Will be called for each element
-- opts.silent (bool): if true will not echo messages that are not accessible
-- opts.symlink (bool): if true will follow symlinks
-- @return array with files
m.scan_dir = function(path, opts)
opts = opts or {}
Expand Down
1 change: 1 addition & 0 deletions tests/plenary/job.symlink
8 changes: 8 additions & 0 deletions tests/plenary/scandir_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ describe("scandir", function()
eq(false, contains(dirs, "./asdf/asdf/adsf.lua"))
end)

it("with symlinks", function()
local dirs = scan.scan_dir(".", { symlink = true })
eq("table", type(dirs))
eq(true, contains(dirs, "./tests/plenary/job.symlink/validation_spec.lua"))
eq(true, contains(dirs, "./README.md"))
eq(true, contains(dirs, "./lua/plenary/job.lua"))
end)

it("with add directories", function()
local dirs = scan.scan_dir(".", { add_dirs = true })
eq("table", type(dirs))
Expand Down
Loading