diff options
Diffstat (limited to 'autoload/rustfmt.vim')
-rw-r--r-- | autoload/rustfmt.vim | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/autoload/rustfmt.vim b/autoload/rustfmt.vim index 53ea9b28..514e4147 100644 --- a/autoload/rustfmt.vim +++ b/autoload/rustfmt.vim @@ -62,18 +62,19 @@ function! s:RustfmtWriteMode() endif endfunction -function! s:RustfmtConfig() +function! s:RustfmtConfigOptions() let l:rustfmt_toml = findfile('rustfmt.toml', expand('%:p:h') . ';') if l:rustfmt_toml !=# '' - return '--config-path '.l:rustfmt_toml + return '--config-path '.fnamemodify(l:rustfmt_toml, ":p") endif let l:_rustfmt_toml = findfile('.rustfmt.toml', expand('%:p:h') . ';') if l:_rustfmt_toml !=# '' - return '--config-path '.l:_rustfmt_toml + return '--config-path '.fnamemodify(l:_rustfmt_toml, ":p") endif - return '' + " Default to edition 2018 in case no rustfmt.toml was found. + return '--edition 2018' endfunction function! s:RustfmtCommandRange(filename, line1, line2) @@ -84,7 +85,7 @@ function! s:RustfmtCommandRange(filename, line1, line2) let l:arg = {"file": shellescape(a:filename), "range": [a:line1, a:line2]} let l:write_mode = s:RustfmtWriteMode() - let l:rustfmt_config = s:RustfmtConfig() + let l:rustfmt_config = s:RustfmtConfigOptions() " FIXME: When --file-lines gets to be stable, add version range checking " accordingly. @@ -98,14 +99,9 @@ function! s:RustfmtCommandRange(filename, line1, line2) endfunction function! s:RustfmtCommand() - if g:rustfmt_emit_files - let l:write_mode = "--emit=stdout" - else - let l:write_mode = "--write-mode=display" - endif - " rustfmt will pick on the right config on its own due to the - " current directory change. - return g:rustfmt_command . " ". l:write_mode . " " . g:rustfmt_options + let write_mode = g:rustfmt_emit_files ? '--emit=stdout' : '--write-mode=display' + let config = s:RustfmtConfigOptions() + return join([g:rustfmt_command, write_mode, config, g:rustfmt_options]) endfunction function! s:DeleteLines(start, end) abort |