diff --git a/autoload/dpp.vim b/autoload/dpp.vim index 4183e8a..8f90eea 100644 --- a/autoload/dpp.vim +++ b/autoload/dpp.vim @@ -1,14 +1,12 @@ -function dpp#load_state(path) abort +function dpp#load_state(base_path) abort + if !('#dpp'->exists()) + call dpp#min#_init() + endif endfunction function dpp#begin(path, options = {}) abort - if !has('patch-9.0.1276') && !has('nvim-0.10') - call dpp#util#_error('dpp.vim requires Vim 9.0.1276+ or NeoVim 0.10+.') - return 1 - endif - if !('#dpp'->exists()) - call dpp#_init() + call dpp#min#_init() endif let g:dpp#_options = extend(g:dpp#_options, a:options) @@ -119,12 +117,6 @@ function dpp#end() abort if !(depends->empty()) call dpp#source(depends) endif - - if !has('vim_starting') - call dpp#call_hook('add') - call dpp#call_hook('source') - call dpp#call_hook('post_source') - endif endfunction function dpp#get(name = '') abort @@ -137,29 +129,24 @@ function dpp#source(plugins = g:dpp#_plugins->values()) abort endfunction function dpp#make_state(base_path, config_path) abort + if !has('patch-9.0.1276') && !has('nvim-0.10') + call dpp#util#_error('dpp.vim requires Vim 9.0.1276+ or NeoVim 0.10+.') + return 1 + endif + if !(a:config_path->filereadable()) call dpp#util#print_error(printf('"%s" is not found.', a:config_path)) - return + return 1 endif - return dpp#denops#_notify('makeState', [a:base_path, a:config_path]) -endfunction - -function dpp#is_sudo() abort - return $SUDO_USER !=# '' && $USER !=# $SUDO_USER - \ && $HOME !=# ('~'.$USER)->expand() - \ && $HOME ==# ('~'.$SUDO_USER)->expand() -endfunction - -function dpp#_init() abort - let g:dpp#_plugins = {} - let g:dpp#_options = {} + if !('#dpp'->exists()) + call dpp#min#_init() + endif - const g:dpp#_progname = has('nvim') && exists('$NVIM_APPNAME') ? - \ $NVIM_APPNAME : v:progname->fnamemodify(':r') - const g:dpp#_init_runtimepath = &runtimepath + " Check sudo + if g:dpp#_is_sudo + return + endif - augroup dpp - autocmd! - augroup END + return dpp#denops#_notify('makeState', [a:base_path, a:config_path]) endfunction diff --git a/autoload/dpp/min.vim b/autoload/dpp/min.vim new file mode 100644 index 0000000..d9cbf57 --- /dev/null +++ b/autoload/dpp/min.vim @@ -0,0 +1,16 @@ +function dpp#min#_init() abort + let g:dpp#_cache_version = 1 + let g:dpp#_plugins = {} + let g:dpp#_options = {} + let g:dpp#_is_sudo = $SUDO_USER !=# '' && $USER !=# $SUDO_USER + \ && $HOME !=# ('~'.$USER)->expand() + \ && $HOME ==# ('~'.$SUDO_USER)->expand() + + const g:dpp#_progname = has('nvim') && exists('$NVIM_APPNAME') ? + \ $NVIM_APPNAME : v:progname->fnamemodify(':r') + const g:dpp#_init_runtimepath = &runtimepath + + augroup dpp + autocmd! + augroup END +endfunction diff --git a/denops/dpp/app.ts b/denops/dpp/app.ts index a97bfd5..ea20868 100644 --- a/denops/dpp/app.ts +++ b/denops/dpp/app.ts @@ -27,8 +27,6 @@ export function main(denops: Denops) { }); await dpp.makeState(denops, basePath, plugins); - - return Promise.resolve(); }, }; } diff --git a/denops/dpp/dpp.ts b/denops/dpp/dpp.ts index 74fc9d6..ed8ee3f 100644 --- a/denops/dpp/dpp.ts +++ b/denops/dpp/dpp.ts @@ -1,4 +1,4 @@ -import { assertEquals, Denops, is } from "./deps.ts"; +import { assertEquals, Denops, is, vars } from "./deps.ts"; import { ActionName, BaseExt, @@ -19,7 +19,7 @@ import { } from "./context.ts"; import { Loader } from "./loader.ts"; import { defaultExtOptions } from "./base/ext.ts"; -import { errorException } from "./utils.ts"; +import { errorException, isDirectory } from "./utils.ts"; export class Dpp { private loader: Loader; @@ -63,16 +63,38 @@ export class Dpp { } async makeState(denops: Denops, basePath: string, plugins: Plugin[]) { - // Check sudo - const isSudo = await denops.call("dpp#is_sudo") as boolean; - // Initialize plugins const recordPlugins: Record = {}; for (const plugin of plugins) { - recordPlugins[plugin.name] = initPlugin(plugin, basePath, isSudo); + recordPlugins[plugin.name] = initPlugin(plugin, basePath); + } + + console.log(recordPlugins); + + if (!isDirectory(basePath)) { + await Deno.mkdir(basePath, { recursive: true }); } // Write state file + const progname = await vars.g.get(denops, "dpp#_progname"); + const stateFile = `${basePath}/cache_${progname}`; + + const cacheVersion = await vars.g.get(denops, "dpp#_cache_version"); + const initRuntimepath = await vars.g.get(denops, "dpp#_init_runtimepath"); + const stateLines = [ + `if g:dpp#_cache_version !=# ${cacheVersion} || ` + + `g:dpp#_init_runtimepath !=# '${initRuntimepath}' | ` + + " | throw ''Cache loading error'' | endif", + "let [s:plugins, s:ftplugin] = dpp#min#_load_cache_raw()", + "if s:plugins->empty() | throw 'Cache loading error' | endif", + "let g:dpp#_plugins = s:plugins", + "let g:dpp#ftplugin = s:ftplugin", + `let g:dpp#_base_path = '${basePath}'`, + `let &runtimepath = `, + ]; + + console.log(stateFile); + console.log(stateLines); } private async getExt( @@ -160,10 +182,10 @@ function extArgs< return [o, p]; } -function initPlugin(plugin: Plugin, basePath: string, isSudo: boolean): Plugin { +function initPlugin(plugin: Plugin, basePath: string): Plugin { if (!plugin.path) { // Set default path from basePath - plugin.path = `${basePath}/repos/${plugin.name}`; + plugin.path = `${basePath}/repos/${plugin.repo ?? plugin.name}`; } if (plugin.rev && plugin.rev.length > 0) { @@ -178,13 +200,10 @@ function initPlugin(plugin: Plugin, basePath: string, isSudo: boolean): Plugin { // Set rtp if (!plugin.rtp || plugin.rtp.length != 0) { - plugin.rtp = `${plugin.path}/${plugin.rtp}`; + plugin.rtp = !plugin.rtp ? plugin.path : `${plugin.path}/${plugin.rtp}`; } // Chomp plugin.rtp = plugin.rtp.replace(/\/$/, ""); - if (isSudo && !plugin.trusted) { - plugin.rtp = ""; - } if (plugin.depends && is.String(plugin.depends)) { plugin.depends = [plugin.depends]; @@ -223,7 +242,7 @@ Deno.test("initPlugin", () => { rev: "[hoge]", script_type: "foo", rtp: "autoload", - }, "base", false), + }, "base"), { name: "foo", path: "base/repos/foo__hoge_/foo", @@ -235,30 +254,16 @@ Deno.test("initPlugin", () => { }, ); - // sudo - assertEquals( - initPlugin({ - name: "foo", - }, "base", true), - { - name: "foo", - path: "base/repos/foo", - rtp: "", - lazy: false, - merged: true, - }, - ); - // lazy assertEquals( initPlugin({ name: "foo", on_ft: "foo", - }, "base", true), + }, "base"), { name: "foo", path: "base/repos/foo", - rtp: "", + rtp: "base/repos/foo", lazy: true, merged: false, on_ft: "foo", diff --git a/denops/dpp/types.ts b/denops/dpp/types.ts index b1d496d..cf032d0 100644 --- a/denops/dpp/types.ts +++ b/denops/dpp/types.ts @@ -95,5 +95,4 @@ export type Plugin = { rtp?: string; script_type?: string; timeout?: number; - trusted?: boolean; };