Skip to content

Commit

Permalink
Merge pull request #182 from vim-skk/loadDictionary
Browse files Browse the repository at this point in the history
Fix loadDictionary() initializer
  • Loading branch information
kuuote authored Jan 13, 2024
2 parents 4183657 + f6aa766 commit aab00fd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
19 changes: 8 additions & 11 deletions denops/skkeleton/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { zip } from "./deps/std/collections.ts";
import type { CompletionData, RankData } from "./types.ts";
import { SkkDictionary } from "./sources/skk_dictionary.ts";
import { DenoKvDictionary } from "./sources/deno_kv.ts";
import {
UserDictionary,
UserDictionaryPath,
} from "./sources/user_dictionary.ts";
import { UserDictionary } from "./sources/user_dictionary.ts";
import { SkkServer } from "./sources/skk_server.ts";
import { GoogleJapaneseInput } from "./sources/google_japanese_input.ts";

Expand Down Expand Up @@ -259,13 +256,13 @@ export class Library {
}
}

export async function load(
globalDictionaryConfig: [string, string][],
userDictionaryPath: UserDictionaryPath,
): Promise<Library> {
export async function load(): Promise<Library> {
const userDictionary = new UserDictionary();
try {
await userDictionary.load(userDictionaryPath);
await userDictionary.load({
path: config.userDictionary,
rankPath: config.completionRankFile,
});
} catch (e) {
if (config.debug) {
console.log("userDictionary loading failed");
Expand All @@ -278,7 +275,7 @@ export async function load(
for (const source of config.sources) {
if (source === "skk_dictionary") {
const globalDictionaries = await Promise.all(
globalDictionaryConfig.map(async ([path, encodingName]) => {
config.globalDictionaries.map(async ([path, encodingName]) => {
try {
const dict = new SkkDictionary();
await dict.load(path, encodingName);
Expand All @@ -301,7 +298,7 @@ export async function load(
}
} else if (source === "deno_kv") {
const globalDictionaries = await Promise.all(
globalDictionaryConfig.map(async ([path, encodingName]) => {
config.globalDictionaries.map(async ([path, encodingName]) => {
try {
const dict = await DenoKvDictionary.create(path, encodingName);
await dict.load();
Expand Down
8 changes: 5 additions & 3 deletions denops/skkeleton/dictionary_test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { config } from "./config.ts";
import { dirname, fromFileUrl, join } from "./deps/std/path.ts";
import { assertEquals } from "./deps/std/assert.ts";
import {
Dictionary,
Library,
load as loadJisyo,
load as loadDictionary,
wrapDictionary,
} from "./dictionary.ts";
import { SkkDictionary } from "./sources/skk_dictionary.ts";
Expand Down Expand Up @@ -282,10 +283,11 @@ Deno.test({
Deno.test({
name: "multi dictionary",
async fn() {
const lib = await loadJisyo([
config.globalDictionaries = [
[globalJisyo, "euc-jp"],
[globalJisyo2, "utf-8"],
], {});
];
const lib = await loadDictionary();
assertEquals(await lib.getHenkanResult("okurinasi", "てすと"), [
"テスト",
"test",
Expand Down
10 changes: 1 addition & 9 deletions denops/skkeleton/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,7 @@ async function init(denops: Denops) {
console.log(e);
}
currentContext.get().denops = denops;
currentLibrary.setInitializer(async () =>
await loadDictionary(
config.globalDictionaries,
{
path: config.userDictionary,
rankPath: config.completionRankFile,
},
)
);
currentLibrary.setInitializer(loadDictionary);
await receiveNotation(denops);
autocmd.group(denops, "skkeleton-internal-denops", (helper) => {
helper.remove("*");
Expand Down

0 comments on commit aab00fd

Please sign in to comment.