Skip to content

Commit b9a4108

Browse files
committed
Change helpers back to accept syscall-like args, but consistently
1 parent a1c0f71 commit b9a4108

10 files changed

+29
-35
lines changed

autoload/codefmt/autopep8.vim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ function! codefmt#autopep8#GetFormatter() abort
6969
call maktaba#ensure#IsNumber(a:endline)
7070

7171
if s:autopep8_supports_range
72-
call codefmt#formatterhelpers#Format(maktaba#syscall#Create([
72+
call codefmt#formatterhelpers#Format([
7373
\ l:executable,
7474
\ '--range', string(a:startline), string(a:endline),
75-
\ '-']))
75+
\ '-'])
7676
else
7777
call codefmt#formatterhelpers#AttemptFakeRangeFormatting(
7878
\ a:startline,
7979
\ a:endline,
80-
\ maktaba#syscall#Create([l:executable, '-']))
80+
\ [l:executable, '-'])
8181
endif
8282
endfunction
8383

autoload/codefmt/buildifier.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ function! codefmt#buildifier#GetFormatter() abort
4848
try
4949
" NOTE: Ignores any line ranges given and formats entire buffer.
5050
" buildifier does not support range formatting.
51-
call codefmt#formatterhelpers#Format(maktaba#syscall#Create(l:cmd))
51+
call codefmt#formatterhelpers#Format(l:cmd)
5252
catch
5353
" Parse all the errors and stick them in the quickfix list.
5454
let l:errors = []

autoload/codefmt/dartfmt.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function! codefmt#dartfmt#GetFormatter() abort
4343
" dartfmt does not support range formatting yet:
4444
" https://github.com/dart-lang/dart_style/issues/92
4545
call codefmt#formatterhelpers#AttemptFakeRangeFormatting(
46-
\ a:startline, a:endline, maktaba#syscall#Create(l:cmd))
46+
\ a:startline, a:endline, l:cmd)
4747
catch /ERROR(ShellError):/
4848
" Parse all the errors and stick them in the quickfix list.
4949
let l:errors = []

autoload/codefmt/formatterhelpers.vim

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,15 @@
1313
" limitations under the License.
1414

1515

16-
function! s:EnsureIsSyscall(Value) abort
17-
if type(a:Value) == type({}) &&
18-
\ has_key(a:Value, 'Call') &&
19-
\ maktaba#function#HasSameName(
20-
\ a:Value.Call, function('maktaba#syscall#Call'))
21-
return a:Value
22-
endif
23-
throw maktaba#error#BadValue(
24-
\ 'Not a valid matkaba.Syscall: %s', string(a:Value))
25-
endfunction
26-
27-
2816
""
2917
" @public
30-
" Format lines in the current buffer via a formatter invoked by {cmd} (a
31-
" |maktaba.Syscall|). The command includes the explicit range line numbers to
32-
" use, if any.
18+
" Format lines in the current buffer via a formatter invoked by {cmd}, which
19+
" is a system call represented by either a |maktaba.Syscall| or any argument
20+
" accepted by |maktaba#syscall#Create()|. The command includes any arguments
21+
" for the explicit range line numbers to use, if any.
3322
"
3423
" @throws ShellError if the {cmd} system call fails
3524
function! codefmt#formatterhelpers#Format(cmd) abort
36-
call s:EnsureIsSyscall(a:cmd)
3725
let l:lines = getline(1, line('$'))
3826
let l:input = join(l:lines, "\n")
3927

@@ -47,8 +35,11 @@ endfunction
4735
" @public
4836
" Attempt to format a range of lines from {startline} to {endline} in the
4937
" current buffer via a formatter that doesn't natively support range
50-
" formatting (invoked by {cmd}, a |maktaba.Syscall|), using a hacky strategy
51-
" of sending those lines to the formatter in isolation.
38+
" formatting, which is invoked via {cmd} (a system call represented by either
39+
" a |maktaba.Syscall| or any argument accepted by |maktaba#syscall#Create()|).
40+
" It uses a hacky strategy of sending those lines to the formatter in
41+
" isolation, which gives bad results if the code on those lines isn't
42+
" a self-contained block of syntax or is part of a larger indent.
5243
"
5344
" If invoking this hack, please make sure to file a feature request against
5445
" the tool for range formatting and post a URL for that feature request above
@@ -59,12 +50,11 @@ function! codefmt#formatterhelpers#AttemptFakeRangeFormatting(
5950
\ startline, endline, cmd) abort
6051
call maktaba#ensure#IsNumber(a:startline)
6152
call maktaba#ensure#IsNumber(a:endline)
62-
call s:EnsureIsSyscall(a:cmd)
6353

6454
let l:lines = getline(1, line('$'))
6555
let l:input = join(l:lines[a:startline - 1 : a:endline - 1], "\n")
6656

