diff --git a/autoload/skkeleton.vim b/autoload/skkeleton.vim index 2d469cca..767f352f 100644 --- a/autoload/skkeleton.vim +++ b/autoload/skkeleton.vim @@ -328,3 +328,9 @@ endfunction function! skkeleton#initialize() abort call skkeleton#notify_async('initialize', []) endfunction + +function! skkeleton#update_database(path, ...) abort + let encoding = a:0 > 0 ? a:1 : '' + let force = a:0 > 1 ? a:2 : v:false + call skkeleton#notify_async('updateDatabase', [a:path, encoding, force]) +endfunction diff --git a/denops/skkeleton/jisyo/deno_kv.ts b/denops/skkeleton/jisyo/deno_kv.ts index 45402bbc..ca939561 100644 --- a/denops/skkeleton/jisyo/deno_kv.ts +++ b/denops/skkeleton/jisyo/deno_kv.ts @@ -85,10 +85,13 @@ export class DenoKvDictionary implements Dictionary { return Promise.resolve(candidates); } - async load() { + async load(force = false) { const stat = await Deno.stat(this.#path); const mtime = stat.mtime?.getTime(); - if (mtime && (await this.#db.get([this.#path, "mtime"])).value === mtime) { + if ( + !force && mtime && + (await this.#db.get([this.#path, "mtime"])).value === mtime + ) { return this; } diff --git a/denops/skkeleton/main.ts b/denops/skkeleton/main.ts index 67799718..af69e292 100644 --- a/denops/skkeleton/main.ts +++ b/denops/skkeleton/main.ts @@ -5,6 +5,7 @@ import { functions, modeFunctions } from "./function.ts"; import { disable as disableFunc } from "./function/disable.ts"; import { load as jisyoLoad } from "./jisyo.ts"; import { SkkServer } from "./jisyo/skk_server.ts"; +import { DenoKvDictionary } from "./jisyo/deno_kv.ts"; import { GoogleJapaneseInput } from "./jisyo/google_japanese_input.ts"; import { currentKanaTable, registerKanaTable } from "./kana.ts"; import { handleKey, registerKeyMap } from "./keymap.ts"; @@ -393,6 +394,14 @@ export async function main(denops: Denops) { // NOTE: Initialize dictionary await currentLibrary.get(); }, + async updateDatabase(path: unknown, encoding: unknown, force: unknown) { + 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}"'`); + }, }; if (config.debug) { await denops.cmd(`echomsg "loaded skkeleton"`);