Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deps #203

Merged
merged 11 commits into from
Sep 10, 2024
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
2 changes: 1 addition & 1 deletion 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 yaml from "jsr:@std/[email protected].5";
export * as msgpack from "https://esm.sh/@msgpack/[email protected]";
Shougo marked this conversation as resolved.
Show resolved Hide resolved
export { default as jsonschema } from "https://esm.sh/[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" };
Shougo marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion denops/skkeleton/deps/std/assert.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "jsr:@std/assert@~1.0.3";
export { assertEquals } from "jsr:@std/assert@~1.0.3/equals";
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.

5 changes: 3 additions & 2 deletions denops/skkeleton/dictionary.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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 { 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
5 changes: 4 additions & 1 deletion 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 { 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
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
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
8 changes: 5 additions & 3 deletions denops/skkeleton/notation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { Denops } from "./deps.ts";
import { is, u } from "./deps/unknownutil.ts";

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

let received = false;
export let notationToKey: Record<string, string> = {};
Expand All @@ -10,10 +12,10 @@ export async function receiveNotation(denops: Denops) {
return;
}
const n2k = await denops.eval("g:skkeleton#notation#notation_to_key");
u.assert(n2k, is.RecordOf(is.String));
assert(n2k, is.RecordOf(is.String));
notationToKey = n2k;
const k2n = await denops.eval("g:skkeleton#notation#key_to_notation");
u.assert(k2n, is.RecordOf(is.String));
assert(k2n, is.RecordOf(is.String));
keyToNotation = k2n;
received = true;
}
3 changes: 2 additions & 1 deletion denops/skkeleton/sources/google_japanese_input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
Source as BaseSource,
} from "../dictionary.ts";
import type { CompletionData } from "../types.ts";
import { deadline } from "../deps/std/async.ts";

import { deadline } from "jsr:@std/async@~1.0.4/deadline";

export class Source implements BaseSource {
getDictionaries(): Promise<BaseDictionary[]> {
Expand Down
3 changes: 2 additions & 1 deletion denops/skkeleton/sources/skk_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { config } from "../config.ts";
import { encoding } from "../deps/encoding_japanese.ts";
import { Encode } from "../types.ts";
import { getKanaTable } from "../kana.ts";
import { TextLineStream } from "../deps/std/streams.ts";
import {
Dictionary as BaseDictionary,
HenkanType,
Source as BaseSource,
} from "../dictionary.ts";
import type { CompletionData, Encoding, SkkServerOptions } from "../types.ts";

import { TextLineStream } from "jsr:@std/streams@~1.0.3/text-line-stream";

type Server = {
conn: Deno.Conn;
readCallback: (result: string) => void;
Expand Down
6 changes: 4 additions & 2 deletions denops/skkeleton/sources/user_dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {
UserDictionaryPath,
} from "../dictionary.ts";
import { wrap } from "../deps/iterator_helpers.ts";
import { is, u } from "../deps/unknownutil.ts";

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

export class Source implements BaseSource {
async getDictionaries(): Promise<BaseDictionary[]> {
Expand Down Expand Up @@ -166,7 +168,7 @@ export class Dictionary implements UserDictionary {
return;
}
const rankData = JSON.parse(await Deno.readTextFile(rankPath));
u.assert(rankData, is.ArrayOf(is.String));
assert(rankData, is.ArrayOf(is.String));
this.#rank = new Map(rankData.map((c, i) => [c, i]));
}

Expand Down
8 changes: 5 additions & 3 deletions denops/skkeleton/testutil.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { autocmd, Denops } from "./deps.ts";
import * as DenopsTest from "./deps/denops_test.ts";
import * as path from "./deps/std/path.ts";
import { main } from "./main.ts";
import { currentContext } from "./store.ts";

const runtimepath = path.resolve(
path.fromFileUrl(new URL("../..", import.meta.url)),
import { fromFileUrl } from "jsr:@std/path@~1.0.3/from-file-url";
import { resolve } from "jsr:@std/path@~1.0.3/resolve";

const runtimepath = resolve(
fromFileUrl(new URL("../..", import.meta.url)),
);

// It is inspired from https://github.com/lambdalisue/gin.vim/blob/e737a4b59a9d391c49aaa07f7c4d91e4a29ae09c/denops/gin/util/testutil.ts
Expand Down
4 changes: 3 additions & 1 deletion denops/skkeleton/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Denops, fn, op } from "./deps.ts";
import { basename, parse } from "./deps/std/path.ts";
import { encoding } from "./deps/encoding_japanese.ts";

import { basename } from "jsr:@std/path@~1.0.3/basename";
import { parse } from "jsr:@std/path@~1.0.3/parse";

export class Cell<T> {
initialized = false;
initializer: () => T;
Expand Down
Loading