Skip to content

Commit

Permalink
Merge pull request #203 from vim-skk/remove_deps
Browse files Browse the repository at this point in the history
Remove deps
  • Loading branch information
kuuote authored Sep 10, 2024
2 parents 882ec0c + f8c0d30 commit 843b02b
Show file tree
Hide file tree
Showing 32 changed files with 109 additions and 86 deletions.
48 changes: 25 additions & 23 deletions denops/skkeleton/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Denops } from "./deps.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";

import { is } from "jsr:@core/unknownutil@~4.3.0/is";
import { ensure } from "jsr:@core/unknownutil@~4.3.0/ensure";

export const config: Omit<ConfigOptions, "globalDictionaries"> & {
globalDictionaries: [string, string][];
} = {
Expand Down Expand Up @@ -47,11 +49,11 @@ function ensureEncoding(x: unknown): Encoding {
}

const validators: Validators = {
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),
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),
globalDictionaries: (x): (string | [string, string])[] => {
if (
!is.ArrayOf(
Expand All @@ -78,45 +80,45 @@ const validators: Validators = {
}
return x;
},
immediatelyCancel: (x) => u.ensure(x, is.Boolean),
immediatelyDictionaryRW: (x) => u.ensure(x, is.Boolean),
immediatelyOkuriConvert: (x) => u.ensure(x, is.Boolean),
immediatelyCancel: (x) => ensure(x, is.Boolean),
immediatelyDictionaryRW: (x) => ensure(x, is.Boolean),
immediatelyOkuriConvert: (x) => ensure(x, is.Boolean),
kanaTable: (x): string => {
const name = u.ensure(x, is.String);
const name = ensure(x, is.String);
try {
getKanaTable(name);
} catch {
throw TypeError("can't use undefined kanaTable: " + x);
}
return name;
},
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),
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),
selectCandidateKeys: (x) => {
const keys = u.ensure(x, is.String);
const keys = ensure(x, is.String);
if (keys.length !== 7) {
throw TypeError("selectCandidateKeys.length !== 7");
}
return keys;
},
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),
setUndoPoint: (x) => ensure(x, is.Boolean),
showCandidatesCount: (x) => ensure(x, is.Number),
skkServerHost: (x) => ensure(x, is.String),
skkServerPort: (x) => ensure(x, is.Number),
skkServerReqEnc: ensureEncoding,
skkServerResEnc: ensureEncoding,
sources: (x) => u.ensure(x, is.ArrayOf(is.String)),
sources: (x) => ensure(x, is.ArrayOf(is.String)),
useGoogleJapaneseInput: () => {
throw '`useGoogleJapaneseInput` is removed. Please use `sources` with "google_japanese_input"';
},
usePopup: (x) => u.ensure(x, is.Boolean),
usePopup: (x) => ensure(x, is.Boolean),
useSkkServer: () => {
throw '`useSkkServer` is removed. Please use `sources` with "skk_server"';
},
userDictionary: (x) => u.ensure(x, is.String),
userDictionary: (x) => ensure(x, is.String),
};

