aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitermayer <mitermayer.reis@gmail.com>2017-06-19 21:15:00 -0700
committermitermayer <mitermayer.reis@gmail.com>2017-06-19 21:19:06 -0700
commitb55d891d2824f98d9fa6e258f5dba28d6b5ccc3c (patch)
tree1cd692c85623a22378d3bad303cbad2cb241ceca
parente93d69afb780ea2035c7ee3a9297ee37575b0b35 (diff)
downloadvim-prettier-b55d891d2824f98d9fa6e258f5dba28d6b5ccc3c.tar.xz
feature: enabling partial buffer conversion (tech review)
- removing trailing spaces - removing extra param from error callback - changing function signature with more consistent params
-rw-r--r--autoload/prettier.vim58
-rw-r--r--ftplugin/css.vim2
-rw-r--r--ftplugin/less.vim2
-rw-r--r--ftplugin/scss.vim2
-rw-r--r--ftplugin/typescript.vim2
-rw-r--r--plugin/prettier.vim2
6 files changed, 34 insertions, 34 deletions
diff --git a/autoload/prettier.vim b/autoload/prettier.vim
index 6a1e23c..fc0e14c 100644
--- a/autoload/prettier.vim
+++ b/autoload/prettier.vim
@@ -3,9 +3,9 @@ let s:prettier_job_running = 0
function! prettier#Prettier(...) abort
let l:execCmd = s:Get_Prettier_Exec()
- 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: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:config = getbufvar(bufnr('%'), 'prettier_ft_default_args', {})
if l:execCmd != -1
@@ -27,25 +27,25 @@ endfunction
function! prettier#Autoformat(...) abort
let l:curPos = getpos('.')
- let l:maxLineLookup = 50
- let l:maxTimeLookupMs = 500
+ let l:maxLineLookup = 50
+ let l:maxTimeLookupMs = 500
let l:pattern = '@format'
- " we need to move selection to the top before looking up to avoid
+ " 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)
+ call prettier#Prettier(1)
endif
" Restore the selection and if greater then before it defaults to end
call cursor(curPos[1], curPos[2])
endfunction
-function! s:Prettier_Exec_Sync(cmd, startSelection, endSelection) abort
+function! s:Prettier_Exec_Sync(cmd, startSelection, endSelection) abort
let l:out = split(system(a:cmd, getbufline(bufnr('%'), a:startSelection, a:endSelection)), '\n')
" check system exit code
@@ -54,14 +54,14 @@ function! s:Prettier_Exec_Sync(cmd, startSelection, endSelection) abort
return
endif
- if (s:Has_Content_Changed(a:startSelection, a:endSelection, l:out) == 0)
+ if (s:Has_Content_Changed(l:out, a:startSelection, a:endSelection) == 0)
return
endif
call s:Apply_Prettier_Format(l:out, a:startSelection, a:endSelection)
endfunction
-function! s:Prettier_Exec_Async(cmd, startSelection, endSelection) abort
+function! s:Prettier_Exec_Async(cmd, startSelection, endSelection) abort
if s:prettier_job_running != 1
let s:prettier_job_running = 1
call job_start(a:cmd, {
@@ -69,12 +69,12 @@ function! s:Prettier_Exec_Async(cmd, startSelection, endSelection) abort
\ 'in_top': a:startSelection,
\ 'in_bot': a:endSelection,
\ 'in_name': bufname('%'),
- \ 'err_cb': {channel, msg -> s:Prettier_Job_Error(channel, msg)},
+ \ 'err_cb': {channel, msg -> s:Prettier_Job_Error(msg)},
\ 'close_cb': {channel -> s:Prettier_Job_Close(channel, a:startSelection, a:endSelection)}})
endif
endfunction
-function! s:Prettier_Job_Close(channel, startSelection, endSelection) abort
+function! s:Prettier_Job_Close(channel, startSelection, endSelection) abort
let l:out = []
while ch_status(a:channel, {'part': 'out'}) == 'buffered'
@@ -82,19 +82,19 @@ function! s:Prettier_Job_Close(channel, startSelection, endSelection) abort
endwhile
" nothing to update
- if (s:Has_Content_Changed(a:startSelection, a:endSelection, l:out) == 0)
+ if (s:Has_Content_Changed(l:out, a:startSelection, a:endSelection) == 0)
let s:prettier_job_running = 0
return
endif
-
- if len(l:out)
+
+ if len(l:out)
call s:Apply_Prettier_Format(l:out, a:startSelection, a:endSelection)
write
let s:prettier_job_running = 0
endif
endfunction
-function! s:Prettier_Job_Error(channel, msg) abort
+function! s:Prettier_Job_Error(msg) abort
call s:Prettier_Parse_Error(split(a:msg, '\n'))
let s:prettier_job_running = 0
endfunction
@@ -114,13 +114,13 @@ function! s:Handle_Parsing_Errors(out) abort
endif
endfor
- if len(l:errors)
+ if len(l:errors)
call setqflist(l:errors)
botright copen
endif
endfunction
-function! s:Has_Content_Changed(startLine, endLine, content) abort
+function! s:Has_Content_Changed(content, startLine, endLine) abort
return getbufline(bufnr('%'), 1, line('$')) == s:Get_New_Buffer(a:content, a:startLine, a:endLine) ? 0 : 1
endfunction
@@ -172,24 +172,24 @@ endfunction
" By default we will search for the following
" => locally installed prettier inside node_modules on any parent folder
-" => globally installed prettier
+" => globally installed prettier
" => vim-prettier prettier installation
" => if all fails suggest install
function! s:Get_Prettier_Exec() abort
let l:local_exec = s:Get_Prettier_Local_Exec()
if executable(l:local_exec)
return l:local_exec
- endif
+ endif
let l:global_exec = s:Get_Prettier_Global_Exec()
if executable(l:global_exec)
return l:global_exec
- endif
+ endif
let l:plugin_exec = s:Get_Prettier_Plugin_Exec()
if executable(l:plugin_exec)
return l:plugin_exec
- endif
+ endif
return -1
endfunction
@@ -207,11 +207,11 @@ function! s:Get_Prettier_Plugin_Exec() abort
endfunction
function! s:Get_Exec(...) abort
- let l:rootDir = a:0 > 0 ? a:1 : 0
+ let l:rootDir = a:0 > 0 ? a:1 : 0
let l:exec = -1
- if isdirectory(l:rootDir)
- let l:dir = s:Tranverse_Dir_Search(l:rootDir)
+ if isdirectory(l:rootDir)
+ let l:dir = s:Tranverse_Dir_Search(l:rootDir)
if dir != -1
let l:exec = s:Get_Path_To_Exec(l:dir)
endif
@@ -223,8 +223,8 @@ function! s:Get_Exec(...) abort
endfunction
function! s:Get_Path_To_Exec(...) abort
- let l:rootDir = a:0 > 0 ? a:1 : -1
- let l:dir = l:rootDir != -1 ? l:rootDir . '/.bin/' : ''
+ let l:rootDir = a:0 > 0 ? a:1 : -1
+ let l:dir = l:rootDir != -1 ? l:rootDir . '/.bin/' : ''
return dir . 'prettier'
endfunction
@@ -234,12 +234,12 @@ function! s:Tranverse_Dir_Search(rootDir) abort
while 1
let l:search_dir = root . '/' . dir
- if isdirectory(l:search_dir)
+ if isdirectory(l:search_dir)
return l:search_dir
endif
let l:parent = fnamemodify(root, ':h')
- if l:parent == l:root
+ if l:parent == l:root
return -1
endif
diff --git a/ftplugin/css.vim b/ftplugin/css.vim
index 92bc628..f268f42 100644
--- a/ftplugin/css.vim
+++ b/ftplugin/css.vim
@@ -1,5 +1,5 @@
let b:prettier_ft_default_args = {
- \ 'parser': 'postcss'
+ \ 'parser': 'postcss'
\ }
augroup Prettier
diff --git a/ftplugin/less.vim b/ftplugin/less.vim
index 92bc628..f268f42 100644
--- a/ftplugin/less.vim
+++ b/ftplugin/less.vim
@@ -1,5 +1,5 @@
let b:prettier_ft_default_args = {
- \ 'parser': 'postcss'
+ \ 'parser': 'postcss'
\ }
augroup Prettier
diff --git a/ftplugin/scss.vim b/ftplugin/scss.vim
index 92bc628..f268f42 100644
--- a/ftplugin/scss.vim
+++ b/ftplugin/scss.vim
@@ -1,5 +1,5 @@
let b:prettier_ft_default_args = {
- \ 'parser': 'postcss'
+ \ 'parser': 'postcss'
\ }
augroup Prettier
diff --git a/ftplugin/typescript.vim b/ftplugin/typescript.vim
index b654a48..8151c09 100644
--- a/ftplugin/typescript.vim
+++ b/ftplugin/typescript.vim
@@ -1,5 +1,5 @@
let b:prettier_ft_default_args = {
- \ 'parser': 'typescript'
+ \ 'parser': 'typescript'
\ }
augroup Prettier
diff --git a/plugin/prettier.vim b/plugin/prettier.vim
index ca35c79..207c46c 100644
--- a/plugin/prettier.vim
+++ b/plugin/prettier.vim
@@ -20,7 +20,7 @@ let g:loaded_prettier = 1
" autoformating enabled by default upon saving
let g:prettier#autoformat = get(g:, 'prettier#autoformat', 1)
-" calling :Prettier by default runs synchronous
+" calling :Prettier by default runs synchronous
let g:prettier#exec_cmd_async = get(g:, 'prettier#exec_cmd_async', 0)
" when having formatting errors will open the quickfix by default