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

Fix loadDictionary() initializer #182

Merged
merged 4 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(async () => await loadDictionary());
Shougo marked this conversation as resolved.
Show resolved Hide resolved
await receiveNotation(denops);
autocmd.group(denops, "skkeleton-internal-denops", (helper) => {
helper.remove("*");
Expand Down