diff options
| author | Mitermayer Reis <mitermayer.reis@gmail.com> | 2018-05-25 13:06:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-25 13:06:44 -0700 |
| commit | 01c69288869829e12657f86a8e1c52858f669db5 (patch) | |
| tree | 328c1b60101b7eec45c38473f07f3a2045d74462 /autoload | |
| parent | 9093c1600698be5cedc0f917ca71dbdb4d5624b9 (diff) | |
| parent | 13d6948ca17540a2c480812f7d39d1b5ba102a38 (diff) | |
| download | vim-prettier-01c69288869829e12657f86a8e1c52858f669db5.tar.xz | |
Merge pull request #138 from SamHowie/master
Fix PrettierAsync segmentation fault
Diffstat (limited to 'autoload')
| -rw-r--r-- | autoload/prettier.vim | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/autoload/prettier.vim b/autoload/prettier.vim index 4b5a4e9..dcd9926 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,11 +277,18 @@ 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 + + " delete trailing newline introduced by the above append procedure + silent! execute '$delete _' + " Restore view call winrestview(l:winview) endfunction |
