Skip to content

Commit

Permalink
Fix expand path
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Sep 24, 2023
1 parent dcc5904 commit d62d6d6
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const s:denops_src = '~/.cache/dpp/repos/github.com/denops/denops.vim'
" Set dpp runtime path (required)
execute 'set runtimepath^=' .. s:dpp_src
if dpp#load_state(s:dpp_base)
if dpp#min#load_state(s:dpp_base)
" NOTE: dpp#make_state() requires denops.vim
execute 'set runtimepath^=' .. s:denops_src
autocmd User DenopsReady
Expand Down
15 changes: 6 additions & 9 deletions autoload/dpp.vim
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
function dpp#load_state(base_path) abort
if !('#dpp'->exists())
call dpp#min#_init()
endif
endfunction

function dpp#get(name = '') abort
return a:name ==# '' ?
\ g:dpp#_plugins->copy() : g:dpp#_plugins->get(a:name, {})
Expand All @@ -19,8 +13,11 @@ function dpp#make_state(base_path, config_path) abort
return 1
endif

if !(a:config_path->filereadable())
call dpp#util#print_error(printf('"%s" is not found.', a:config_path))
const config_path = dpp#util#_expand(a:config_path)
const base_path = dpp#util#_expand(a:base_path)

if !(config_path->filereadable())
call dpp#util#_error(printf('"%s" is not found.', a:config_path))
return 1
endif

Expand All @@ -33,5 +30,5 @@ function dpp#make_state(base_path, config_path) abort
return
endif

return dpp#denops#_notify('makeState', [a:base_path, a:config_path])
return dpp#denops#_notify('makeState', [base_path, config_path])
endfunction
9 changes: 5 additions & 4 deletions autoload/dpp/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ function dpp#util#_add_after(rtps, path) abort
endfunction

function dpp#util#_expand(path) abort
const path = (a:path =~# '^\~') ? a:path->fnamemodify(':p') :
\ (a:path =~# '^\$\h\w*') ? a:path
\ ->substitute('^\$\h\w*', '\=eval(submatch(0))', '') :
\ a:path
let path = (a:path =~# '^\$\h\w*') ? a:path->substitute(
\ '^\$\h\w*', '\=eval(submatch(0))', '') : a:path
if path =~# '^\~'
let path = path->fnamemodify(':p')
endif
return ((s:is_windows && path =~# '\\') ?
\ dpp#util#_substitute_path(path) : path)->substitute('/$', '', '')
endfunction
Expand Down
1 change: 0 additions & 1 deletion denops/@dpp-exts/toml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class Ext extends BaseExt<Params> {
name: plugin.name ?? basename(plugin.repo ?? ""),
};
});
console.log(plugins);

return plugins;
},
Expand Down
2 changes: 1 addition & 1 deletion denops/dpp/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export class ContextBuilder {
for (const key in options) {
if (!(key in defaults)) {
await denops.call(
"dpp#util#print_error",
"dpp#util#_error",
`Invalid ${name}: "${key}"`,
);
}
Expand Down
19 changes: 5 additions & 14 deletions denops/dpp/dpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Dpp {
const action = ext.actions[actionName];
if (!action) {
await denops.call(
"ddu#util#print_error",
"ddu#util#_error",
`Not found UI action: ${actionName}`,
);
return;
Expand Down Expand Up @@ -79,10 +79,7 @@ export class Dpp {
const progname = await vars.g.get(denops, "dpp#_progname");

// Get runtimepath
const dppRuntimepath = await denops.call(
"dpp#util#_expand",
`${basePath}/.dpp`,
) as string;
const dppRuntimepath = `${basePath}/.dpp`;
console.log(dppRuntimepath);
if (!await isDirectory(dppRuntimepath)) {
await Deno.mkdir(dppRuntimepath, { recursive: true });
Expand Down Expand Up @@ -152,16 +149,10 @@ export class Dpp {
`let &runtimepath = '${newRuntimepath}'`,
];

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

const cacheFile = await denops.call(
"dpp#util#_expand",
`${basePath}/cache_${progname}`,
) as string;
const cacheFile = `${basePath}/cache_${progname}`;
const cacheLines = [
JSON.stringify([plugins, {}]),
];
Expand Down Expand Up @@ -190,7 +181,7 @@ export class Dpp {
if (!ext) {
if (extName.length !== 0) {
await denops.call(
"dpp#util#print_error",
"dpp#util#_error",
`Not found ext: "${extName}"`,
);
}
Expand Down
8 changes: 4 additions & 4 deletions denops/dpp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ export async function errorException(
message: string,
) {
await denops.call(
"dpp#util#print_error",
"dpp#util#_error",
message,
);
if (e instanceof Error) {
await denops.call(
"dpp#util#print_error",
"dpp#util#_error",
e.message,
);
if (e.stack) {
await denops.call(
"dpp#util#print_error",
"dpp#util#_error",
e.stack,
);
}
} else {
await denops.call(
"dpp#util#print_error",
"dpp#util#_error",
"unknown error object",
);
console.error(e);
Expand Down
2 changes: 1 addition & 1 deletion doc/dpp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ EXAMPLES *dpp-examples*
" Set dpp runtime path (required)
execute 'set runtimepath^=' .. s:dpp_src
if dpp#load_state(s:dpp_base)
if dpp#min#load_state(s:dpp_base)
" NOTE: dpp#make_state() requires denops.vim
execute 'set runtimepath^=' .. s:denops_src
autocmd User DenopsReady
Expand Down

0 comments on commit d62d6d6

Please sign in to comment.