async function normalize(
Expand Down
3 changes: 2 additions & 1 deletion denops/skkeleton/config_test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { config } from "./config.ts";
import { Context } from "./context.ts";
import { Denops } from "./deps.ts";
import { assertEquals } from "./deps/std/assert.ts";
import { disable } from "./function/disable.ts";
import { katakana } from "./function/mode.ts";
import { dispatch } from "./function/testutil.ts";
import { currentContext, currentLibrary, variables } from "./store.ts";
import { test } from "./testutil.ts";

import { assertEquals } from "jsr:@std/assert@~1.0.3/equals";

const defaultConfig = { ...config };

const lib = await currentLibrary.get();
Expand Down
6 changes: 3 additions & 3 deletions denops/skkeleton/deps/dictionary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * as yaml from "jsr:@std/[email protected].4";
export * as msgpack from "https://esm.sh/@msgpack/[email protected]";
export { default as jsonschema } from "https://esm.sh/[email protected]";
export * as yaml from "jsr:@std/yaml@~1.0.5";
export * as msgpack from "npm:@msgpack/[email protected]";
export { default as jsonschema } from "npm:[email protected]";
export { default as jisyoschema } from "https://cdn.jsdelivr.net/gh/skk-dict/jisyo/schema/jisyo.schema.v0.0.0.json" with { type: "json" };
1 change: 0 additions & 1 deletion denops/skkeleton/deps/encoding_japanese.ts

This file was deleted.

1 change: 0 additions & 1 deletion denops/skkeleton/deps/japanese_numeral.ts

This file was deleted.

1 change: 0 additions & 1 deletion denops/skkeleton/deps/roman.ts

This file was deleted.

1 change: 0 additions & 1 deletion denops/skkeleton/deps/std/assert.ts

This file was deleted.

1 change: 0 additions & 1 deletion denops/skkeleton/deps/std/async.ts

This file was deleted.

1 change: 0 additions & 1 deletion denops/skkeleton/deps/std/collections.ts

This file was deleted.

1 change: 0 additions & 1 deletion denops/skkeleton/deps/std/path.ts

This file was deleted.

1 change: 0 additions & 1 deletion denops/skkeleton/deps/std/streams.ts

This file was deleted.

2 changes: 0 additions & 2 deletions denops/skkeleton/deps/unknownutil.ts

This file was deleted.

13 changes: 7 additions & 6 deletions denops/skkeleton/dictionary.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { config } from "./config.ts";
import { toFileUrl } from "./deps/std/path.ts";
import { JpNum } from "./deps/japanese_numeral.ts";
import { RomanNum } from "./deps/roman.ts";
import { zip } from "./deps/std/collections.ts";
import type { CompletionData, RankData } from "./types.ts";
import { number2kanji } from "npm:@geolonia/[email protected]";
import { convertNumberToRoman } from "npm:[email protected]";

import { toFileUrl } from "jsr:@std/path@~1.0.3/to-file-url";
import { zip } from "jsr:@std/collections@~1.0.5/zip";

export const okuriAriMarker = ";; okuri-ari entries.";
export const okuriNasiMarker = ";; okuri-nasi entries.";
Expand Down Expand Up @@ -54,8 +55,8 @@ function toKanjiModern(n: number): string {
return kanjiNumbers[parseInt(c)];
});
}
const toRoman: (n: number) => string = RomanNum.convertNumberToRoman;
const toKanjiClassic: (n: number) => string = JpNum.number2kanji;
const toRoman: (n: number) => string = convertNumberToRoman;
const toKanjiClassic: (n: number) => string = number2kanji;

