diff --git a/denops/skkeleton/config.ts b/denops/skkeleton/config.ts index 905274e7..48805635 100644 --- a/denops/skkeleton/config.ts +++ b/denops/skkeleton/config.ts @@ -1,5 +1,5 @@ import { Denops } from "./deps.ts"; -import { ensure, is } from "./deps/unknownutil.ts"; +import { is, u } from "./deps/unknownutil.ts"; import { getKanaTable, loadKanaTableFiles } from "./kana.ts"; import { ConfigOptions, Encode, Encoding } from "./types.ts"; import { homeExpand } from "./util.ts"; @@ -47,11 +47,11 @@ function ensureEncoding(x: unknown): Encoding { } const validators: Validators = { - acceptIllegalResult: (x) => ensure(x, is.Boolean), - completionRankFile: (x) => ensure(x, is.String), - databasePath: (x) => ensure(x, is.String), - debug: (x) => ensure(x, is.Boolean), - eggLikeNewline: (x) => ensure(x, is.Boolean), + acceptIllegalResult: (x) => u.ensure(x, is.Boolean), + completionRankFile: (x) => u.ensure(x, is.String), + databasePath: (x) => u.ensure(x, is.String), + debug: (x) => u.ensure(x, is.Boolean), + eggLikeNewline: (x) => u.ensure(x, is.Boolean), globalDictionaries: (x): (string | [string, string])[] => { if ( !is.ArrayOf( @@ -74,11 +74,11 @@ const validators: Validators = { } return x; }, - immediatelyCancel: (x) => ensure(x, is.Boolean), - immediatelyDictionaryRW: (x) => ensure(x, is.Boolean), - immediatelyOkuriConvert: (x) => ensure(x, is.Boolean), + immediatelyCancel: (x) => u.ensure(x, is.Boolean), + immediatelyDictionaryRW: (x) => u.ensure(x, is.Boolean), + immediatelyOkuriConvert: (x) => u.ensure(x, is.Boolean), kanaTable: (x): string => { - const name = ensure(x, is.String); + const name = u.ensure(x, is.String); try { getKanaTable(name); } catch { @@ -86,33 +86,33 @@ const validators: Validators = { } return name; }, - keepMode: (x) => ensure(x, is.Boolean), - keepState: (x) => ensure(x, is.Boolean), - markerHenkan: (x) => ensure(x, is.String), - markerHenkanSelect: (x) => ensure(x, is.String), - registerConvertResult: (x) => ensure(x, is.Boolean), + keepMode: (x) => u.ensure(x, is.Boolean), + keepState: (x) => u.ensure(x, is.Boolean), + markerHenkan: (x) => u.ensure(x, is.String), + markerHenkanSelect: (x) => u.ensure(x, is.String), + registerConvertResult: (x) => u.ensure(x, is.Boolean), selectCandidateKeys: (x) => { - const keys = ensure(x, is.String); + const keys = u.ensure(x, is.String); if (keys.length !== 7) { throw TypeError("selectCandidateKeys.length !== 7"); } return keys; }, - setUndoPoint: (x) => ensure(x, is.Boolean), - showCandidatesCount: (x) => ensure(x, is.Number), - skkServerHost: (x) => ensure(x, is.String), - skkServerPort: (x) => ensure(x, is.Number), + setUndoPoint: (x) => u.ensure(x, is.Boolean), + showCandidatesCount: (x) => u.ensure(x, is.Number), + skkServerHost: (x) => u.ensure(x, is.String), + skkServerPort: (x) => u.ensure(x, is.Number), skkServerReqEnc: ensureEncoding, skkServerResEnc: ensureEncoding, - sources: (x) => ensure(x, is.ArrayOf(is.String)), + sources: (x) => u.ensure(x, is.ArrayOf(is.String)), useGoogleJapaneseInput: () => { throw '`useGoogleJapaneseInput` is removed. Please use `sources` with "google_japanese_input"'; }, - usePopup: (x) => ensure(x, is.Boolean), + usePopup: (x) => u.ensure(x, is.Boolean), useSkkServer: () => { throw '`useSkkServer` is removed. Please use `sources` with "skk_server"'; }, - userDictionary: (x) => ensure(x, is.String), + userDictionary: (x) => u.ensure(x, is.String), }; async function normalize( diff --git a/denops/skkeleton/deps/unknownutil.ts b/denops/skkeleton/deps/unknownutil.ts index 11ca144d..5ee94fbf 100644 --- a/denops/skkeleton/deps/unknownutil.ts +++ b/denops/skkeleton/deps/unknownutil.ts @@ -1 +1,2 @@ -export * from "https://deno.land/x/unknownutil@v3.16.0/mod.ts"; +export * as u from "https://deno.land/x/unknownutil@v3.16.0/mod.ts"; +export { is } from "https://deno.land/x/unknownutil@v3.16.0/mod.ts"; diff --git a/denops/skkeleton/kana.ts b/denops/skkeleton/kana.ts index 2c284ec1..7e8679f3 100644 --- a/denops/skkeleton/kana.ts +++ b/denops/skkeleton/kana.ts @@ -1,6 +1,6 @@ import { config } from "./config.ts"; import { distinctBy } from "./deps/std/collections.ts"; -import { assert, is } from "./deps/unknownutil.ts"; +import { is, u } from "./deps/unknownutil.ts"; import { functions } from "./function.ts"; import { romToHira } from "./kana/rom_hira.ts"; import { romToZen } from "./kana/rom_zen.ts"; @@ -48,7 +48,7 @@ export function registerKanaTable( console.log("skkeleton: new kana table"); console.log(`name: ${name}, table: ${Deno.inspect(rawTable)}`); } - assert(rawTable, is.Record); + u.assert(rawTable, is.Record); const table: KanaTable = Object.entries(rawTable).map(( e, ) => [e[0], asKanaResult(e[1])]); diff --git a/denops/skkeleton/main.ts b/denops/skkeleton/main.ts index d667c82f..85939abc 100644 --- a/denops/skkeleton/main.ts +++ b/denops/skkeleton/main.ts @@ -1,6 +1,6 @@ import { config, setConfig } from "./config.ts"; import { autocmd, Denops, fn, op, vars } from "./deps.ts"; -import { assert, AssertError, is } from "./deps/unknownutil.ts"; +import { is, u } from "./deps/unknownutil.ts"; import { functions, modeFunctions } from "./function.ts"; import { disable as disableFunc } from "./function/disable.ts"; import { load as loadDictionary } from "./dictionary.ts"; @@ -45,7 +45,7 @@ function isOpts(x: any): x is Opts { function assertOpts(x: unknown): asserts x is Opts { if (!isOpts(x)) { - throw new AssertError("value must be Opts"); + throw new u.AssertError("value must be Opts"); } } @@ -262,18 +262,18 @@ export async function main(denops: Denops) { } denops.dispatcher = { async config(config: unknown) { - assert(config, is.Record); + u.assert(config, is.Record); await setConfig(config, denops); return; }, async registerKeyMap(state: unknown, key: unknown, funcName: unknown) { - assert(state, is.String); - assert(key, is.String); + u.assert(state, is.String); + u.assert(key, is.String); await receiveNotation(denops); registerKeyMap(state, key, funcName); }, registerKanaTable(tableName: unknown, table: unknown, create: unknown) { - assert(tableName, is.String); + u.assert(tableName, is.String); registerKanaTable(tableName, table, !!create); return Promise.resolve(); }, @@ -285,6 +285,8 @@ export async function main(denops: Denops) { await init(denops); if (func === "handleKey") { return buildResult(await handle(opts, vimStatus)); + } else if (func === "setState") { + return buildResult(await enable(opts, vimStatus)); } else if (func === "enable") { return buildResult(await enable(opts, vimStatus)); } else if (func === "disable") { @@ -337,8 +339,8 @@ export async function main(denops: Denops) { await denops.dispatcher.completeCallback(kana, word); }, async completeCallback(kana: unknown, word: unknown) { - assert(kana, is.String); - assert(word, is.String); + u.assert(kana, is.String); + u.assert(word, is.String); const lib = await currentLibrary.get(); await lib.registerHenkanResult("okurinasi", kana, word); const context = currentContext.get(); @@ -362,9 +364,9 @@ export async function main(denops: Denops) { await currentLibrary.get(); }, async updateDatabase(path: unknown, encoding: unknown, force: unknown) { - assert(path, is.String); - assert(encoding, is.String); - assert(force, is.Boolean); + u.assert(path, is.String); + u.assert(encoding, is.String); + u.assert(force, is.Boolean); await DenoKvDictionary.create(path, encoding) .then((dict) => dict.load(force)); await denops.cmd(`echomsg 'updated database: "${path}"'`); diff --git a/denops/skkeleton/notation.ts b/denops/skkeleton/notation.ts index 1b8f0e04..3d9d28b5 100644 --- a/denops/skkeleton/notation.ts +++ b/denops/skkeleton/notation.ts @@ -1,5 +1,5 @@ import type { Denops } from "./deps.ts"; -import { assert, is } from "./deps/unknownutil.ts"; +import { is, u } from "./deps/unknownutil.ts"; let received = false; export let notationToKey: Record = {}; @@ -10,10 +10,10 @@ export async function receiveNotation(denops: Denops) { return; } const n2k = await denops.eval("g:skkeleton#notation#notation_to_key"); - assert(n2k, is.RecordOf(is.String)); + u.assert(n2k, is.RecordOf(is.String)); notationToKey = n2k; const k2n = await denops.eval("g:skkeleton#notation#key_to_notation"); - assert(k2n, is.RecordOf(is.String)); + u.assert(k2n, is.RecordOf(is.String)); keyToNotation = k2n; received = true; } diff --git a/denops/skkeleton/sources/user_dictionary.ts b/denops/skkeleton/sources/user_dictionary.ts index 4551e345..9d841f8e 100644 --- a/denops/skkeleton/sources/user_dictionary.ts +++ b/denops/skkeleton/sources/user_dictionary.ts @@ -11,7 +11,7 @@ import { UserDictionaryPath, } from "../dictionary.ts"; import { wrap } from "../deps/iterator_helpers.ts"; -import { assert, is } from "../deps/unknownutil.ts"; +import { is, u } from "../deps/unknownutil.ts"; export class Source implements BaseSource { async getDictionaries(): Promise { @@ -166,7 +166,7 @@ export class Dictionary implements UserDictionary { return; } const rankData = JSON.parse(await Deno.readTextFile(rankPath)); - assert(rankData, is.ArrayOf(is.String)); + u.assert(rankData, is.ArrayOf(is.String)); this.#rank = new Map(rankData.map((c, i) => [c, i])); } diff --git a/denops/skkeleton/types.ts b/denops/skkeleton/types.ts index 08adc658..0867d15d 100644 --- a/denops/skkeleton/types.ts +++ b/denops/skkeleton/types.ts @@ -1,5 +1,3 @@ -import { isRecord } from "./deps/unknownutil.ts"; - export type CompletionData = [string, string[]][]; export type RankData = [string, number][]; @@ -8,13 +6,6 @@ export type CompletionMetadata = { kana: string; }; -export function asCompletionMetadata(x: unknown): CompletionMetadata | null { - if (isRecord(x) && x.tag === "skkeleton") { - return x as CompletionMetadata; - } - return null; -} - export const Encode = { "utf-32": "UTF32", "utf-16": "UTF16",