aboutsummaryrefslogtreecommitdiff
path: root/autoload/prettier.vim
diff options
context:
space:
mode:
authormitermayer <mitermayer.reis@gmail.com>2018-05-28 20:53:30 -0700
committermitermayer <mitermayer.reis@gmail.com>2018-06-03 22:58:24 -0700
commitec6ede90f3b9948ed7063402189653f8d6721326 (patch)
tree69d08cc06297b9144fd630032368013a450a8aea /autoload/prettier.vim
parent98845cdbbe243f4a62adbd73cbe7febec1f41efa (diff)
downloadvim-prettier-ec6ede90f3b9948ed7063402189653f8d6721326.tar.xz
Enabling partial formatting but still maintaining support for fragment
formatting
Diffstat (limited to 'autoload/prettier.vim')
-rw-r--r--autoload/prettier.vim18
1 files changed, 17 insertions, 1 deletions
diff --git a/autoload/prettier.vim b/autoload/prettier.vim
index fae1ef8..0e8ade3 100644
--- a/autoload/prettier.vim
+++ b/autoload/prettier.vim
@@ -69,14 +69,30 @@ function! prettier#Prettier(...) abort
let l:async = a:0 > 0 ? a:1 : 0
let l:startSelection = a:0 > 1 ? a:2 : 1
let l:endSelection = a:0 > 2 ? a:3 : line('$')
+ let l:hasSelection = a:0 > 2 ? 1 : 0
+ let l:partialFormat = a:0 > 3 && a:4 ? a:4 : 0
let l:config = getbufvar(bufnr('%'), 'prettier_ft_default_args', {})
+ let l:partialFormatEnabled = l:hasSelection && l:partialFormat
if l:execCmd != -1
- let l:cmd = l:execCmd . prettier#resolver#config#buildCliArgs(prettier#resolver#preset#build(l:config))
+ " TODO
+ " => we should make sure we can resolve --range-start and --range-end when required
+ " => when the above is required we should also update l:startSelection to '1' and l:endSelection to line('$')
+ let l:cmd = l:execCmd . prettier#resolver#config#resolve(
+ \ prettier#resolver#preset#resolve(l:config),
+ \ l:partialFormatEnabled,
+ \ l:startSelection,
+ \ l:endSelection)
" close quickfix if it is opened
call prettier#utils#quickfix#close()
+ " we will be using portion formatting, so we need to send entire buffer to prettier
+ if l:partialFormatEnabled
+ let l:startSelection = 1
+ let l:endSelection = line('$')
+ endif
+
" format buffer
call prettier#job#runner#run(l:cmd, l:startSelection, l:endSelection, l:async)
else