Skip to content

Commit

Permalink
chore
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 committed Jun 18, 2024
1 parent 681a933 commit bbcc2e4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 37 deletions.
48 changes: 23 additions & 25 deletions lua/fzfx/cfg/file_explorer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,18 +275,19 @@ M._directory_previewer = function(filename)
return f(filename)
end

local parser
if consts.HAS_LSD then
parser = parsers_helper.parse_lsd

Check warning on line 280 in lua/fzfx/cfg/file_explorer.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/file_explorer.lua#L280

Added line #L280 was not covered by tests
elseif consts.HAS_EZA then
parser = parsers_helper.parse_eza

Check warning on line 282 in lua/fzfx/cfg/file_explorer.lua

View check run for this annotation

Codecov / codecov/patch

lua/fzfx/cfg/file_explorer.lua#L282

Added line #L282 was not covered by tests
else
parser = parsers_helper.parse_ls
end

--- @param line string
--- @param context fzfx.FileExplorerPipelineContext
--- @return string[]|nil
M._previewer = function(line, context)
local parser
if consts.HAS_LSD then
parser = parsers_helper.parse_lsd
elseif consts.HAS_EZA then
parser = parsers_helper.parse_eza
else
parser = parsers_helper.parse_ls
end
local parsed = parser(line, context)

if path.isfile(parsed.filename) then
Expand Down Expand Up @@ -323,34 +324,31 @@ M.previewers = {
--- @param line string
--- @param context fzfx.FileExplorerPipelineContext
M._cd_file_explorer = function(line, context)
local parsed = consts.HAS_LSD and parsers_helper.parse_lsd(line, context)
or (
consts.HAS_EZA and parsers_helper.parse_eza(line, context)
or parsers_helper.parse_ls(line, context)
)
if vim.fn.isdirectory(parsed.filename) > 0 then
local parsed = parser(line, context)

if path.isdir(parsed.filename) then
fileio.writefile(context.cwd, parsed.filename)
end
end

--- @param line string
--- @param context fzfx.FileExplorerPipelineContext
M._upper_file_explorer = function(line, context)
log.debug(
string.format(
"|_upper_file_explorer| line:%s, context:%s",
vim.inspect(line),
vim.inspect(context)
)
)
-- log.debug(
-- string.format(
-- "|_upper_file_explorer| line:%s, context:%s",
-- vim.inspect(line),
-- vim.inspect(context)
-- )
-- )
local cwd = fileio.readfile(context.cwd) --[[@as string]]
log.debug("|_upper_file_explorer| cwd:" .. vim.inspect(cwd))
-- log.debug("|_upper_file_explorer| cwd:" .. vim.inspect(cwd))
local target = vim.fn.fnamemodify(cwd, ":h") --[[@as string]]
log.debug("|_upper_file_explorer| target:" .. vim.inspect(target))
-- log.debug("|_upper_file_explorer| target:" .. vim.inspect(target))
-- Windows root folder: `C:\`
-- Unix/linux root folder: `/`
local root_len = consts.IS_WINDOWS and 3 or 1
if vim.fn.isdirectory(target) > 0 and string.len(target) > root_len then
local root_dir_len = consts.IS_WINDOWS and 3 or 1
if path.isdir(target) and string.len(target) > root_dir_len then
fileio.writefile(context.cwd, target)
end
end
Expand Down
20 changes: 8 additions & 12 deletions spec/cfg/file_explorer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -312,39 +312,35 @@ describe("fzfx.cfg.file_explorer", function()
local ctx = file_explorer_cfg._context_maker()
if consts.HAS_LSD then
for _, line in ipairs(LSD_LINES) do
local actual = file_explorer_cfg._cd_file_explorer(line, ctx)
assert_true(actual == nil)
file_explorer_cfg._cd_file_explorer(line, ctx)
end
elseif consts.HAS_EZA then
for _, line in ipairs(EZA_LINES) do
local actual = file_explorer_cfg._cd_file_explorer(line, ctx)
assert_true(actual == nil)
file_explorer_cfg._cd_file_explorer(line, ctx)
end
else
for _, line in ipairs(LS_LINES) do
local actual = file_explorer_cfg._cd_file_explorer(line, ctx)
assert_true(actual == nil)
file_explorer_cfg._cd_file_explorer(line, ctx)
end
end
assert_true(true)
end)
it("_upper_file_explorer", function()
local ctx = file_explorer_cfg._context_maker()
if consts.HAS_LSD then
for _, line in ipairs(LSD_LINES) do
local actual = file_explorer_cfg._upper_file_explorer(line, ctx)
assert_true(actual == nil)
file_explorer_cfg._upper_file_explorer(line, ctx)
end
elseif consts.HAS_EZA then
for _, line in ipairs(EZA_LINES) do
local actual = file_explorer_cfg._upper_file_explorer(line, ctx)
assert_true(actual == nil)
file_explorer_cfg._upper_file_explorer(line, ctx)
end
else
for _, line in ipairs(LS_LINES) do
local actual = file_explorer_cfg._upper_file_explorer(line, ctx)
assert_true(actual == nil)
file_explorer_cfg._upper_file_explorer(line, ctx)
end
end
assert_true(true)
end)
end)
end)

0 comments on commit bbcc2e4

Please sign in to comment.