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 10, 2024
1 parent 4d23d35 commit ff24e02
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 @@ -87,7 +87,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 @@ -1614,7 +1614,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")
);
// Reload plugin.
await host.call("execute", [
"let g:__test_denops_events = []",
`call denops#plugin#reload('dummyWaitAsyncReloading')`,
], "");

const resultPromise = host.call("execute", [
"call denops#plugin#wait_async('dummyWaitAsyncReloading', { -> add(g:__test_denops_events, 'WaitAsyncCallbackCalled:dummyWaitAsyncReloading') })",
], "");

await t.step("returns immediately", async () => {
await deadline(resultPromise, 100);
});

await t.step("does not call the 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 the 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 ff24e02

Please sign in to comment.