Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 03b8f30

Browse files
Merge pull request #225 from malcolmr/fix-dartfmt-isavailable
Fix dartfmt's IsAvailable() method.
2 parents 4c23304 + cd29c3d commit 03b8f30

File tree

3 files changed

+49
-44
lines changed

3 files changed

+49
-44
lines changed

‎autoload/codefmt/dartfmt.vim‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,28 @@ function! codefmt#dartfmt#GetFormatter() abort
2626
\ 'https://dart.dev/get-dart'}
2727

2828
function l:formatter.IsAvailable() abort
29-
return executable(s:plugin.Flag('dartfmt_executable'))
29+
let l:cmd = codefmt#formatterhelpers#ResolveFlagToArray(
30+
\ 'dartfmt_executable')
31+
if !empty(l:cmd) && executable(l:cmd[0])
32+
return 1
33+
else
34+
return 0
35+
endif
3036
endfunction
3137

3238
function l:formatter.AppliesToBuffer() abort
3339
return codefmt#formatterhelpers#FiletypeMatches(&filetype, 'dart')
3440
endfunction
3541

3642
""
37-
" Reformat the current buffer with dartfmt or the binary named in
43+
" Reformat the current buffer with dart format or the binary named in
3844
" @flag(dartfmt_executable}, only targetting the range from {startline} to
3945
" {endline}
4046
function l:formatter.FormatRange(startline, endline) abort
41-
let l:dartfmt_executable = s:plugin.Flag('dartfmt_executable')
42-
if type(l:dartfmt_executable) is# type([])
43-
let l:cmd = l:dartfmt_executable
44-
elseif type(l:dartfmt_executable) is# type('')
45-
let l:cmd = [l:dartfmt_executable]
46-
else
47-
throw maktaba#error#WrongType(
48-
\ 'dartfmt_executable flag must be a list or string. Found %s',
49-
\ string(l:dartfmt_executable))
50-
endif
47+
let l:cmd = codefmt#formatterhelpers#ResolveFlagToArray(
48+
\ 'dartfmt_executable')
5149
try
52-
" dartfmt does not support range formatting yet:
50+
" dart format does not support range formatting yet:
5351
" https://github.com/dart-lang/dart_style/issues/92
5452
call codefmt#formatterhelpers#AttemptFakeRangeFormatting(
5553
\ a:startline, a:endline, l:cmd)
@@ -86,4 +84,3 @@ function! codefmt#dartfmt#GetFormatter() abort
8684

8785
return l:formatter
8886
endfunction
89-

‎doc/codefmt.txt‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Default: 'autopep8' `
6868

6969
*codefmt:clang_format_executable*
7070
The path to the clang-format executable. String, list, or callable that takes
71-
no args and returns a string or a list.
71+
no args and returns a string or a list with command line arguments.
7272
Default: 'clang-format' `
7373

7474
*codefmt:clang_format_style*
@@ -84,15 +84,17 @@ additionally adjust imports when formatting.
8484
Default: 'gofmt' `
8585

8686
*codefmt:dartfmt_executable*
87-
The path to the dartfmt executable. Either a list or a string.
87+
The path to the dartfmt executable. String, list, or callable that takes no
88+
args and returns a string or a list with command line arguments.
8889
Default: ['dart', 'format'] `
8990

9091
*codefmt:js_beautify_executable*
9192
The path to the js-beautify executable.
9293
Default: 'js-beautify' `
9394

9495
*codefmt:mix_executable*
95-
The path to the mix executable for Elixir.
96+
The path to the mix executable for Elixir. String, list, or callable that
97+
takes no args and returns a string or a list with command line arguments.
9698
Default: 'mix' `
9799

98100
*codefmt:yapf_executable*
@@ -153,9 +155,10 @@ The path to the google-java executable. Generally, this should have the form:
153155
Default: 'google-java-format' `
154156

155157
*codefmt:ktfmt_executable*
156-
The path to the ktfmt executable with args, as a list. The default value
157-
assumes there is a wrapper script named `ktfmt`. Without such a script, this
158-
will generally have the form:
158+
The path to the ktfmt executable with args. String, list, or callable that
159+
takes no args and returns a string or a list with command line arguments. The
160+
default value assumes there is a wrapper script named `ktfmt`. Without such a
161+
script, this will generally have the form:
159162
`ktfmt_executable=java,-jar,/path/to/ktfmt-VERSION-jar-with-dependencies.jar`
160163

161164
Note that range formatting is not fully supported, with a feature request at
@@ -165,14 +168,14 @@ surrounding blocks.
165168
Default: ['ktfmt'] `
166169

167170
*codefmt:shfmt_options*
168-
Command line arguments to feed shfmt. Either a list or callable that takes no
169-
args and returns a list with command line arguments. By default, uses the
170-
Google's style. See https://github.com/mvdan/sh for details.
171+
Command line arguments to feed shfmt. String, list, or callable that takes no
172+
args and returns a string or a list with command line arguments. By default,
173+
uses the Google style. See https://github.com/mvdan/sh for details.
171174
Default: ['-i', '2', '-sr', '-ci'] `
172175

173176
*codefmt:shfmt_executable*
174177
The path to the shfmt executable. String, list, or callable that takes no args
175-
and returns a string or a list.
178+
and returns a string or a list with command line arguments.
176179
Default: 'shfmt' `
177180

