Skip to content

Commit

Permalink
Fix for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Nov 5, 2023
1 parent 5b7bd44 commit 9a8a7c1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
15 changes: 6 additions & 9 deletions autoload/dpp/util.vim
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,12 @@ function dpp#util#_execute_hook(plugin, hook_name, hook) abort
endif

try
if a:hook->type() == v:t_string
let cmds = a:hook->split('\n')
if !(cmds->empty()) && cmds[0] =~# '^\s*vim9script' && exists(':vim9')
vim9 call execute(cmds[1 : ], '')
else
call execute(cmds, '')
endif
" NOTE: hook may contain \r in Windows
const cmds = a:hook->split('\r\?\n')
if !(cmds->empty()) && cmds[0] =~# '^\s*vim9script' && exists(':vim9')
vim9 call execute(cmds[1 : ], '')
else
call call(a:hook, [])
call execute(cmds, '')
endif

let a:plugin.called[string(a:hook)] = v:true
Expand Down Expand Up @@ -249,7 +246,7 @@ endfunction
function dpp#util#_dos2unix(path) abort
call writefile(
\ readfile(a:path)
\ ->map({ _, val -> val->substitute("\r", '', 'g')}),
\ ->map({ _, val -> val->substitute('\r', '', 'g')}),
\ a:path
\ )
endfunction
15 changes: 12 additions & 3 deletions denops/dpp/dpp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Denops,
dirname,
extname,
fn,
is,
join,
vars,
Expand Down Expand Up @@ -115,6 +116,8 @@ export class Dpp {
name: string,
configReturn: ConfigReturn,
) {
const hasWindows = await fn.has(denops, "win32");

// Initialize plugins
const protocols = await this.getProtocols(denops, options);
const recordPlugins: Record<string, Plugin> = {};
Expand Down Expand Up @@ -375,7 +378,9 @@ export class Dpp {
// Write state file
const stateFile = `${basePath}/${name}/state.vim`;
await Deno.writeTextFile(stateFile, stateLines.join("\n"));
await denops.call("dpp#util#_dos2unix", stateFile);
if (hasWindows) {
await denops.call("dpp#util#_dos2unix", stateFile);
}

const cacheFile = `${basePath}/${name}/cache.vim`;
const cacheLines = [
Expand All @@ -387,7 +392,9 @@ export class Dpp {
]),
];
await Deno.writeTextFile(cacheFile, cacheLines.join("\n"));
await denops.call("dpp#util#_dos2unix", cacheFile);
if (hasWindows) {
await denops.call("dpp#util#_dos2unix", cacheFile);
}

//console.log(stateLines);
//console.log(cacheLines);
Expand All @@ -409,7 +416,9 @@ export class Dpp {
}

await Deno.writeTextFile(path, generatedFtplugins[path].join("\n"));
await denops.call("dpp#util#_dos2unix", path);
if (hasWindows) {
await denops.call("dpp#util#_dos2unix", path);
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion denops/dpp/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export function convert2List<T>(expr: T | T[] | undefined): T[] {
return !expr ? [] : is.Array(expr) ? expr : [expr];
}

export async function isDirectory(path: string) {
export async function isDirectory(path: string | undefined) {
if (!path) {
return false;
}

// NOTE: Deno.stat() may be failed
try {
if ((await Deno.stat(path)).isDirectory) {
Expand Down

0 comments on commit 9a8a7c1

Please sign in to comment.