aboutsummaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorSam Howie <showie@fb.com>2018-05-24 20:59:24 -0700
committerSam Howie <showie@fb.com>2018-05-24 20:59:24 -0700
commit62fdd10233a0ad8da88e02a4d7e3c476da57859c (patch)
tree395427d72b822a4162e9f13c6208f248ed686cc7 /autoload
parent9093c1600698be5cedc0f917ca71dbdb4d5624b9 (diff)
downloadvim-prettier-62fdd10233a0ad8da88e02a4d7e3c476da57859c.tar.xz
Fix PrettierAsync segmentation fault
Diffstat (limited to 'autoload')
-rw-r--r--autoload/prettier.vim19
1 files changed, 11 insertions, 8 deletions
diff --git a/autoload/prettier.vim b/autoload/prettier.vim
index 4b5a4e9..f00426e 100644
--- a/autoload/prettier.vim
+++ b/autoload/prettier.vim
@@ -168,14 +168,13 @@ function! s:Prettier_Exec_Async(cmd, startSelection, endSelection) abort
if s:prettier_job_running != 1
let s:prettier_job_running = 1
- call job_start([&shell, &shellcmdflag, l:async_cmd], {
- \ 'in_io': 'buffer',
- \ 'in_top': a:startSelection,
- \ 'in_bot': a:endSelection,
- \ 'in_name': l:bufferName,
+ let l:job = job_start([&shell, &shellcmdflag, l:async_cmd], {
\ 'err_cb': {channel, msg -> s:Prettier_Job_Error(msg)},
\ 'close_cb': {channel -> s:Prettier_Job_Close(channel, a:startSelection, a:endSelection, l:bufferName)}})
- endif
+ let l:stdin = job_getchannel(l:job)
+ call ch_sendraw(l:stdin, join(getbufline(bufnr(l:bufferName), a:startSelection,a:endSelection), "\n"))
+ call ch_close_in(l:stdin)
+ endif
endfunction
function! s:Prettier_Job_Close(channel, startSelection, endSelection, bufferName) abort
@@ -278,10 +277,14 @@ function! s:Apply_Prettier_Format(lines, startSelection, endSelection) abort
endif
" delete all lines on the current buffer
- silent! execute len(l:newBuffer) . ',' . line('$') . 'delete _'
+ silent! execute '%delete _'
" replace all lines from the current buffer with output from prettier
- call setline(1, l:newBuffer)
+ let l:idx = 0
+ for l:line in l:newBuffer
+ silent! call append(l:idx, l:line)
+ let l:idx += 1
+ endfor
" Restore view
call winrestview(l:winview)