From f9ba3e38e5a6c7b2bbe5e122de80483607435380 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sat, 23 Mar 2024 13:35:16 +0900 Subject: [PATCH] Generate startup.vim --- autoload/dpp/min.vim | 14 ++++++------- autoload/dpp/util.vim | 8 ++++---- denops/@ddu-sources/dpp.ts | 4 ++-- denops/dpp/deps.ts | 22 ++++++++++---------- denops/dpp/dpp.ts | 41 +++++++++++++++++++------------------- 5 files changed, 45 insertions(+), 44 deletions(-) diff --git a/autoload/dpp/min.vim b/autoload/dpp/min.vim index 81a2970..ecdf5c6 100644 --- a/autoload/dpp/min.vim +++ b/autoload/dpp/min.vim @@ -5,14 +5,14 @@ function dpp#min#load_state(path, name=v:progname->fnamemodify(':r')) abort if g:dpp#_is_sudo | return 1 | endif let g:dpp#_base_path = a:path->expand() let g:dpp#_name = a:name + const startup = printf('%s/%s/startup.vim', g:dpp#_base_path, a:name) const state = printf('%s/%s/state.vim', g:dpp#_base_path, a:name) - const cache = printf('%s/%s/cache.vim', g:dpp#_base_path, a:name) - if !cache->filereadable() || !state->filereadable() | return 1 | endif + if !startup->filereadable() || !state->filereadable() | return 1 | endif try - let g:dpp#_cache = has('nvim') ? cache->readfile()->json_decode() - \ : cache->readfile()[0]->js_decode() - execute 'source' state->fnameescape() - unlet g:dpp#_cache + let g:dpp#_state = has('nvim') ? state->readfile()->json_decode() + \ : state->readfile()[0]->js_decode() + execute 'source' startup->fnameescape() + unlet g:dpp#_state catch call dpp#util#_error('Loading state error: ' .. v:exception) call dpp#util#_clear_state(a:name) @@ -20,7 +20,7 @@ function dpp#min#load_state(path, name=v:progname->fnamemodify(':r')) abort endtry endfunction function dpp#min#_init() abort - const g:dpp#_cache_version = 1 + const g:dpp#_state_version = 1 const g:dpp#_is_sudo = $SUDO_USER !=# '' && $USER !=# $SUDO_USER \ && $HOME !=# ('~'.$USER)->expand() \ && $HOME ==# ('~'.$SUDO_USER)->expand() diff --git a/autoload/dpp/util.vim b/autoload/dpp/util.vim index 56a735f..d120b0a 100644 --- a/autoload/dpp/util.vim +++ b/autoload/dpp/util.vim @@ -149,14 +149,14 @@ function s:tsort_impl(target, mark, sorted) abort endfunction function dpp#util#_clear_state(name) abort + const startup = printf('%s/%s/startup.vim', g:dpp#_base_path, a:name) + if startup->filereadable() + call delete(startup) + endif const state = printf('%s/%s/state.vim', g:dpp#_base_path, a:name) if state->filereadable() call delete(state) endif - const cache = printf('%s/%s/cache.vim', g:dpp#_base_path, a:name) - if cache->filereadable() - call delete(cache) - endif endfunction function dpp#util#_get_normalized_name(plugin) abort diff --git a/denops/@ddu-sources/dpp.ts b/denops/@ddu-sources/dpp.ts index 6ec895f..5524ab6 100644 --- a/denops/@ddu-sources/dpp.ts +++ b/denops/@ddu-sources/dpp.ts @@ -3,8 +3,8 @@ import { ActionFlags, BaseSource, Item, -} from "https://deno.land/x/ddu_vim@v3.10.2/types.ts"; -import { Denops, vars } from "https://deno.land/x/ddu_vim@v3.10.2/deps.ts"; +} from "https://deno.land/x/ddu_vim@v3.10.3/types.ts"; +import { Denops, vars } from "https://deno.land/x/ddu_vim@v3.10.3/deps.ts"; import { ActionData } from "https://deno.land/x/ddu_kind_file@v0.7.1/file.ts"; import { Plugin } from "../dpp/types.ts"; diff --git a/denops/dpp/deps.ts b/denops/dpp/deps.ts index f32129d..8eb5953 100644 --- a/denops/dpp/deps.ts +++ b/denops/dpp/deps.ts @@ -1,22 +1,22 @@ -export type { Denops } from "https://deno.land/x/denops_std@v6.2.0/mod.ts"; +export type { Denops } from "https://deno.land/x/denops_std@v6.4.0/mod.ts"; export { echo, execute, -} from "https://deno.land/x/denops_std@v6.2.0/helper/mod.ts"; +} from "https://deno.land/x/denops_std@v6.4.0/helper/mod.ts"; export { batch, collect, -} from "https://deno.land/x/denops_std@v6.2.0/batch/mod.ts"; -export * as op from "https://deno.land/x/denops_std@v6.2.0/option/mod.ts"; -export * as fn from "https://deno.land/x/denops_std@v6.2.0/function/mod.ts"; -export * as vars from "https://deno.land/x/denops_std@v6.2.0/variable/mod.ts"; -export * as autocmd from "https://deno.land/x/denops_std@v6.2.0/autocmd/mod.ts"; -export { ensure, is } from "https://deno.land/x/unknownutil@v3.16.3/mod.ts"; +} from "https://deno.land/x/denops_std@v6.4.0/batch/mod.ts"; +export * as op from "https://deno.land/x/denops_std@v6.4.0/option/mod.ts"; +export * as fn from "https://deno.land/x/denops_std@v6.4.0/function/mod.ts"; +export * as vars from "https://deno.land/x/denops_std@v6.4.0/variable/mod.ts"; +export * as autocmd from "https://deno.land/x/denops_std@v6.4.0/autocmd/mod.ts"; +export { ensure, is } from "https://deno.land/x/unknownutil@v3.17.0/mod.ts"; export { assertEquals, assertInstanceOf, equal, -} from "https://deno.land/std@0.218.0/assert/mod.ts"; +} from "https://deno.land/std@0.220.1/assert/mod.ts"; export { basename, dirname, @@ -25,10 +25,10 @@ export { parse, SEPARATOR as pathsep, toFileUrl, -} from "https://deno.land/std@0.218.0/path/mod.ts"; +} from "https://deno.land/std@0.220.1/path/mod.ts"; export { deadline, DeadlineError, -} from "https://deno.land/std@0.218.0/async/mod.ts"; +} from "https://deno.land/std@0.220.1/async/mod.ts"; export { TimeoutError } from "https://deno.land/x/msgpack_rpc@v4.0.1/response_waiter.ts"; export { Lock } from "https://deno.land/x/async@v2.1.0/mod.ts"; diff --git a/denops/dpp/dpp.ts b/denops/dpp/dpp.ts index 890480b..b048962 100644 --- a/denops/dpp/dpp.ts +++ b/denops/dpp/dpp.ts @@ -280,11 +280,11 @@ export class Dpp { dppRuntimepath, ); - const cacheVersion = await vars.g.get(denops, "dpp#_cache_version"); - let stateLines = [ - `if g:dpp#_cache_version !=# ${cacheVersion}` + - `| throw "Cache version error" | endif`, - "let [g:dpp#_plugins, g:dpp#ftplugin, g:dpp#_options, g:dpp#_check_files] = g:dpp#_cache", + const stateVersion = await vars.g.get(denops, "dpp#_state_version"); + let startupLines = [ + `if g:dpp#_state_version !=# ${stateVersion}` + + `| throw "State version error" | endif`, + "let [g:dpp#_plugins, g:dpp#ftplugin, g:dpp#_options, g:dpp#_check_files] = g:dpp#_state", `let g:dpp#_config_path = '${configPath}'`, `let &runtimepath = '${newRuntimepath}'`, ]; @@ -323,13 +323,13 @@ export class Dpp { } if (await vars.g.get(denops, "dpp#_did_load_filetypes", false)) { - stateLines.push("filetype off"); + startupLines.push("filetype off"); } if (await vars.g.get(denops, "dpp#_did_load_ftplugin", false)) { - stateLines.push("filetype plugin indent off"); + startupLines.push("filetype plugin indent off"); } if (configReturn.stateLines) { - stateLines = stateLines.concat(configReturn.stateLines); + startupLines = startupLines.concat(configReturn.stateLines); } // NOTE: inlineVimrcs must be before plugins hook_add. @@ -340,14 +340,14 @@ export class Dpp { const vimrcLines = (await Deno.readTextFile(vimrc)).split(/\r?\n/); if (extname(vimrc) == ".lua") { if (hasLua) { - stateLines = stateLines.concat( + startupLines = startupLines.concat( ["lua < !line.match(/^\s*$|^\s*--/)), ["EOF"], ); } } else { - stateLines = stateLines.concat( + startupLines = startupLines.concat( vimrcLines.filter((line) => !line.match(/^\s*$|^\s*"/)), ); } @@ -365,7 +365,7 @@ export class Dpp { } if (plugin.hook_add) { - stateLines.push(plugin.hook_add); + startupLines.push(plugin.hook_add); } if (plugin.ftplugin) { @@ -373,15 +373,16 @@ export class Dpp { } } - // Write state file - const stateFile = `${basePath}/${name}/state.vim`; - await Deno.writeTextFile(stateFile, stateLines.join("\n")); + // Write startup script + const startupFile = `${basePath}/${name}/startup.vim`; + await Deno.writeTextFile(startupFile, startupLines.join("\n")); if (hasWindows) { - await denops.call("dpp#util#_dos2unix", stateFile); + await denops.call("dpp#util#_dos2unix", startupFile); } - const cacheFile = `${basePath}/${name}/cache.vim`; - const cacheLines = [ + // Write state file + const stateFile = `${basePath}/${name}/state.vim`; + const stateLines = [ JSON.stringify([ recordPlugins, {}, @@ -389,13 +390,13 @@ export class Dpp { checkFiles, ]), ]; - await Deno.writeTextFile(cacheFile, cacheLines.join("\n")); + await Deno.writeTextFile(stateFile, stateLines.join("\n")); if (hasWindows) { - await denops.call("dpp#util#_dos2unix", cacheFile); + await denops.call("dpp#util#_dos2unix", stateFile); } + //console.log(startupLines); //console.log(stateLines); - //console.log(cacheLines); await this.#mergePlugins(denops, dppRuntimepath, recordPlugins);