Skip to content

Commit

Permalink
🐛 fix denops#plugin#wait_async() calls the callback after reloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
Milly committed Jul 11, 2024
1 parent dba9343 commit 173e304
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
1 change: 0 additions & 1 deletion autoload/denops/_internal/plugin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ function! s:DenopsSystemPluginUnloadPost() abort
const l:name = matchstr(expand('<amatch>'), 'DenopsSystemPluginUnloadPost:\zs.*')
let l:plugin = denops#_internal#plugin#get(l:name)
let l:plugin.state = s:STATE_RESERVED
let l:plugin.callbacks = []
execute printf('doautocmd <nomodeline> User DenopsPluginUnloadPost:%s', l:name)
endfunction

Expand Down
46 changes: 45 additions & 1 deletion tests/denops/runtime/functions/plugin_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,51 @@ testHost({
});
});

// FIXME: "if the plugin is reloading"
await t.step("if the plugin is reloading", async (t) => {
// Load plugin and wait.
await host.call("execute", [
"let g:__test_denops_events = []",
`call denops#plugin#load('dummyWaitAsyncReloading', '${scriptValidWait}')`,
], "");
await wait(async () =>
(await host.call("eval", "g:__test_denops_events") as string[])
.includes("DenopsPluginPost:dummyWaitAsyncReloading")
);

await host.call("execute", [
"let g:__test_denops_events = []",
`call denops#plugin#reload('dummyWaitAsyncReloading')`,
"let g:__test_denops_wait_start = reltime()",
"call denops#plugin#wait_async('dummyWaitAsyncReloading', { -> add(g:__test_denops_events, 'WaitAsyncCallbackCalled:dummyWaitAsyncReloading') })",
"let g:__test_denops_wait_elapsed = g:__test_denops_wait_start->reltime()->reltimefloat()",
], "");

await t.step("returns immediately", async () => {
const elapsed_sec = await host.call(
"eval",
"g:__test_denops_wait_elapsed",
) as number;
assertLess(elapsed_sec, 0.1);
});

await t.step("does not call `callback` immediately", async () => {
const actual =
(await host.call("eval", "g:__test_denops_events") as string[])
.filter((ev) => ev.startsWith("WaitAsyncCallbackCalled:"));
assertEquals(actual, []);
});

await t.step("calls `callback` when the plugin is loaded", async () => {
await wait(async () =>
(await host.call("eval", "g:__test_denops_events") as string[])
.includes("DenopsPluginPost:dummyWaitAsyncReloading")
);
assertArrayIncludes(
await host.call("eval", "g:__test_denops_events") as string[],
["WaitAsyncCallbackCalled:dummyWaitAsyncReloading"],
);
});
});

await t.step("if the plugin is reloaded", async (t) => {
// Load plugin and wait.
Expand Down

0 comments on commit 173e304

Please sign in to comment.