Skip to content

Commit

Permalink
save rtp
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Sep 22, 2023
1 parent 11aedda commit a5284c8
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 145 deletions.
115 changes: 0 additions & 115 deletions autoload/dpp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -4,121 +4,6 @@ function dpp#load_state(base_path) abort
endif
endfunction

function dpp#begin(path, options = {}) abort
if !('#dpp'->exists())
call dpp#min#_init()
endif

let g:dpp#_options = extend(g:dpp#_options, a:options)

let g:dpp#_base_path = dpp#util#_expand(a:path)
if g:dpp#_base_path[-1:] ==# '/'
let g:dpp#_base_path = g:dpp#_base_path[: -2]
endif

" Cache paths
call dpp#util#_get_runtime_path()
call dpp#util#_get_cache_path()

const inline_vimrcs = g:dpp#_options->get('inline_vimrcs', [])

let g:dpp#_vimrcs = dpp#util#_get_vimrcs(g:dpp#_options->get('vimrcs', []))
let g:dpp#_vimrcs += inline_vimrcs
call map(g:dpp#_vimrcs, { _, val -> dpp#util#_expand(val) })

let g:dpp#_hook_add = ''

if has('vim_starting')
" Filetype off
if g:->get('did_load_filetypes', v:false)
let g:dpp#_off1 = 'filetype off'
execute g:dpp#_off1
endif
if 'b:did_indent'->exists() || 'b:did_ftplugin'->exists()
let g:dpp#_off2 = 'filetype plugin indent off'
execute g:dpp#_off2
endif
else
execute 'set rtp-=' .. g:dpp#_runtime_path->fnameescape()
execute 'set rtp-=' .. (g:dpp#_runtime_path .. '/after')->fnameescape()
endif

" Insert dpp runtimepath to the head of 'runtimepath'.
let rtps = dpp#util#_split_rtp(&runtimepath)
const idx = rtps->index(dpp#util#_substitute_path($VIMRUNTIME))
if idx < 0
call dpp#util#_error(printf(
\ '%s is not contained in "runtimepath".', $VIMRUNTIME))
call dpp#util#_error('verbose set runtimepath?'->execute())
return 1
endif
if a:path->fnamemodify(':t') ==# 'plugin'
\ && rtps->index(a:path->fnamemodify(':h')) >= 0
call dpp#util#_error('You must not set the installation directory'
\ .. ' under "&runtimepath/plugin"')
return 1
endif
call insert(rtps, g:dpp#_runtime_path, idx)
call dpp#util#_add_after(rtps, g:dpp#_runtime_path .. '/after')
let &runtimepath = dpp#util#_join_rtp(rtps,
\ &runtimepath, g:dpp#_runtime_path)

for vimrc in inline_vimrcs
execute (vimrc->fnamemodify(':e') ==# 'lua' ? 'luafile' : 'source')
\ vimrc->fnameescape()
endfor
endfunction
function dpp#end() abort
if !has('vim_starting')
call dpp#source(g:dpp#_plugins->values()
\ ->filter({ _, val ->
\ !val.lazy && !val.sourced && val.rtp !=# '' }))
endif

" Add runtimepath
const rtps = dpp#util#_split_rtp(&runtimepath)
const index = rtps->index(g:dpp#_runtime_path)
if index < 0
call dpp#util#_error(printf(
\ '%s is not contained in "runtimepath".', $VIMRUNTIME))
call dpp#util#_error('verbose set runtimepath?'->execute())
return 1
endif

let depends = []
const sourced = has('vim_starting') &&
\ (!('&loadplugins'->exists()) || &loadplugins)
for plugin in g:dpp#_plugins->values()
\ ->filter({ _, val ->
\ !(val->empty())
\ && !val.lazy && !val.sourced && val.rtp !=# ''
\ && (!(v:val->has_key('if')) || v:val.if->eval())
\ && v:val.path->isdirectory()
\ })

" Load dependencies
if plugin->has_key('depends')
let depends += plugin.depends
endif

if !plugin.merged
call insert(rtps, plugin.rtp, index)

if (plugin.rtp .. '/after')->isdirectory()
call dpp#util#_add_after(rtps, plugin.rtp .. '/after')
endif
endif

let plugin.sourced = sourced
endfor

let &runtimepath = dpp#util#_join_rtp(rtps, &runtimepath, '')

if !(depends->empty())
call dpp#source(depends)
endif
endfunction

function dpp#get(name = '') abort
return a:name ==# '' ?
\ g:dpp#_plugins->copy() : g:dpp#_plugins->get(a:name, {})
Expand Down
2 changes: 1 addition & 1 deletion autoload/dpp/source.vim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function dpp#autoload#_source(plugins) abort
endif

let rtps = dpp#util#_split_rtp(&runtimepath)
const index = rtps->index(dpp#util#_get_runtime_path())
const index = rtps->index(g:dpp#_runtime_path)
if index < 0
return []
endif
Expand Down
25 changes: 1 addition & 24 deletions autoload/dpp/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,8 @@ function dpp#util#_get_plugins(plugins) abort
\ ->filter({ _, val -> !(val->empty()) })
endfunction

function dpp#util#_get_base_path() abort
return g:dpp#_base_path
endfunction
function dpp#util#_get_runtime_path() abort
if g:dpp#_runtime_path !=# ''
return g:dpp#_runtime_path
endif

const g:dpp#_runtime_path = dpp#util#_get_cache_path() .. '/.dpp'
call dpp#util#_safe_mkdir(g:dpp#_runtime_path)
return g:dpp#_runtime_path
endfunction
function dpp#util#_get_cache_path() abort
if g:dpp#_cache_path !=# ''
return g:dpp#_cache_path
endif

const vimrc_path = has('nvim') && exists('$NVIM_APPNAME') ?
\ $NVIM_APPNAME :
\ dpp#util#_get_myvimrc()->fnamemodify(':t')
const g:dpp#_cache_path = dpp#util#_substitute_path(
\ g:->get('dpp#cache_directory', g:dpp#_base_path)
\ .. '/.cache/' .. vimrc_path)
call dpp#util#_safe_mkdir(g:dpp#_cache_path)
return g:dpp#_cache_path
return dpp#util#_substitute_path($VIMRUNTIME)
endfunction
function dpp#util#_get_vimrcs(vimrcs) abort
return !(a:vimrcs->empty()) ?
Expand Down
87 changes: 82 additions & 5 deletions denops/dpp/dpp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assertEquals, Denops, is, vars } from "./deps.ts";
import { assertEquals, Denops, is, op, vars } from "./deps.ts";
import {
ActionName,
BaseExt,
Expand Down Expand Up @@ -71,13 +71,72 @@ export class Dpp {

console.log(recordPlugins);

if (!isDirectory(basePath)) {
if (!await 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}`;

// Get runtimepath
const dppRuntimepath = await denops.call(
"dpp#util#_expand",
`${basePath}/.dpp`,
) as string;
console.log(dppRuntimepath);
if (!await isDirectory(dppRuntimepath)) {
await Deno.mkdir(dppRuntimepath, { recursive: true });
}
const currentRuntimepath = await op.runtimepath.getGlobal(denops);

const rtps = await denops.call(
"dpp#util#_split_rtp",
currentRuntimepath,
) as string[];

const runtimeIndex = rtps.indexOf(
await denops.call("dpp#util#_get_runtime_path") as string,
);

// Add plugins runtimepath
for (
const plugin of Object.values(recordPlugins).filter((plugin) =>
!plugin.lazy
)
) {
if (plugin.rtp && await isDirectory(plugin.rtp)) {
plugin.sourced = true;
rtps.splice(runtimeIndex, 0, plugin.rtp);

// TODO: Load dependencies

const afterDir = `${plugin.rtp}/after`;
if (await isDirectory(afterDir)) {
rtps.splice(
rtps.indexOf(
await denops.call("dpp#util#_get_runtime_path") as string,
) + 1,
0,
afterDir,
);
}
}
}
rtps.splice(
rtps.indexOf(
await denops.call("dpp#util#_get_runtime_path") as string,
),
0,
dppRuntimepath,
);
rtps.push(`${dppRuntimepath}/after`);

const newRuntimepath = await denops.call(
"dpp#util#_join_rtp",
rtps,
currentRuntimepath,
dppRuntimepath,
);

const cacheVersion = await vars.g.get(denops, "dpp#_cache_version");
const initRuntimepath = await vars.g.get(denops, "dpp#_init_runtimepath");
Expand All @@ -90,11 +149,27 @@ export class Dpp {
"let g:dpp#_plugins = s:plugins",
"let g:dpp#ftplugin = s:ftplugin",
`let g:dpp#_base_path = '${basePath}'`,
`let &runtimepath = `,
`let &runtimepath = '${newRuntimepath}'`,
];

console.log(stateFile);
const stateFile = await denops.call(
"dpp#util#_expand",
`${basePath}/state_${progname}`,
) as string;
await Deno.writeTextFile(stateFile, stateLines.join("\n"));

const cacheFile = await denops.call(
"dpp#util#_expand",
`${basePath}/cache_${progname}`,
) as string;
const cacheLines = [
JSON.stringify([plugins, {}]),
];
await Deno.writeTextFile(cacheFile, cacheLines.join("\n"));

console.log(stateLines);
console.log(cacheLines);
//console.log(rtps);
}

private async getExt(
Expand Down Expand Up @@ -183,6 +258,8 @@ function extArgs<
}

function initPlugin(plugin: Plugin, basePath: string): Plugin {
plugin.sourced = false;

if (!plugin.path) {
// Set default path from basePath
plugin.path = `${basePath}/repos/${plugin.repo ?? plugin.name}`;
Expand Down
1 change: 1 addition & 0 deletions denops/dpp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ export type Plugin = {
rev?: string;
rtp?: string;
script_type?: string;
sourced?: boolean;
timeout?: number;
};

0 comments on commit a5284c8

Please sign in to comment.