Skip to content

Commit f1df3d6

Browse files
committed
fix: call schedule before event dispatch
1 parent 965e284 commit f1df3d6

File tree

4 files changed

+8
-12
lines changed

4 files changed

+8
-12
lines changed

lua/nvim-tree/actions/fs/create-file.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ local function create_and_notify(file)
2323
end
2424
if M.enable_async then
2525
async.call(vim.loop.fs_close, fd)
26-
async.schedule()
2726
else
2827
vim.loop.fs_close(fd)
2928
end
@@ -104,7 +103,6 @@ local async_fn = async.wrap(function(node)
104103
is_error = true
105104
break
106105
end
107-
async.schedule()
108106
events._dispatch_folder_created(new_file_path)
109107
end
110108
end

lua/nvim-tree/api.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ Api.marks.navigate.next = require("nvim-tree.marks.navigation").next
129129
Api.marks.navigate.prev = require("nvim-tree.marks.navigation").prev
130130
Api.marks.navigate.select = require("nvim-tree.marks.navigation").select
131131

132-
Api.async.call = require("nvim-tree.async").call
132+
Api.async.call = function(...)
133+
if not require("nvim-tree.async").in_async() then
134+
error "The async call is not triggered in an async context of nvim-tree, please use `api.in_async` to detect beforehand"
135+
end
136+
require("nvim-tree.async").call(...)
137+
end
133138
Api.async.in_async = require("nvim-tree.async").in_async
134139

135140
return Api

lua/nvim-tree/async.lua

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,6 @@ function M.schedule()
101101
end)
102102
end
103103

104-
function M.unwrap_err(...)
105-
local args = { ... }
106-
local err = table.remove(args, 1)
107-
if err then
108-
error(err)
109-
end
110-
return unpack(args)
111-
end
112-
113104
---@class Interrupter
114105
---@field yield fun()
115106
---@field interval number

lua/nvim-tree/events.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ local function dispatch(event_name, payload)
5656
safe_call_handlers(evt_handlers.normal)
5757

5858
if async.in_async() then
59+
async.schedule() -- schedule to avoid manually calling `vim.schedule` in event handlers
5960
safe_call_handlers(evt_handlers.async)
6061
else
6162
-- if we are not in async context, we should execute them in a new async context
6263
async.exec(function()
64+
async.schedule()
6365
safe_call_handlers(evt_handlers.async)
6466
end)
6567
end

0 commit comments

Comments
 (0)