@@ -157,11 +157,23 @@ if !exists('s:gofmt')
157157endif 
158158
159159
160+ " "
161+ "  Checks whether {formatter} is available.
162+ "  NOTE:  If @function(#DisableIsAvailableChecksForTesting) has been called, skips
163+ "  the IsAvailable check and always returns true.
164+ function !  s: IsAvailableabort 
165+  if  get (s: ' check_formatters_available' 1 )
166+  return  a: formatterIsAvailable ()
167+  endif 
168+  return  1 
169+ endfunction 
170+ 171+ 160172" "
161173"  Detects whether a formatter has been defined for the current buffer/filetype.
162174function !  codefmt#IsFormatterAvailable () abort 
163175 let  l: formatters=  copy (codefmtlib#GetFormatters ())
164-  let  l: is_available=  ' v:val.AppliesToBuffer() && v:val. IsAvailable()' 
176+  let  l: is_available=  ' v:val.AppliesToBuffer() && s: IsAvailable(v:val )' 
165177 return  ! empty (filter (l: formattersl: is_available|| 
166178 \  ! empty (get (b: ' codefmt_formatter' 
167179endfunction 
@@ -187,7 +199,7 @@ function! s:GetFormatter(...) abort
187199 return 
188200 endif 
189201 let  l: formatter=  l: selected_formatters0 ]
190-  if  ! l: formatter . IsAvailable ()
202+  if  ! s: IsAvailablel: formatter 
191203 "  Not available. Print setup instructions if possible. 
192204 let  l: error=  ' Formatter "%s" is not available.' 
193205 if  has_key (l: formatter' setup_instructions' 
@@ -199,7 +211,7 @@ function! s:GetFormatter(...) abort
199211 else 
200212 "  No explicit name, use default. 
201213 let  l: default_formatters=  filter (
202-  \  copy (l: formatters' v:val.AppliesToBuffer() && v:val. IsAvailable()' 
214+  \  copy (l: formatters' v:val.AppliesToBuffer() && s: IsAvailable(v:val )' 
203215 if  ! empty (l: default_formatters
204216 let  l: formatter=  l: default_formatters0 ]
205217 else 
@@ -272,15 +284,15 @@ endfunction
272284"  @public
273285"  Suitable for use as 'operatorfunc'; see |g@| for details.
274286"  The type is ignored since formatting only works on complete lines.
275- function !  codefmt#FormatMap (type ) range 
287+ function !  codefmt#FormatMap (type ) range abort 
276288 call  codefmt#FormatLines (line (" '[" line (" ']" 
277289endfunction 
278290
279291" "
280292"  Generate the completion for supported formatters. Lists available formatters
281293"  that apply to the current buffer first, then unavailable formatters that
282294"  apply, then everything else.
283- function !  codefmt#GetSupportedFormatters (ArgLead, CmdLine, CursorPos)
295+ function !  codefmt#GetSupportedFormatters (ArgLead, CmdLine, CursorPos)abort 
284296 let  l: groups=  [[], [], []]
285297 for  l: formatterin  codefmtlib#GetFormatters ()
286298 let  l: key=  l: formatterAppliesToBuffer () ? (
@@ -290,3 +302,11 @@ function! codefmt#GetSupportedFormatters(ArgLead, CmdLine, CursorPos)
290302 return  join (l: groups0 ] +  l: groups1 ] +  l: groups2 ], " \n " 
291303endfunction 
292304
305+ 306+ " "
307+ "  @private
308+ "  Bypasses FORMATTER.IsAvailable checks and assumes every formatter is available
309+ "  to avoid checking for executables on the path.
310+ function !  codefmt#DisableIsAvailableChecksForTesting () abort 
311+  let  s: check_formatters_available=  0 
312+ endfunction 
0 commit comments