Skip to content

Commit

Permalink
Add skkeleton#update_database()
Browse files Browse the repository at this point in the history
  • Loading branch information
uga-rosa committed Dec 27, 2023
1 parent 151612a commit 97de534
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions autoload/skkeleton.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 5 additions & 2 deletions denops/skkeleton/jisyo/deno_kv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions denops/skkeleton/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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"`);
Expand Down
11 changes: 11 additions & 0 deletions doc/skkeleton.jax
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ g:skkeleton#state *g:skkeleton#state*
"henkan" 変換
"escape" escapeした際

*skkeleton#update_database()*
skkeleton#update_database({path} [, {encoding} [, {force}]])

データベースを手動で更新します。
- {path} 辞書のパス
- {encoding} 辞書のエンコード。省略するか空文字列だと自動で判別します
- {force} 辞書に更新がなくても強制的にデータベースを更新します

------------------------------------------------------------------------------
CONFIG *skkeleton-config*

Expand Down Expand Up @@ -350,6 +358,9 @@ databasePath *skkeleton-config-databasePath*
ます。データベースの構築には通常の読み込みよりも時間がかかりますが、デ
ータベースはローカルなファイルに保存されるため、次回以降の起動は高速に
なります。
データベースの構築は skkeleton の起動時に自動で行われます。mtimeが以前
と変更された辞書のデータベースは更新します。手動で行うには
|skkeleton#update_database()| を使ってください。

------------------------------------------------------------------------------
*skkeleton#register_kanatable()*
Expand Down

0 comments on commit 97de534

Please sign in to comment.