@@ -60,18 +60,19 @@ function! s:RustfmtWriteMode()
60
60
endif
61
61
endfunction
62
62
63
- function ! s: RustfmtConfig ()
63
+ function ! s: RustfmtConfigOptions ()
64
64
let l: rustfmt_toml = findfile (' rustfmt.toml' , expand (' %:p:h' ) . ' ;' )
65
65
if l: rustfmt_toml !=# ' '
66
- return ' --config-path ' .l: rustfmt_toml
66
+ return ' --config-path ' .fnamemodify ( l: rustfmt_toml, " :p " )
67
67
endif
68
68
69
69
let l: _rustfmt_toml = findfile (' .rustfmt.toml' , expand (' %:p:h' ) . ' ;' )
70
70
if l: _rustfmt_toml !=# ' '
71
- return ' --config-path ' .l: _rustfmt_toml
71
+ return ' --config-path ' .fnamemodify ( l: _rustfmt_toml, " :p " )
72
72
endif
73
73
74
- return ' '
74
+ " Default to edition 2018 in case no rustfmt.toml was found.
75
+ return ' --edition 2018'
75
76
endfunction
76
77
77
78
function ! s: RustfmtCommandRange (filename, line1, line2)
@@ -82,7 +83,7 @@ function! s:RustfmtCommandRange(filename, line1, line2)
82
83
83
84
let l: arg = {" file" : shellescape (a: filename ), " range" : [a: line1 , a: line2 ]}
84
85
let l: write_mode = s: RustfmtWriteMode ()
85
- let l: rustfmt_config = s: RustfmtConfig ()
86
+ let l: rustfmt_config = s: RustfmtConfigOptions ()
86
87
87
88
" FIXME: When --file-lines gets to be stable, add version range checking
88
89
" accordingly.
@@ -96,14 +97,9 @@ function! s:RustfmtCommandRange(filename, line1, line2)
96
97
endfunction
97
98
98
99
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 ])
107
103
endfunction
108
104
109
105
function ! s: DeleteLines (start , end ) abort
0 commit comments