Skip to content

Commit c15243a

Browse files
committed
added fix for composite filetypes
Now, instead of spitting an error message into (n)vim's messages, the composite filetype is split and the first filetype is used. e.g. `javascript.jsx` --> `javascript`
1 parent f70ea87 commit c15243a

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

autoload/neoformat.vim

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ function! neoformat#Neoformat(user_formatter) abort
1212
if !empty(a:user_formatter)
1313
let formatter = a:user_formatter
1414
else
15-
let formatters = s:get_enabled_formatters(&filetype)
15+
let filetype = s:split_filetypes(&filetype)
16+
let formatters = s:get_enabled_formatters(filetype)
1617
if formatters == []
17-
call neoformat#utils#msg('formatter not defined for ' . &filetype . ' filetype')
18+
call neoformat#utils#msg('formatter not defined for ' . filetype . ' filetype')
1819
return neoformat#format#BasicFormat()
1920
endif
2021

@@ -26,10 +27,10 @@ function! neoformat#Neoformat(user_formatter) abort
2627
let formatter = formatters[s:current_formatter_index]
2728
endif
2829

29-
if exists('g:neoformat_' . &filetype . '_' . formatter)
30-
let definition = g:neoformat_{&filetype}_{formatter}
31-
elseif s:autoload_func_exists('neoformat#formatters#' . &filetype . '#' . formatter)
32-
let definition = neoformat#formatters#{&filetype}#{formatter}()
30+
if exists('g:neoformat_' . filetype . '_' . formatter)
31+
let definition = g:neoformat_{filetype}_{formatter}
32+
elseif s:autoload_func_exists('neoformat#formatters#' . filetype . '#' . formatter)
33+
let definition = neoformat#formatters#{filetype}#{formatter}()
3334
else
3435
call neoformat#utils#log('definition not found for formatter: ' . formatter)
3536
if !empty(a:user_formatter)
@@ -39,7 +40,7 @@ function! neoformat#Neoformat(user_formatter) abort
3940
return neoformat#NextNeoformat()
4041
endif
4142

42-
let cmd = neoformat#cmd#generate(definition)
43+
let cmd = neoformat#cmd#generate(definition, filetype)
4344
if cmd == {}
4445
if !empty(a:user_formatter)
4546
return neoformat#utils#log('user specified formatter failed')
@@ -63,7 +64,8 @@ function! neoformat#CompleteFormatters(ArgLead, CmdLine, CursorPos)
6364
if a:ArgLead =~ '[^A-Za-z0-9]'
6465
return []
6566
endif
66-
return filter(s:get_enabled_formatters(&filetype),
67+
let filetype = s:split_filetypes(&filetype)
68+
return filter(s:get_enabled_formatters(filetype),
6769
\ "v:val =~? '^" . a:ArgLead ."'")
6870
endfunction
6971

@@ -81,3 +83,7 @@ function! s:autoload_func_exists(func_name)
8183
endtry
8284
return 1
8385
endfunction
86+
87+
function! s:split_filetypes(filetype)
88+
return split(a:filetype, '\.')[0]
89+
endfunction

autoload/neoformat/cmd.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function! neoformat#cmd#generate(definition) abort
1+
function! neoformat#cmd#generate(definition, filetype) abort
22
let cmd = get(a:definition, 'exe', '')
33
if cmd == ''
44
call neoformat#utils#log('no exe field in definition')
@@ -51,7 +51,7 @@ function! neoformat#cmd#generate(definition) abort
5151
\ 'no_append': no_append,
5252
\ 'path': path,
5353
\ 'replace': replace,
54-
\ 'filetype': &filetype
54+
\ 'filetype': a:filetype
5555
\ }
5656
endfunction
5757

0 commit comments

Comments
 (0)