diff --git a/autoload/prettier/job/async/neovim.vim b/autoload/prettier/job/async/neovim.vim index 35e5f82..b028efd 100644 --- a/autoload/prettier/job/async/neovim.vim +++ b/autoload/prettier/job/async/neovim.vim @@ -16,7 +16,14 @@ function! prettier#job#async#neovim#run(cmd, startSelection, endSelection) abort let l:out = [] let l:err = [] - let l:job = jobstart([&shell, &shellcmdflag, a:cmd], { + if has('win32') || has('win64') + " windows doesn't cope well with job cmd lists + let l:job_cmd = a:cmd + else + let l:job_cmd = [&shell, &shellcmdflag, a:cmd] + endif + + let l:job = job_start(l:job_cmd, { \ 'stdout_buffered': 1, \ 'stderr_buffered': 1, \ 'on_stdout': {job_id, data, event -> extend(l:out, data)}, diff --git a/autoload/prettier/job/async/vim.vim b/autoload/prettier/job/async/vim.vim index 29774b9..522b30a 100644 --- a/autoload/prettier/job/async/vim.vim +++ b/autoload/prettier/job/async/vim.vim @@ -3,12 +3,19 @@ let s:prettier_job_running = 0 function! prettier#job#async#vim#run(cmd, startSelection, endSelection) abort if s:prettier_job_running == 1 return - endif + endif let s:prettier_job_running = 1 let l:bufferName = bufname('%') - let l:job = job_start([&shell, &shellcmdflag, a:cmd], { + if has('win32') || has('win64') + " windows doesn't cope well with job cmd lists + let l:job_cmd = a:cmd + else + let l:job_cmd = [&shell, &shellcmdflag, a:cmd] + endif + + let l:job = job_start(l:job_cmd, { \ 'out_io': 'buffer', \ 'err_cb': {channel, msg -> s:onError(msg)}, \ 'close_cb': {channel -> s:onClose(channel, a:startSelection, a:endSelection, l:bufferName)}}) diff --git a/autoload/prettier/job/runner.vim b/autoload/prettier/job/runner.vim index 60cb8a5..feb138a 100644 --- a/autoload/prettier/job/runner.vim +++ b/autoload/prettier/job/runner.vim @@ -27,7 +27,7 @@ function! s:asyncFormat(cmd, startSelection, endSelection) abort " required for Windows support on async operations let l:cmd = a:cmd if has('win32') || has('win64') - let l:cmd = 'cmd.exe /c ' . a:cmd + let l:cmd = g:prettier#win_async_shell_cmds . ' ' . a:cmd endif if s:isAsyncVim diff --git a/doc/prettier.txt b/doc/prettier.txt index 052ed1a..ffea822 100644 --- a/doc/prettier.txt +++ b/doc/prettier.txt @@ -137,6 +137,16 @@ By default parsing errors will open the quickfix but can also be disabled > let g:prettier#quickfix_enabled = 1 < +Running async commands in windows is tricky and usually requires running an extra shell. +It is set up by default to use cmd as: +> + let g:prettier#win_async_shell_cmds = 'cmd /c' +< +but it can be modified to use powershell (desktop or core) or powershell scripts as: +> + let g:prettier#win_async_shell_cmds = 'powershell -Command' + let g:prettier#win_async_shell_cmds = 'pwsh -File' +< By default we auto focus on the quickfix when there are errors but can also be disabled > let g:prettier#quickfix_auto_focus = 0 diff --git a/plugin/prettier.vim b/plugin/prettier.vim index 4f9844a..fe4a6cd 100644 --- a/plugin/prettier.vim +++ b/plugin/prettier.vim @@ -137,6 +137,10 @@ let g:prettier#config#trailing_comma = get(g:,'prettier#config#trailing_comma', " See more: https://prettier.io/docs/en/options.html#require-pragma let g:prettier#config#require_pragma= get(g:, 'prettier#config#require_pragma', 'false') +" Commands to decorate the async job on windows +" default: 'cmd /c' +let g:prettier#win_async_shell_cmds = get(g: , 'prettier#win_async_shell_cmds', 'cmd /c') + " synchronous by default command! -nargs=? -range=% Prettier call prettier#Prettier(g:prettier#exec_cmd_async, , , g:prettier#partial_format)