Skip to content

Commit

Permalink
Rename Jisyo
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Jan 11, 2024
1 parent 1bc7a93 commit 2013800
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 79 deletions.
14 changes: 5 additions & 9 deletions denops/skkeleton/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ export const config: ConfigOptions = {
databasePath: "",
debug: false,
eggLikeNewline: false,
globalDictionaries: [],
globalJisyo: "/usr/share/skk/SKK-JISYO.L",
globalJisyoEncoding: "euc-jp",
globalDictionaries: ["/usr/share/skk/SKK-JISYO.L"],
globalKanaTableFiles: [],
immediatelyCancel: true,
immediatelyJisyoRW: true,
immediatelyDictionaryRW: true,
immediatelyOkuriConvert: true,
kanaTable: "rom",
keepMode: false,
Expand All @@ -32,7 +30,7 @@ export const config: ConfigOptions = {
skkServerResEnc: "euc-jp",
sources: ["skk_dictionary"],
usePopup: true,
userJisyo: "~/.skkeleton",
userDictionary: "~/.skkeleton",
};

type Validators = {
Expand Down Expand Up @@ -62,8 +60,6 @@ const validators: Validators = {
}
return x;
},
globalJisyo: (x) => ensure(x, is.String),
globalJisyoEncoding: ensureEncoding,
globalKanaTableFiles: (x): (string | [string, string])[] => {
if (
!is.ArrayOf(
Expand All @@ -77,7 +73,7 @@ const validators: Validators = {
return x;
},
immediatelyCancel: (x) => ensure(x, is.Boolean),
immediatelyJisyoRW: (x) => ensure(x, is.Boolean),
immediatelyDictionaryRW: (x) => ensure(x, is.Boolean),
immediatelyOkuriConvert: (x) => ensure(x, is.Boolean),
kanaTable: (x): string => {
const name = ensure(x, is.String);
Expand Down Expand Up @@ -114,7 +110,7 @@ const validators: Validators = {
useSkkServer: () => {
throw '`useSkkServer` is removed. Please use `sources` with "skk_server"';
},
userJisyo: (x) => ensure(x, is.String),
userDictionary: (x) => ensure(x, is.String),
};

export async function setConfig(
Expand Down
2 changes: 1 addition & 1 deletion denops/skkeleton/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from "./config.ts";
import type { Denops } from "./deps.ts";
import { HenkanType } from "./jisyo.ts";
import { HenkanType } from "./dictionary.ts";
import { PreEdit } from "./preedit.ts";
import { initializeState, State, toString } from "./state.ts";

Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions denops/skkeleton/jisyo.ts → denops/skkeleton/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ 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 { SkkDictionary } from "./jisyo/skk_dictionary.ts";
import { DenoKvDictionary } from "./jisyo/deno_kv.ts";
import { UserDictionary, UserDictionaryPath } from "./jisyo/user_dictionary.ts";
import { SkkServer } from "./jisyo/skk_server.ts";
import { GoogleJapaneseInput } from "./jisyo/google_japanese_input.ts";
import { SkkDictionary } from "./sources/skk_dictionary.ts";
import { DenoKvDictionary } from "./sources/deno_kv.ts";
import { UserDictionary, UserDictionaryPath } from "./sources/user_dictionary.ts";
import { SkkServer } from "./sources/skk_server.ts";
import { GoogleJapaneseInput } from "./sources/google_japanese_input.ts";

export const okuriAriMarker = ";; okuri-ari entries.";
export const okuriNasiMarker = ";; okuri-nasi entries.";
Expand Down Expand Up @@ -184,7 +184,7 @@ export class Library {
}

async getHenkanResult(type: HenkanType, word: string): Promise<string[]> {
if (config.immediatelyJisyoRW) {
if (config.immediatelyDictionaryRW) {
await this.load();
}
const merged = new Set<string>();
Expand All @@ -200,7 +200,7 @@ export class Library {
prefix: string,
feed: string,
): Promise<CompletionData> {
if (config.immediatelyJisyoRW) {
if (config.immediatelyDictionaryRW) {
await this.load();
}
const collector = new Map<string, Set<string>>();
Expand Down Expand Up @@ -235,14 +235,14 @@ export class Library {
candidate: string,
) {
this.#userDictionary.registerHenkanResult(type, word, candidate);
if (config.immediatelyJisyoRW) {
if (config.immediatelyDictionaryRW) {
await this.#userDictionary.save();
}
}

async purgeCandidate(type: HenkanType, word: string, candidate: string) {
this.#userDictionary.purgeCandidate(type, word, candidate);
if (config.immediatelyJisyoRW) {
if (config.immediatelyDictionaryRW) {
await this.#userDictionary.save();
}
}
Expand Down Expand Up @@ -340,7 +340,7 @@ export async function load(
} else if (source === "google_japanese_input") {
dictionaries.push(new GoogleJapaneseInput());
} else {
console.error(`Invalid jisyo name: ${source}`);
console.error(`Invalid source name: ${source}`);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {
Library,
load as loadJisyo,
wrapDictionary,
} from "./jisyo.ts";
import { SkkDictionary } from "./jisyo/skk_dictionary.ts";
import { DenoKvDictionary } from "./jisyo/deno_kv.ts";
import { UserDictionary } from "./jisyo/user_dictionary.ts";
} from "./dictionary.ts";
import { SkkDictionary } from "./sources/skk_dictionary.ts";
import { DenoKvDictionary } from "./sources/deno_kv.ts";
import { UserDictionary } from "./sources/user_dictionary.ts";

const newJisyoJson = join(
dirname(fromFileUrl(import.meta.url)),
Expand Down
2 changes: 1 addition & 1 deletion denops/skkeleton/function/common.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from "../config.ts";
import { Context } from "../context.ts";
import { HenkanType } from "../jisyo.ts";
import { HenkanType } from "../dictionary.ts";
import { initializeStateWithAbbrev } from "../mode.ts";
import { initializeState } from "../state.ts";
import { currentLibrary } from "../store.ts";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { modeChange } from "../mode.ts";

const cmapKeys = ["<Esc>", "<C-g>"];

export async function jisyoTouroku(context: Context): Promise<boolean> {
export async function registerWord(context: Context): Promise<boolean> {
const denops = context.denops!;
const state = context.state as HenkanState;
await batch(denops, async (denops) => {
Expand Down Expand Up @@ -41,7 +41,7 @@ export async function jisyoTouroku(context: Context): Promise<boolean> {
return true;
} catch (e) {
if (config.debug) {
console.log("jisyo touroku interrupted");
console.log("registerWord interrupted");
console.log(e);
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { currentKanaTable, getKanaTable } from "../kana.ts";
import { HenkanState } from "../state.ts";
import { currentContext } from "../store.ts";
import { test } from "../testutil.ts";
import { jisyoTouroku } from "./jisyo.ts";
import { registerWord } from "./dictionary.ts";

test({
mode: "all",
Expand All @@ -29,7 +29,7 @@ test({
await denops.cmd(
'autocmd CmdlineEnter * ++once call feedkeys("\\<Esc>", "n")',
);
await jisyoTouroku(context);
await registerWord(context);

assertEquals(context.preEdit.output(""), "");
},
Expand Down
6 changes: 3 additions & 3 deletions denops/skkeleton/function/henkan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getOkuriStr } from "../okuri.ts";
import { HenkanState, initializeState } from "../state.ts";
import { kakutei } from "./common.ts";
import { kakuteiFeed } from "./input.ts";
import { jisyoTouroku } from "./jisyo.ts";
import { registerWord } from "./dictionary.ts";

export async function henkanFirst(context: Context, key: string) {
if (context.state.type !== "input") {
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function henkanForward(context: Context) {
state.candidateIndex++;
}
if (state.candidates.length <= state.candidateIndex) {
if (await jisyoTouroku(context)) {
if (await registerWord(context)) {
return;
}
state.candidateIndex = oldCandidateIndex;
Expand Down Expand Up @@ -100,7 +100,7 @@ async function selectCandidates(context: Context) {
while (index >= 0) {
const start = count + index * keys.length;
if (start >= state.candidates.length) {
if (await jisyoTouroku(context)) {
if (await registerWord(context)) {
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions denops/skkeleton/function/input_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ Deno.test({
},
});

config.globalJisyo = "";
config.userJisyo = "";
config.globalDictionaries = [];
config.userDictionary = "";

test({
mode: "nvim",
Expand Down
14 changes: 6 additions & 8 deletions denops/skkeleton/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { autocmd, Denops, fn, op, vars } from "./deps.ts";
import { assert, AssertError, is } from "./deps/unknownutil.ts";
import { functions, modeFunctions } from "./function.ts";
import { disable as disableFunc } from "./function/disable.ts";
import { load as jisyoLoad } from "./jisyo.ts";
import { DenoKvDictionary } from "./jisyo/deno_kv.ts";
import { load as loadDictionary } from "./dictionary.ts";
import { DenoKvDictionary } from "./sources/deno_kv.ts";
import { currentKanaTable, registerKanaTable } from "./kana.ts";
import { handleKey, registerKeyMap } from "./keymap.ts";
import { initializeStateWithAbbrev } from "./mode.ts";
Expand Down Expand Up @@ -67,12 +67,10 @@ async function init(denops: Denops) {
currentContext.get().denops = denops;
const {
completionRankFile,
userJisyo,
userDictionary,
} = config;
const globalDictionaries = await Promise.all(
(config.globalDictionaries.length === 0
? [[config.globalJisyo, config.globalJisyoEncoding]]
: config.globalDictionaries)
(config.globalDictionaries.length === 0 ? [] : config.globalDictionaries)
.map(async (
cfg,
): Promise<[string, string]> => {
Expand All @@ -84,10 +82,10 @@ async function init(denops: Denops) {
}),
);
currentLibrary.setInitializer(async () =>
await jisyoLoad(
await loadDictionary(
globalDictionaries,
{
path: await homeExpand(userJisyo, denops),
path: await homeExpand(userDictionary, denops),
rankPath: await homeExpand(completionRankFile, denops),
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
HenkanType,
okuriAriMarker,
okuriNasiMarker,
} from "../jisyo.ts";
import { jisyoschema, jsonschema, msgpack, yaml } from "../deps/jisyo.ts";
} from "../dictionary.ts";
import { jisyoschema, jsonschema, msgpack, yaml } from "../deps/dictionary.ts";

interface Jisyo {
okuri_ari: Record<string, string[]>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { config } from "../config.ts";
import { Dictionary, HenkanType } from "../jisyo.ts";
import { Dictionary, HenkanType } from "../dictionary.ts";
import type { CompletionData } from "../types.ts";
import { deadline, DeadlineError } from "../deps/std/async.ts";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
HenkanType,
okuriAriMarker,
okuriNasiMarker,
} from "../jisyo.ts";
import { jisyoschema, jsonschema, msgpack, yaml } from "../deps/jisyo.ts";
} from "../dictionary.ts";
import { jisyoschema, jsonschema, msgpack, yaml } from "../deps/dictionary.ts";

interface Jisyo {
okuri_ari: Record<string, string[]>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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, HenkanType } from "../jisyo.ts";
import { Dictionary, HenkanType } from "../dictionary.ts";
import type { CompletionData, Encoding, SkkServerOptions } from "../types.ts";

type Server = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
HenkanType,
okuriAriMarker,
okuriNasiMarker,
} from "../jisyo.ts";
} from "../dictionary.ts";
import { wrap } from "../deps/iterator_helpers.ts";
import { assert, is } from "../deps/unknownutil.ts";

Expand Down Expand Up @@ -183,7 +183,7 @@ export class UserDictionary implements Dictionary {
await Deno.writeTextFile(path, data);
} catch (e) {
console.log(
`warning(skkeleton): can't write userJisyo to ${path}`,
`warning(skkeleton): can't write userDictionary to ${path}`,
);
throw e;
}
Expand Down
2 changes: 1 addition & 1 deletion denops/skkeleton/state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { config } from "./config.ts";
import type { HenkanType } from "./jisyo.ts";
import type { HenkanType } from "./dictionary.ts";
import { getKanaTable } from "./kana.ts";
import { KanaTable } from "./kana/type.ts";
import { Cell } from "./util.ts";
Expand Down
2 changes: 1 addition & 1 deletion denops/skkeleton/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context } from "./context.ts";
import { Library } from "./jisyo.ts";
import { Library } from "./dictionary.ts";
import { Cell, LazyCell } from "./util.ts";

export const currentContext = new Cell(() => new Context());
Expand Down
6 changes: 2 additions & 4 deletions denops/skkeleton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ export type ConfigOptions = {
debug: boolean;
eggLikeNewline: boolean;
globalDictionaries: (string | [string, string])[];
globalJisyo: string;
globalJisyoEncoding: Encoding;
globalKanaTableFiles: (string | [string, string])[];
immediatelyCancel: boolean;
immediatelyJisyoRW: boolean;
immediatelyDictionaryRW: boolean;
immediatelyOkuriConvert: boolean;
kanaTable: string;
keepMode: boolean;
Expand All @@ -67,5 +65,5 @@ export type ConfigOptions = {
useGoogleJapaneseInput?: never;
usePopup: boolean;
useSkkServer?: never;
userJisyo: string;
userDictionary: string;
};
Loading

0 comments on commit 2013800

Please sign in to comment.