From ea791b95a02af646d19f88fda107cbb7b25120c0 Mon Sep 17 00:00:00 2001 From: kuuote Date: Tue, 5 Dec 2023 22:54:12 +0900 Subject: [PATCH] =?UTF-8?q?=E6=99=82=E4=BB=A3=E3=81=AFdenops?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .local.vimrc | 16 +++++++- denops/@vimrc/makestate.ts | 78 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 denops/@vimrc/makestate.ts diff --git a/.local.vimrc b/.local.vimrc index 53bdc968..5b06e219 100644 --- a/.local.vimrc +++ b/.local.vimrc @@ -1,5 +1,19 @@ +function s:wait() + while v:true + let stat = vimrc#denops#request('makestate', 'status', []) + if empty(stat) + return + endif + echo 'waiting ' .. stat->join(', ') + redraw + sleep 10m + call getchar(0) + endwhile +endfunction + augroup new_vimrc autocmd! * - autocmd BufWritePost call vimrc#dpp#makestate_job() autocmd BufWritePost call delete('/tmp/inline.vim', 'rf') + autocmd BufWritePost call vimrc#denops#notify('makestate', 'run', []) + autocmd VimLeavePre call s:wait() augroup END diff --git a/denops/@vimrc/makestate.ts b/denops/@vimrc/makestate.ts new file mode 100644 index 00000000..3e782fb1 --- /dev/null +++ b/denops/@vimrc/makestate.ts @@ -0,0 +1,78 @@ +import { + ensure, + is, +} from "/data/vim/repos/github.com/lambdalisue/deno-unknownutil/mod.ts"; +import { Denops } from "/data/vim/repos/github.com/vim-denops/deno-denops-std/denops_std/mod.ts"; +import { g } from "/data/vim/repos/github.com/vim-denops/deno-denops-std/denops_std/variable/mod.ts"; + +let vimProc: Deno.ChildProcess | undefined; +let nvimProc: Deno.ChildProcess | undefined; + +const vimrc = Deno.env.get("VIMDIR") + "/vimrc"; + +const isStringArray = is.ArrayOf(is.String); +async function glob(denops: Denops, path: string): Promise { + return ensure( + await denops.call("glob", path, 1, 1), + isStringArray, + ); +} + +export async function main(denops: Denops) { + denops.dispatcher = { + async run() { + vimProc?.kill("SIGKILL"); + nvimProc?.kill("SIGKILL"); + const base = String(await g.get(denops, "vimrc#dpp_base", "/tmp/dpp")); + const files = [ + ...await glob(denops, base + "/*/cache.vim"), + ...await glob(denops, base + "/*/state.vim"), + ]; + for (const f of files) { + await Deno.remove(f); + } + // await Deno.remove(base, { recursive: true }).catch(console.trace); + // 並列で実行すると多分denoのlockに引っ掛かる + vimProc = new Deno.Command("vim", { + args: ["-e", "-s", "-u", vimrc], + env: { + VIM: "", + VIMRUNTIME: "", + }, + stdin: "piped", + stdout: "piped", + stderr: "piped", + }).spawn(); + const vimStatus = await vimProc.status; + vimProc = void 0; + if (vimStatus.success) { + console.log("vim success"); + } + nvimProc = new Deno.Command("nvim", { + args: ["--headless", "-u", vimrc], + env: { + VIM: "", + VIMRUNTIME: "", + }, + stdin: "piped", + stdout: "piped", + stderr: "piped", + }).spawn(); + const nvimStatus = await nvimProc.status; + nvimProc = void 0; + if (nvimStatus.success) { + console.log("nvim success"); + } + }, + status() { + const stat = []; + if (vimProc != null) { + stat.push("vim"); + } + if (nvimProc != null) { + stat.push("nvim"); + } + return stat; + }, + }; +}