-
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { assert, assertEquals } from "jsr:@std/assert@^1.0.1"; | ||
import { resolveTestDataPath } from "/denops-testdata/resolve.ts"; | ||
import { testHost } from "/denops-testutil/host.ts"; | ||
import { wait } from "/denops-testutil/wait.ts"; | ||
|
||
const scriptInterrupt = resolveTestDataPath("dummy_interrupt_plugin.ts"); | ||
|
||
testHost({ | ||
name: "denops#interrupt()", | ||
mode: "all", | ||
postlude: [ | ||
"let g:__test_denops_events = []", | ||
"autocmd User DenopsPlugin* call add(g:__test_denops_events, expand('<amatch>'))", | ||
"autocmd User DummyInterruptPlugin:* call add(g:__test_denops_events, expand('<amatch>'))", | ||
"runtime plugin/denops.vim", | ||
// NOTE: Disable startup on VimEnter. | ||
"autocmd! denops_plugin_internal_startup VimEnter", | ||
], | ||
fn: async ({ host, t }) => { | ||
await t.step("if the server is not yet running", async (t) => { | ||
await t.step("returns immediately", async () => { | ||
await host.call("denops#interrupt"); | ||
}); | ||
}); | ||
|
||
// Start the server and wait. | ||
await host.call("denops#server#start"); | ||
await wait(() => host.call("eval", "denops#server#status() ==# 'running'")); | ||
|
||
await t.step("if the plugin is not yet loaded", async (t) => { | ||
await t.step("returns immediately", async () => { | ||
await host.call("denops#interrupt"); | ||
}); | ||
}); | ||
|
||
await t.step("if the plugin is loaded", async (t) => { | ||
// Load plugin and wait. | ||
await host.call("execute", [ | ||
"let g:__test_denops_events = []", | ||
`call denops#plugin#load('dummy', '${scriptInterrupt}')`, | ||
], ""); | ||
await wait(async () => | ||
(await host.call("eval", "g:__test_denops_events") as string[]) | ||
.includes("DenopsPluginPost:dummy") | ||
); | ||
await host.call("execute", [ | ||
"let g:__test_denops_events = []", | ||
], ""); | ||
|
||
await t.step("returns immediately", async () => { | ||
await host.call("denops#interrupt"); | ||
}); | ||
|
||
await t.step("sends signal to the plugin", async () => { | ||
await wait(() => host.call("eval", "len(g:__test_denops_events)")); | ||
const events = await host.call( | ||
"eval", | ||
"g:__test_denops_events", | ||
) as string[]; | ||
assert( | ||
events.some((event) => | ||
event.startsWith("DummyInterruptPlugin:Interrupted:") | ||
), | ||
`Expected event 'DummyInterruptPlugin:Interrupted:*', but: ${ | ||
JSON.stringify(events) | ||
}`, | ||
); | ||
}); | ||
|
||
await host.call("denops#request", "dummy", "reset", []); | ||
|
||
await t.step("sends signal to the plugin with reason", async () => { | ||
await host.call("execute", [ | ||
"let g:__test_denops_events = []", | ||
], ""); | ||
|
||
await host.call("denops#interrupt", "test"); | ||
|
||
await wait(() => host.call("eval", "len(g:__test_denops_events)")); | ||
assertEquals(await host.call("eval", "g:__test_denops_events"), [ | ||
"DummyInterruptPlugin:Interrupted:test", | ||
]); | ||
}); | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { Entrypoint } from "jsr:@denops/core@^7.0.0"; | ||
|
||
export const main: Entrypoint = (denops) => { | ||
function reset(): void { | ||
const signal = denops.interrupted; | ||
signal?.addEventListener("abort", async () => { | ||
await denops.cmd( | ||
`doautocmd <nomodeline> User DummyInterruptPlugin:Interrupted:${signal.reason}`, | ||
); | ||
}, { once: true }); | ||
} | ||
reset(); | ||
|
||
denops.dispatcher = { | ||
reset, | ||
}; | ||
}; |