Skip to content

Commit 81269a6

Browse files
authored
chore: remove async to avoid unecessary complexity (nvim-tree#277)
1 parent bbb8d60 commit 81269a6

File tree

2 files changed

+27
-38
lines changed

2 files changed

+27
-38
lines changed

lua/nvim-tree.lua

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ function M.toggle()
1414
lib.close()
1515
else
1616
if vim.g.nvim_tree_follow == 1 then
17-
vim.schedule(function() M.find_file(true) end)
17+
M.find_file(true)
1818
else
19-
vim.schedule(lib.open)
19+
lib.open()
2020
end
2121
end
2222
end
@@ -28,27 +28,21 @@ function M.close()
2828
end
2929
end
3030

31-
function M.open(cb)
32-
vim.schedule(
33-
function()
34-
if not lib.win_open() then
35-
lib.open()
36-
else
37-
lib.set_target_win()
38-
end
39-
pcall(cb)
40-
end
41-
)
31+
function M.open()
32+
if not lib.win_open() then
33+
lib.open()
34+
else
35+
lib.set_target_win()
36+
end
4237
end
4338

4439
local winopts = config.window_options()
4540
function M.tab_change()
4641
-- we need defer_fn to make sure we close/open after we enter the tab
4742
vim.defer_fn(function()
4843
if M.close() then
49-
M.open(function()
50-
api.nvim_command('wincmd '..winopts.open_command)
51-
end)
44+
M.open()
45+
api.nvim_command('wincmd '..winopts.open_command)
5246
end
5347
end, 1)
5448
end
@@ -82,7 +76,7 @@ local keypress_funcs = {
8276
prev_git_item = gen_go_to('prev_git_item'),
8377
next_git_item = gen_go_to('next_git_item'),
8478
dir_up = lib.dir_up,
85-
close = function(node) M.close() end,
79+
close = function() M.close() end,
8680
preview = function(node)
8781
if node.entries ~= nil or node.name == '..' then return end
8882
return lib.open_file('preview', node.absolute_path)
@@ -153,13 +147,11 @@ function M.find_file(with_open)
153147
local filepath = vim.fn.fnamemodify(bufname, ':p')
154148

155149
if with_open then
156-
return M.open(
157-
function()
158-
lib.win_focus()
159-
if not is_file_readable(filepath) then return end
160-
lib.set_index_and_redraw(filepath)
161-
end
162-
)
150+
M.open()
151+
lib.win_focus()
152+
if not is_file_readable(filepath) then return end
153+
lib.set_index_and_redraw(filepath)
154+
return
163155
end
164156

165157
if not is_file_readable(filepath) then return end

lua/nvim-tree/lib.lua

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,22 +155,19 @@ local function refresh_nodes(node)
155155
end
156156

157157
function M.refresh_tree()
158-
vim.schedule(
159-
function ()
160-
if vim.v.exiting ~= nil then return end
158+
if vim.v.exiting ~= nil then return end
161159

162-
refresh_nodes(M.Tree)
160+
refresh_nodes(M.Tree)
163161

164-
if config.get_icon_state().show_git_icon or vim.g.nvim_tree_git_hl == 1 then
165-
git.reload_roots()
166-
refresh_git(M.Tree)
167-
end
168-
if M.win_open() then
169-
renderer.draw(M.Tree, true)
170-
else
171-
M.Tree.loaded = false
172-
end
173-
end)
162+
if config.get_icon_state().show_git_icon or vim.g.nvim_tree_git_hl == 1 then
163+
git.reload_roots()
164+
refresh_git(M.Tree)
165+
end
166+
if M.win_open() then
167+
renderer.draw(M.Tree, true)
168+
else
169+
M.Tree.loaded = false
170+
end
174171
end
175172

176173
function M.set_index_and_redraw(fname)

0 commit comments

Comments
 (0)