aboutsummaryrefslogtreecommitdiff
path: root/autoload/prettier.vim
diff options
context:
space:
mode:
authormitermayer <mitermayer.reis@gmail.com>2017-06-07 10:45:48 -0700
committermitermayer <mitermayer.reis@gmail.com>2017-06-07 10:46:20 -0700
commitc211c98ab7118be61873d0fe9897e5986c6f6441 (patch)
treefc18e666a6f7446ca8021119f16eb28b729e4e04 /autoload/prettier.vim
parentc28004d9c616a3599e8d0622c87fa071aa2342e8 (diff)
downloadvim-prettier-c211c98ab7118be61873d0fe9897e5986c6f6441.tar.xz
Adding async command and user configurations
- Adding configuration toggle for controlling error quick fix parsing - Adding PrettierAsync command - Fixing configuration bug where boolean values where not correctly parsed - Making sure that async jobs do not execute if already in progress
Diffstat (limited to 'autoload/prettier.vim')
-rw-r--r--autoload/prettier.vim21
1 files changed, 15 insertions, 6 deletions
diff --git a/autoload/prettier.vim b/autoload/prettier.vim
index 66166f4..6c655d2 100644
--- a/autoload/prettier.vim
+++ b/autoload/prettier.vim
@@ -1,4 +1,5 @@
let s:root_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h')
+let s:prettier_job_running = 0
function! prettier#Prettier(...) abort
let l:execCmd = s:Get_Prettier_Exec()
@@ -55,11 +56,14 @@ function! s:Prettier_Exec_Sync(cmd) abort
endfunction
function! s:Prettier_Exec_Async(cmd) abort
- call job_start(a:cmd, {
- \ 'in_io': 'buffer',
- \ 'in_name': bufname('%'),
- \ 'err_cb': 'Prettier_Job_Error',
- \ 'close_cb': 'Prettier_Job_Close' })
+ if s:prettier_job_running != 1
+ let s:prettier_job_running = 1
+ call job_start(a:cmd, {
+ \ 'in_io': 'buffer',
+ \ 'in_name': bufname('%'),
+ \ 'err_cb': 'Prettier_Job_Error',
+ \ 'close_cb': 'Prettier_Job_Close' })
+ endif
endfunction
function! Prettier_Job_Close(channel) abort
@@ -71,17 +75,20 @@ function! Prettier_Job_Close(channel) abort
" nothing to update
if (getbufline(bufnr('%'), 1, '$') == l:out)
+ let s:prettier_job_running = 0
return
endif
if len(l:out)
call s:Apply_Prettier_Format(l:out)
write
+ let s:prettier_job_running = 0
endif
endfunction
function! Prettier_Job_Error(channel, msg) abort
call s:Prettier_Parse_Error(split(a:msg, '\n'))
+ let s:prettier_job_running = 0
endfunction
function! s:Handle_Parsing_Errors(out) abort
@@ -225,7 +232,9 @@ endfunction
function! s:Prettier_Parse_Error(errors) abort
echohl WarningMsg | echom 'Prettier: failed to parse buffer.' | echohl NONE
- call s:Handle_Parsing_Errors(a:errors)
+ if g:prettier#quickfix_enabled
+ call s:Handle_Parsing_Errors(a:errors)
+ endif
endfunction
" If we can't find any prettier installing we then suggest where to get it from