Skip to content

Commit a61b88a

Browse files
committed
Add an option to let rustfmt 0.7 work
Added an option to let this plugin work with both rustfmt < 0.6 and >= 0.7. Fixes rust-lang#212
1 parent 8e75da9 commit a61b88a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

autoload/rustfmt.vim

+16-2
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,29 @@ if !exists("g:rustfmt_fail_silently")
1919
let g:rustfmt_fail_silently = 0
2020
endif
2121

22+
if !exists("g:rustfmt_emit_files")
23+
let g:rustfmt_emit_files = 0
24+
endif
25+
2226
let s:got_fmt_error = 0
2327

28+
function! s:RustfmtWriteMode()
29+
if g:rustfmt_emit_files
30+
return "--emit=files"
31+
else
32+
return "--write-mode=overwrite"
33+
endif
34+
endfunction
35+
2436
function! s:RustfmtCommandRange(filename, line1, line2)
2537
let l:arg = {"file": shellescape(a:filename), "range": [a:line1, a:line2]}
26-
return printf("%s %s --write-mode=overwrite --file-lines '[%s]'", g:rustfmt_command, g:rustfmt_options, json_encode(l:arg))
38+
let l:write_mode = s:RustfmtWriteMode()
39+
return printf("%s %s %s --file-lines '[%s]'", g:rustfmt_command, l:write_mode, g:rustfmt_options, json_encode(l:arg))
2740
endfunction
2841

2942
function! s:RustfmtCommand(filename)
30-
return g:rustfmt_command . " --write-mode=overwrite " . g:rustfmt_options . " " . shellescape(a:filename)
43+
let l:write_mode = s:RustfmtWriteMode()
44+
return g:rustfmt_command . " ". l:write_mode . " " . g:rustfmt_options . " " . shellescape(a:filename)
3145
endfunction
3246

3347
function! s:RunRustfmt(command, curw, tmpname)

doc/rust.txt

+7
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ g:rustfmt_options~
113113
defaults to '' : >
114114
let g:rustfmt_options = ''
115115
<
116+
*g:rustfmt_emit_files*
117+
g:rustfmt_emit_files~
118+
Set this option to 1 to run rustfmt with '--emit=files' instead of
119+
'--write-mode=overwrite'. Necessary for rustfmt >= 0.7.0
120+
If not specified it defaults to 0 : >
121+
let g:rustfmt_emit_files = 0
122+
<
116123

117124
*g:rust_playpen_url*
118125
g:rust_playpen_url~

0 commit comments

Comments
 (0)