178181
*codefmt:prettier_options*
@@ -190,8 +193,9 @@ Default: 'rubocop' `
190193

191194
*codefmt:prettier_executable*
192195
The path to the prettier executable. String, list, or callable that takes no
193-
args and returns a string or a list. The default uses npx if available, so
194-
that the repository-local prettier will have priority.
196+
args and returns a string or a list with command line arguments. The default
197+
uses npx if available, so that the repository-local prettier will have
198+
priority.
195199
Default: function('s:LookupPrettierExecutable') `
196200

197201
*codefmt:rustfmt_options*
@@ -204,9 +208,9 @@ The path to the rustfmt executable.
204208
Default: 'rustfmt' `
205209

206210
*codefmt:zprint_options*
207-
Command line arguments to feed zprint. Either a list or callable that takes no
208-
args and returns a list with command line arguments. The default configures
209-
zprint with Vim's textwidth.
211+
Command line arguments to feed zprint. String, list, or callable that takes no
212+
args and returns a string or a list with command line arguments. The default
213+
configures zprint with Vim's textwidth.
210214
Default: function('s:ZprintOptions') `
211215

212216
*codefmt:zprint_executable*

‎instant/flags.vim‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ call s:plugin.flags.autopep8_executable.AddCallback(
5353

5454
""
5555
" The path to the clang-format executable. String, list, or callable that
56-
" takes no args and returns a string or a list.
56+
" takes no args and returns a string or a list with command line arguments.
5757
call s:plugin.Flag('clang_format_executable', 'clang-format')
5858
" Invalidate cache of detected clang-format version when this is changed,
5959
" regardless of {value} arg.
@@ -73,7 +73,8 @@ call s:plugin.Flag('clang_format_style', 'file')
7373
call s:plugin.Flag('gofmt_executable', 'gofmt')
7474

7575
""
76-
" The path to the dartfmt executable. Either a list or a string.
76+
" The path to the dartfmt executable. String, list, or callable that takes no
77+
" args and returns a string or a list with command line arguments.
7778
call s:plugin.Flag('dartfmt_executable', ['dart', 'format'])
7879

7980

@@ -82,7 +83,8 @@ call s:plugin.Flag('dartfmt_executable', ['dart', 'format'])
8283
call s:plugin.Flag('js_beautify_executable', 'js-beautify')
8384

8485
""
85-
" The path to the mix executable for Elixir.
86+
" The path to the mix executable for Elixir. String, list, or callable that
87+
" takes no args and returns a string or a list with command line arguments.
8688
call s:plugin.Flag('mix_executable', 'mix')
8789

8890
""
@@ -143,9 +145,10 @@ call s:plugin.Flag('jsonnetfmt_executable', 'jsonnetfmt')
143145
call s:plugin.Flag('google_java_executable', 'google-java-format')
144146

145147
""
146-
" The path to the ktfmt executable with args, as a list. The default value
147-
" assumes there is a wrapper script named `ktfmt`. Without such a script, this
148-
" will generally have the form:
148+
" The path to the ktfmt executable with args. String, list, or callable that
149+
" takes no args and returns a string or a list with command line arguments.
150+
" The default value assumes there is a wrapper script named `ktfmt`. Without
151+
" such a script, this will generally have the form:
149152
" `ktfmt_executable=java,-jar,/path/to/ktfmt-VERSION-jar-with-dependencies.jar`
150153
"
151154
" Note that range formatting is not fully supported, with a feature request at
@@ -155,15 +158,15 @@ call s:plugin.Flag('google_java_executable', 'google-java-format')
155158
call s:plugin.Flag('ktfmt_executable', ['ktfmt'])
156159

157160
""
158-
" Command line arguments to feed shfmt. Either a list or callable that
159-
" takes no args and returns a list with command line arguments. By default, uses
160-
" the Google's style.
161+
" Command line arguments to feed shfmt. String, list, or callable that
162+
" takes no args and returns a string or a list with command line arguments.
163+
" By default, uses the Google style.
161164
" See https://github.com/mvdan/sh for details.
162165
call s:plugin.Flag('shfmt_options', ['-i', '2', '-sr', '-ci'])
163166

164167
""
165168
" The path to the shfmt executable. String, list, or callable that
166-
" takes no args and returns a string or a list.
169+
" takes no args and returns a string or a list with command line arguments.
167170
call s:plugin.Flag('shfmt_executable', 'shfmt')
168171

169172
""
@@ -187,8 +190,9 @@ endfunction
187190

188191
""
189192
" The path to the prettier executable. String, list, or callable that
190-
" takes no args and returns a string or a list. The default uses npx if
191-
" available, so that the repository-local prettier will have priority.
193+
" takes no args and returns a string or a list with command line arguments.
194+
" The default uses npx if available, so that the repository-local prettier
195+
" will have priority.
192196
call s:plugin.Flag('prettier_executable', function('s:LookupPrettierExecutable'))
193197

194198
" Invalidate cache of detected prettier availability whenever
@@ -214,9 +218,9 @@ function s:ZprintOptions() abort
214218
endfunction
215219

216220
""
217-
" Command line arguments to feed zprint. Either a list or callable that takes no
218-
" args and returns a list with command line arguments. The default configures
219-
" zprint with Vim's textwidth.
221+
" Command line arguments to feed zprint. String, list, or callable that
222+
" takes no args and returns a string or a list with command line arguments.
223+
" The default configures zprint with Vim's textwidth.
220224
call s:plugin.Flag('zprint_options', function('s:ZprintOptions'))
221225

222226
""

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /