Skip to content

Commit 0f37349

Browse files
mhinzda-x
authored andcommitted
RustFmt: use '--edition 2018' if no rustfmt.toml available
References rust-lang#368 [amended by [email protected]: due to lchdir inner function, we need to provide absolute paths of the rustfmt.toml file]
1 parent 05f9847 commit 0f37349

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

autoload/rustfmt.vim

+9-13
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,19 @@ function! s:RustfmtWriteMode()
6060
endif
6161
endfunction
6262

63-
function! s:RustfmtConfig()
63+
function! s:RustfmtConfigOptions()
6464
let l:rustfmt_toml = findfile('rustfmt.toml', expand('%:p:h') . ';')
6565
if l:rustfmt_toml !=# ''
66-
return '--config-path '.l:rustfmt_toml
66+
return '--config-path '.fnamemodify(l:rustfmt_toml, ":p")
6767
endif
6868

6969
let l:_rustfmt_toml = findfile('.rustfmt.toml', expand('%:p:h') . ';')
7070
if l:_rustfmt_toml !=# ''
71-
return '--config-path '.l:_rustfmt_toml
71+
return '--config-path '.fnamemodify(l:_rustfmt_toml, ":p")
7272
endif
7373

74-
return ''
74+
" Default to edition 2018 in case no rustfmt.toml was found.
75+
return '--edition 2018'
7576
endfunction
7677

7778
function! s:RustfmtCommandRange(filename, line1, line2)
@@ -82,7 +83,7 @@ function! s:RustfmtCommandRange(filename, line1, line2)
8283

8384
let l:arg = {"file": shellescape(a:filename), "range": [a:line1, a:line2]}
8485
let l:write_mode = s:RustfmtWriteMode()
85-
let l:rustfmt_config = s:RustfmtConfig()
86+
let l:rustfmt_config = s:RustfmtConfigOptions()
8687

8788
" FIXME: When --file-lines gets to be stable, add version range checking
8889
" accordingly.
@@ -96,14 +97,9 @@ function! s:RustfmtCommandRange(filename, line1, line2)
9697
endfunction
9798

9899
function! s:RustfmtCommand()
99-
if g:rustfmt_emit_files
100-
let l:write_mode = "--emit=stdout"
101-
else
102-
let l:write_mode = "--write-mode=display"
103-
endif
104-
" rustfmt will pick on the right config on its own due to the
105-
" current directory change.
106-
return g:rustfmt_command . " ". l:write_mode . " " . g:rustfmt_options
100+
let write_mode = g:rustfmt_emit_files ? '--emit=stdout' : '--write-mode=display'
101+
let config = s:RustfmtConfigOptions()
102+
return join([g:rustfmt_command, write_mode, config, g:rustfmt_options])
107103
endfunction
108104

109105
function! s:DeleteLines(start, end) abort

0 commit comments

Comments
 (0)