diff options
| author | Mitermayer Reis <mitermayer.reis@gmail.com> | 2019-09-13 14:56:12 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-13 14:56:12 -0700 |
| commit | e98b108ded5c906dde32db2f9856184e00dfc945 (patch) | |
| tree | 2bb00ea13832cd22f23566250ece8c93954a852e /autoload/prettier.vim | |
| parent | 758415cc88bbe7144964ef3ad770acd400567e55 (diff) | |
| parent | 3dc6684302ff2749570d938e1d49862db0e2648c (diff) | |
| download | vim-prettier-e98b108ded5c906dde32db2f9856184e00dfc945.tar.xz | |
Merge pull request #206 from prettier/issues/184-fixing-undo-step
Adding support for require-pragma and depracting previous naive implemenation
Diffstat (limited to 'autoload/prettier.vim')
| -rw-r--r-- | autoload/prettier.vim | 33 |
1 files changed, 6 insertions, 27 deletions
diff --git a/autoload/prettier.vim b/autoload/prettier.vim index 3241f48..e66f4b7 100644 --- a/autoload/prettier.vim +++ b/autoload/prettier.vim @@ -34,33 +34,9 @@ function! prettier#PrettierCli(user_input) abort endif endfunction -" Allows @format pragma support +" Allows @format and @prettier pragma support upon saving function! prettier#Autoformat(...) abort - let l:curPos = getpos('.') - let l:maxLineLookup = 50 - let l:maxTimeLookupMs = 500 - let l:pattern = '@format' - let l:search = @/ - let l:winview = winsaveview() - - " we need to move selection to the top before looking up to avoid - " scanning a very long file - call cursor(1, 1) - - " Search starting at the start of the document - if search(l:pattern, 'n', l:maxLineLookup, l:maxTimeLookupMs) > 0 - " autoformat async - call prettier#Prettier(1) - endif - - " Restore the selection and if greater then before it defaults to end - call cursor(l:curPos[1], l:curPos[2]) - - " Restore view - call winrestview(l:winview) - - " Restore search - let @/=l:search + call prettier#Prettier(1, 1, line('$'), 0, { 'requirePragma': 'true'}) endfunction " Main prettier command @@ -71,9 +47,12 @@ function! prettier#Prettier(...) abort 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 + let l:overWrite = a:0 > 4 ? a:5 : {} + let l:bufferConfig = getbufvar(bufnr('%'), 'prettier_ft_default_args', {}) + let l:config = extend(l:bufferConfig, l:overWrite) + if l:execCmd != -1 " TODO " => we should make sure we can resolve --range-start and --range-end when required |
