Skip to content

Commit c037c7a

Browse files
committed
refactor(change-dir): add profile from higher order function
1 parent fdcdb0d commit c037c7a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

lua/nvim-tree/actions/change-dir.lua

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ local function should_change_dir()
5555
return M.options.enable and vim.tbl_isempty(vim.v.event)
5656
end
5757

58-
function M.force_dirchange(foldername, should_open_view)
59-
local ps = log.profile_start("change dir %s", foldername)
58+
local function add_profiling_to(f)
59+
return function(foldername, should_open_view)
60+
local ps = log.profile_start("change dir %s", foldername)
61+
f(foldername, should_open_view)
62+
log.profile_end(ps, "change dir %s", foldername)
63+
end
64+
end
6065

66+
M.force_dirchange = add_profiling_to(function(foldername, should_open_view)
6167
if should_change_dir() then
6268
cd(M.options.global, foldername)
6369
end
@@ -69,9 +75,7 @@ function M.force_dirchange(foldername, should_open_view)
6975
else
7076
require("nvim-tree.renderer").draw()
7177
end
72-
73-
log.profile_end(ps, "change dir %s", foldername)
74-
end
78+
end)
7579

7680
function M.setup(options)
7781
M.options = options.actions.change_dir

0 commit comments

Comments
 (0)