67-
let l:result = a:cmd.WithStdin(l:input).Call()
57+
let l:result = maktaba#syscall#Create(a:cmd).WithStdin(l:input).Call()
6858
let l:formatted = split(l:result.stdout, "\n")
6959
" Special case empty slice: neither l:lines[:0] nor l:lines[:-1] is right.
7060
let l:before = a:startline > 1 ? l:lines[ : a:startline - 2] : []

autoload/codefmt/gofmt.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function! codefmt#gofmt#GetFormatter() abort
4343
" gofmt does not support range formatting.
4444
" TODO: File a feature request with gofmt and link it here.
4545
call codefmt#formatterhelpers#AttemptFakeRangeFormatting(
46-
\ a:startline, a:endline, maktaba#syscall#Create(l:cmd))
46+
\ a:startline, a:endline, l:cmd)
4747
catch /ERROR(ShellError):/
4848
" Parse all the errors and stick them in the quickfix list.
4949
let l:errors = []

autoload/codefmt/googlejava.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function! codefmt#googlejava#GetFormatter() abort
5959
let l:ranges_str = join(map(copy(a:ranges), 'v:val[0] . ":" . v:val[1]'), ',')
6060
let l:cmd += ['--lines', l:ranges_str, '-']
6161

62-
call codefmt#formatterhelpers#Format(maktaba#syscall#Create(l:cmd))
62+
call codefmt#formatterhelpers#Format(l:cmd)
6363
endfunction
6464

6565
return l:formatter

autoload/codefmt/jsbeautify.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function! codefmt#jsbeautify#GetFormatter() abort
5555
" js-beautify does not support range formatting yet:
5656
" https://github.com/beautify-web/js-beautify/issues/610
5757
call codefmt#formatterhelpers#AttemptFakeRangeFormatting(
58-
\ a:startline, a:endline, maktaba#syscall#Create(l:cmd))
58+
\ a:startline, a:endline, l:cmd)
5959
endfunction
6060

6161
return l:formatter

autoload/codefmt/rustfmt.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function! codefmt#rustfmt#GetFormatter() abort
5555
" NOTE: Ignores any line ranges given and formats entire buffer.
5656
" Even though rustfmt supports formatting ranges through the --file-lines
5757
" flag, it is not still enabled in the stable binaries.
58-
call codefmt#formatterhelpers#Format(maktaba#syscall#Create(l:cmd))
58+
call codefmt#formatterhelpers#Format(l:cmd)
5959
catch /ERROR(ShellError):/
6060
" Parse all the errors and stick them in the quickfix list.
6161
let l:errors = []

autoload/codefmt/shfmt.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function! codefmt#shfmt#GetFormatter() abort
5555
call codefmt#formatterhelpers#AttemptFakeRangeFormatting(
5656
\ a:startline,
5757
\ a:endline,
58-
\ maktaba#syscall#Create(l:cmd))
58+
\ l:cmd)
5959
catch /ERROR(ShellError):/
6060
" Parse all the errors and stick them in the quickfix list.
6161
let l:errors = []

doc/codefmt.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,22 @@ codefmt#FormatMap({type}) *codefmt#FormatMap()*
226226
ignored since formatting only works on complete lines.
227227

228228
codefmt#formatterhelpers#Format({cmd}) *codefmt#formatterhelpers#Format()*
229-
Format lines in the current buffer via a formatter invoked by {cmd} (a
230-
|maktaba.Syscall|). The command includes the explicit range line numbers to
231-
use, if any.
229+
Format lines in the current buffer via a formatter invoked by {cmd}, which
230+
is a system call represented by either a |maktaba.Syscall| or any argument
231+
accepted by |maktaba#syscall#Create()|. The command includes any arguments
232+
for the explicit range line numbers to use, if any.
232233

233234
Throws ERROR(ShellError) if the {cmd} system call fails
234235

235236
codefmt#formatterhelpers#AttemptFakeRangeFormatting({startline}, {endline},
236237
{cmd}) *codefmt#formatterhelpers#AttemptFakeRangeFormatting()*
237238
Attempt to format a range of lines from {startline} to {endline} in the
238239
current buffer via a formatter that doesn't natively support range
239-
formatting (invoked by {cmd}, a |maktaba.Syscall|), using a hacky strategy
240-
of sending those lines to the formatter in isolation.
240+
formatting, which is invoked via {cmd} (a system call represented by either
241+
a |maktaba.Syscall| or any argument accepted by |maktaba#syscall#Create()|).
242+
It uses a hacky strategy of sending those lines to the formatter in
243+
isolation, which gives bad results if the code on those lines isn't a
244+
self-contained block of syntax or is part of a larger indent.
241245

242246
If invoking this hack, please make sure to file a feature request against
243247
the tool for range formatting and post a URL for that feature request above

0 commit comments

Comments
 (0)