Skip to content

Commit

Permalink
refactor: organize dispatcher of handle
Browse files Browse the repository at this point in the history
  • Loading branch information
kuuote committed Jan 15, 2024
1 parent 819bfc4 commit 88197c3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion autoload/skkeleton.vim
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function! skkeleton#vim_status() abort
endfunction

function! skkeleton#handle(func, opts) abort
let ret = skkeleton#request(a:func, [a:opts, skkeleton#vim_status()])
let ret = skkeleton#request('handle', [a:func, a:opts, skkeleton#vim_status()])

let g:skkeleton#state = ret.state

Expand Down
8 changes: 4 additions & 4 deletions denops/skkeleton/function/disable_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ test({
mode: "all",
name: "kakutei at disable",
async fn(denops: Denops) {
await denops.dispatch("skkeleton", "enable");
await denops.dispatch("skkeleton", "handle", "enable");
await dispatch(currentContext.get(), " ");
assertEquals(
await getResult(denops.dispatch("skkeleton", "disable")),
await getResult(denops.dispatch("skkeleton", "handle", "disable")),
" ",
);
await denops.dispatch("skkeleton", "enable");
await denops.dispatch("skkeleton", "handle", "enable");
await dispatch(currentContext.get(), "n");
assertEquals(
await getResult(denops.dispatch("skkeleton", "disable")),
await getResult(denops.dispatch("skkeleton", "handle", "disable")),
"ん",
);
},
Expand Down
6 changes: 3 additions & 3 deletions denops/skkeleton/function/mode_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ test({
name: "Can get skkeleton mode",
async fn(d: Denops) {
assertEquals(await d.call("skkeleton#mode"), "");
await d.dispatch("skkeleton", "enable");
await d.dispatch("skkeleton", "handle", "enable");
assertEquals(await d.call("skkeleton#mode"), "hira");
await d.dispatch("skkeleton", "disable");
await d.dispatch("skkeleton", "handle", "disable");
assertEquals(await d.call("skkeleton#mode"), "");
await d.dispatch("skkeleton", "enable");
await d.dispatch("skkeleton", "handle", "enable");
await katakana(currentContext.get());
assertEquals(await d.call("skkeleton#mode"), "kata");
await katakana(currentContext.get());
Expand Down
2 changes: 1 addition & 1 deletion denops/skkeleton/kana_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ test({
a: ["hoge", ""],
}, true);
config.kanaTable = "test";
await denops.call("skkeleton#request", "enable", []);
await denops.call("skkeleton#handle", "enable", {});
const context = currentContext.get();
await dispatch(context, "a");
assertEquals(context.preEdit.output(""), "hoge");
Expand Down
31 changes: 16 additions & 15 deletions denops/skkeleton/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,26 @@ export async function main(denops: Denops) {
registerKanaTable(tableName, table, !!create);
return Promise.resolve();
},
async enable(opts: unknown, vimStatus: unknown): Promise<HandleResult> {
async handle(
func: unknown,
opts: unknown,
vimStatus: unknown,
): Promise<HandleResult> {
await init(denops);
return buildResult(await enable(opts, vimStatus));
},
async disable(opts: unknown, vimStatus: unknown): Promise<HandleResult> {
await init(denops);
return buildResult(await disable(opts, vimStatus));
},
async toggle(opts: unknown, vimStatus: unknown): Promise<HandleResult> {
await init(denops);
const mode = await vars.g.get(denops, "skkeleton#mode", "");
if (!await denops.eval("g:skkeleton#enabled") || mode === "") {
if (func === "handleKey") {
return buildResult(await handle(opts, vimStatus));
} else if (func === "enable") {
return buildResult(await enable(opts, vimStatus));
} else {
} else if (func === "disable") {
return buildResult(await disable(opts, vimStatus));
} else if (func === "toggle") {
const noMode = await vars.g.get(denops, "skkeleton#mode", "") === "";
const disabled = noMode || !await denops.eval("g:skkeleton#enabled");
return buildResult(
await (disabled ? enable(opts, vimStatus) : disable(opts, vimStatus)),
);
}
},
async handleKey(opts: unknown, vimStatus: unknown): Promise<HandleResult> {
return buildResult(await handle(opts, vimStatus));
throw "Unsupported function: " + func;
},
reset() {
currentContext.init().denops = denops;
Expand Down

0 comments on commit 88197c3

Please sign in to comment.