Skip to content

Commit

Permalink
Generate startup.vim
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Mar 23, 2024
1 parent cdb9400 commit f9ba3e3
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 44 deletions.
14 changes: 7 additions & 7 deletions autoload/dpp/min.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ 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)
return 1
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()
Expand Down
8 changes: 4 additions & 4 deletions autoload/dpp/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions denops/@ddu-sources/dpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
ActionFlags,
BaseSource,
Item,
} from "https://deno.land/x/[email protected].2/types.ts";
import { Denops, vars } from "https://deno.land/x/[email protected].2/deps.ts";
} from "https://deno.land/x/[email protected].3/types.ts";
import { Denops, vars } from "https://deno.land/x/[email protected].3/deps.ts";
import { ActionData } from "https://deno.land/x/[email protected]/file.ts";
import { Plugin } from "../dpp/types.ts";

Expand Down
22 changes: 11 additions & 11 deletions denops/dpp/deps.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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/[email protected]/response_waiter.ts";
export { Lock } from "https://deno.land/x/[email protected]/mod.ts";
41 changes: 21 additions & 20 deletions denops/dpp/dpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}'`,
];
Expand Down Expand Up @@ -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.
Expand All @@ -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 <<EOF"],
vimrcLines.filter((line) => !line.match(/^\s*$|^\s*--/)),
["EOF"],
);
}
} else {
stateLines = stateLines.concat(
startupLines = startupLines.concat(
vimrcLines.filter((line) => !line.match(/^\s*$|^\s*"/)),
);
}
Expand All @@ -365,37 +365,38 @@ export class Dpp {
}

if (plugin.hook_add) {
stateLines.push(plugin.hook_add);
startupLines.push(plugin.hook_add);
}

if (plugin.ftplugin) {
mergeFtplugins(configReturn.ftplugins, plugin.ftplugin);
}
}

// 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,
{},
options,
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);

Expand Down

0 comments on commit f9ba3e3

Please sign in to comment.