1616let s: plugin = maktaba#plugin#Get (' codefmt' )
1717
1818" See https://prettier.io for a list of supported file types.
19- let s: supported_filetypes = [' javascript' , ' markdown' , ' html' , ' css' , ' yaml' ,
19+ let s: supported_filetypes = [' javascript' , ' markdown' , ' html' , ' css' , ' yaml' ,
2020 \ ' jsx' , ' less' , ' scss' , ' mdx' , ' vue' ]
2121
2222
@@ -30,7 +30,9 @@ function! codefmt#prettier#GetFormatter() abort
3030 \ ' and configure the prettier_executable flag' }
3131
3232 function l: formatter .IsAvailable () abort
33- return executable (s: plugin .Flag (' prettier_executable' ))
33+ let l: cmd = codefmt#formatterhelpers#ResolveFlagToArray (
34+ \ ' prettier_executable' )
35+ return ! empty (l: cmd ) && executable (l: cmd [0 ])
3436 endfunction
3537
3638 function l: formatter .AppliesToBuffer () abort
@@ -42,17 +44,8 @@ function! codefmt#prettier#GetFormatter() abort
4244 " @flag(prettier_executable), only targeting the range between {startline} and
4345 " {endline}.
4446 function l: formatter .FormatRange (startline, endline) abort
45- let l: Prettier_options = s: plugin .Flag (' prettier_options' )
46- if type (l: Prettier_options ) is # type ([])
47- let l: prettier_options = l: Prettier_options
48- elseif maktaba#value#IsCallable (l: Prettier_options )
49- let l: prettier_options = maktaba#function#Call (l: Prettier_options )
50- else
51- throw maktaba#error#WrongType (
52- \ ' prettier_options flag must be list or callable. Found %s' ,
53- \ string (l: Prettier_options ))
54- endif
55- let l: cmd = [s: plugin .Flag (' prettier_executable' ), ' --stdin' , ' --no-color' ]
47+ let l: cmd = codefmt#formatterhelpers#ResolveFlagToArray (
48+ \ ' prettier_executable' ) + [' --stdin' , ' --no-color' ]
5649
5750 " prettier is able to automatically choose the best parser if the filepath
5851 " is provided. Otherwise, fall back to the previous default: babylon.
@@ -74,7 +67,9 @@ function! codefmt#prettier#GetFormatter() abort
7467 let l: lines_end = join (l: lines [0 : a: endline - 1 ], " \n " )
7568 call extend (l: cmd , [' --range-end' , string (strchars (l: lines_end ))])
7669
77- call extend (l: cmd , l: prettier_options )
70+ call extend (l: cmd , codefmt#formatterhelpers#ResolveFlagToArray (
71+ \ ' prettier_options' ))
72+
7873 try
7974 let l: result = maktaba#syscall#Create (l: cmd ).WithStdin (l: input ).Call ()
8075 let l: formatted = split (l: result .stdout, " \n " )
0 commit comments