Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion autoload/prettier/job/async/neovim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down
11 changes: 9 additions & 2 deletions autoload/prettier/job/async/vim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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)}})
Expand Down
2 changes: 1 addition & 1 deletion autoload/prettier/job/runner.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions doc/prettier.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions plugin/prettier.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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, <line1>, <line2>, g:prettier#partial_format)

Expand Down