function toDaiji(n: number): string {
return toKanjiClassic(n)
Expand Down
7 changes: 5 additions & 2 deletions denops/skkeleton/dictionary_test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { dirname, fromFileUrl, join } from "./deps/std/path.ts";
import { assertEquals } from "./deps/std/assert.ts";
import { Dictionary, Library, wrapDictionary } from "./dictionary.ts";
import { Dictionary as SkkDictionary } from "./sources/skk_dictionary.ts";
import { Dictionary as DenoKvDictionary } from "./sources/deno_kv.ts";
import { Dictionary as UserDictionary } from "./sources/user_dictionary.ts";

import { assertEquals } from "jsr:@std/assert@~1.0.3/equals";
import { dirname } from "jsr:@std/path@~1.0.3/dirname";
import { fromFileUrl } from "jsr:@std/path@~1.0.3/from-file-url";
import { join } from "jsr:@std/path@~1.0.3/join";

const newJisyoJson = join(
dirname(fromFileUrl(import.meta.url)),
"testdata",
Expand Down
3 changes: 2 additions & 1 deletion denops/skkeleton/function/common_test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { config } from "../config.ts";
import { Context } from "../context.ts";
import { assertEquals } from "../deps/std/assert.ts";
import { currentLibrary } from "../store.ts";
import { cancel, kakutei, kakuteiKey } from "./common.ts";
import { katakana } from "./mode.ts";
import { dispatch } from "./testutil.ts";

import { assertEquals } from "jsr:@std/assert@~1.0.3/equals";

const lib = await currentLibrary.get();

await lib.registerHenkanResult("okurinasi", "あ", "い");
Expand Down
3 changes: 2 additions & 1 deletion denops/skkeleton/function/dictionary_test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Denops } from "../deps.ts";
import { assertEquals } from "../deps/std/assert.ts";
import { currentKanaTable, getKanaTable } from "../kana.ts";
import { HenkanState } from "../state.ts";
import { currentContext } from "../store.ts";
import { test } from "../testutil.ts";
import { registerWord } from "./dictionary.ts";

import { assertEquals } from "jsr:@std/assert@~1.0.3/equals";

test({
mode: "all",
name: "Don't put string when register dictionary was cancelled",
Expand Down
3 changes: 2 additions & 1 deletion denops/skkeleton/function/disable_test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Denops } from "../deps.ts";
import { assertEquals } from "../deps/std/assert.ts";
import { currentContext } from "../store.ts";
import { test } from "../testutil.ts";
import { dispatch } from "./testutil.ts";

import { assertEquals } from "jsr:@std/assert@~1.0.3/equals";

// deno-lint-ignore no-explicit-any
async function getResult(x: Promise<any>): Promise<string> {
return (await x)?.result;
Expand Down
3 changes: 2 additions & 1 deletion denops/skkeleton/function/henkan_test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Context } from "../context.ts";
import { assertEquals } from "../deps/std/assert.ts";
import { currentLibrary } from "../store.ts";
import { dispatch } from "./testutil.ts";

import { assertEquals } from "jsr:@std/assert@~1.0.3/equals";

const l = await currentLibrary.get();
await l.registerHenkanResult("okurinasi", "へんかん", "返還");
await l.registerHenkanResult("okurinasi", "へんかん", "変換");
Expand Down
3 changes: 2 additions & 1 deletion denops/skkeleton/function/input_test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { config } from "../config.ts";
import { Context } from "../context.ts";
import { Denops, op } from "../deps.ts";
import { assertEquals } from "../deps/std/assert.ts";
import { test } from "../testutil.ts";
import { kakutei } from "./common.ts";
import { deleteChar, henkanPoint } from "./input.ts";
import { hankatakana, katakana } from "./mode.ts";
import { dispatch } from "./testutil.ts";

import { assertEquals } from "jsr:@std/assert@~1.0.3/equals";

Deno.test({
name: "kana input",
async fn() {
Expand Down
3 changes: 2 additions & 1 deletion denops/skkeleton/function/mode_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { autocmd, Denops, vars } from "../deps.ts";
import { assertEquals } from "../deps/std/assert.ts";
import { currentKanaTable } from "../kana.ts";
import { currentLibrary } from "../store.ts";
import { currentContext } from "../store.ts";
Expand All @@ -9,6 +8,8 @@ import { deleteChar, kanaInput } from "./input.ts";
import { abbrev, hankatakana, katakana, zenkaku } from "./mode.ts";
import { dispatch } from "./testutil.ts";

import { assertEquals } from "jsr:@std/assert@~1.0.3/equals";

test({
mode: "all",
name: "Can get skkeleton mode",
Expand Down
8 changes: 5 additions & 3 deletions denops/skkeleton/kana.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { config } from "./config.ts";
import { distinctBy } from "./deps/std/collections.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";
import type { KanaResult, KanaTable } from "./kana/type.ts";
import { Cell, readFileWithEncoding } from "./util.ts";

import { distinctBy } from "jsr:@std/collections@~1.0.5/distinct-by";
import { is } from "jsr:@core/unknownutil@~4.3.0/is";
import { assert } from "jsr:@core/unknownutil@~4.3.0/assert";

type PartialKanaTable = [string, KanaResult | null][];

const tables: Cell<Record<string, KanaTable>> = new Cell(() => ({
Expand Down Expand Up @@ -52,7 +54,7 @@ export function registerKanaTable(
console.log("skkeleton: new kana table");
console.log(`name: ${name}, table: ${Deno.inspect(rawTable)}`);
}
u.assert(rawTable, is.Record);
assert(rawTable, is.Record);
const table: PartialKanaTable = Object.entries(rawTable)
.map(([kana, result]) => {
return [kana, asKanaResult(result)];
Expand Down
6 changes: 4 additions & 2 deletions denops/skkeleton/kana_test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Denops } from "./deps.ts";
import { config } from "./config.ts";
import { Context } from "./context.ts";
import { assertEquals } from "./deps/std/assert.ts";
import { dispatch } from "./function/testutil.ts";
import { registerKanaTable } from "./kana.ts";
import { currentContext } from "./store.ts";
import { test } from "./testutil.ts";

import { assertEquals } from "jsr:@std/assert@~1.0.3/equals";

Deno.test({
name: "customize kanatable",
async fn() {
Expand Down Expand Up @@ -34,7 +36,7 @@ Deno.test({
test({
mode: "all",
name: "create kanatable",
async fn(denops) {
async fn(denops: Denops) {
registerKanaTable("test", {
a: ["hoge", ""],
}, true);
Expand Down
6 changes: 4 additions & 2 deletions denops/skkeleton/keymap_test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Denops } from "./deps.ts";
import { test } from "./testutil.ts";
import { assertEquals } from "./deps/std/assert.ts";
import { currentLibrary } from "./store.ts";
import { currentContext } from "./store.ts";

import { assertEquals } from "jsr:@std/assert@~1.0.3/equals";

test({
mode: "nvim", // can input mode test only in nvim
name: "registerKeyMap",
async fn(denops) {
async fn(denops: Denops) {
const lib = await currentLibrary.get();
lib.registerHenkanResult("okurinasi", "あ", "亜");
await denops.cmd('call skkeleton#register_keymap("henkan", "x", "")');
Expand Down
24 changes: 13 additions & 11 deletions denops/skkeleton/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { config, setConfig } from "./config.ts";
import { autocmd, Denops, Entrypoint, fn, vars } from "./deps.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";
Expand All @@ -13,6 +12,9 @@ import { currentContext, currentLibrary, variables } from "./store.ts";
import { globpath } from "./util.ts";
import type { CompletionData, RankData } from "./types.ts";

import { is } from "jsr:@core/unknownutil@~4.3.0/is";
import { assert, AssertError } from "jsr:@core/unknownutil@~4.3.0/assert";

type Opts = {
key: string | string[];
function?: string;
Expand Down Expand Up @@ -45,7 +47,7 @@ function isOpts(x: any): x is Opts {

function assertOpts(x: unknown): asserts x is Opts {
if (!isOpts(x)) {
throw new u.AssertError("value must be Opts");
throw new AssertError("value must be Opts");
}
}

Expand Down Expand Up @@ -257,18 +259,18 @@ export const main: Entrypoint = async (denops) => {
}
denops.dispatcher = {
async config(config: unknown) {
u.assert(config, is.Record);
assert(config, is.Record);
await setConfig(config, denops);
return;
},
async registerKeyMap(state: unknown, key: unknown, funcName: unknown) {
u.assert(state, is.String);
u.assert(key, is.String);
assert(state, is.String);
assert(key, is.String);
await receiveNotation(denops);
registerKeyMap(state, key, funcName);
},
registerKanaTable(tableName: unknown, table: unknown, create: unknown) {
u.assert(tableName, is.String);
assert(tableName, is.String);
registerKanaTable(tableName, table, !!create);
return Promise.resolve();
},
Expand Down Expand Up @@ -334,8 +336,8 @@ export const main: Entrypoint = async (denops) => {
await denops.dispatcher.completeCallback(kana, word);
},
async completeCallback(kana: unknown, word: unknown) {
u.assert(kana, is.String);
u.assert(word, is.String);
assert(kana, is.String);
assert(word, is.String);
const lib = await currentLibrary.get();
await lib.registerHenkanResult("okurinasi", kana, word);
const context = currentContext.get();
Expand All @@ -359,9 +361,9 @@ export const main: Entrypoint = async (denops) => {
await currentLibrary.get();
},
async updateDatabase(path: unknown, encoding: unknown, force: unknown) {
u.assert(path, is.String);
u.assert(encoding, is.String);
u.assert(force, is.Boolean);
assert(path, is.String);
assert(encoding, is.String);
assert(force, is.Boolean);
await DenoKvDictionary.create(path, encoding)
.then((dict) => dict.load(force));
await denops.cmd(`echomsg 'updated database: "${path}"'`);
Expand Down
Loading

0 comments on commit 843b02b

Please sign in to comment.