Skip to content

Commit eba5133

Browse files
jacobsachrisbra
authored andcommitted
runtime(rust): Do not use rustfmt as 'formatprg' by default
This reverts commit 4ac995b. This was added in #16807, with no explanation for why it was necessary beyond "it's an example of an idea". It completely breaks `gq` for me—rustfmt doesn't reflow comments so is not an appropriate tool here! Beyond that, formatting a selection with rustfmt treats that selection as if it were an entire file, throwing away any indentation. For example, the commit causes `gq` to turn this: ```rust pub fn foo() { // blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah } ``` into this: ```rust pub fn foo() { // blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah } ``` which is totally wrong. In contrast, if I clear `formatprg` then `gq` does the right thing again: ```rust pub fn foo() { // blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah // blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah // blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah // blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah // blah blah blah blah blah blah } ``` related: #16967 related: #17055 closes: #18640 Signed-off-by: Aaron Jacobs <jacobsa@google.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 7d3b647 commit eba5133

File tree

3 files changed

+6
-33
lines changed

3 files changed

+6
-33
lines changed

runtime/autoload/rustfmt.vim

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
" Author: Stephen Sugden <stephen@stephensugden.com>
22
" Last Modified: 2023-09-11
33
" Last Change:
4-
" 2025 Mar 31 by Vim project (rename s:RustfmtConfigOptions())
5-
" 2025 Jul 14 by Vim project (don't parse rustfmt version automatically #17745)
4+
" 2025 Oct 27 by Vim project don't use rustfmt as 'formatprg' by default
5+
"
66
"
77
" Adapted from https://github.com/fatih/vim-go
88
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
@@ -68,13 +68,7 @@ function! s:RustfmtWriteMode()
6868
endif
6969
endfunction
7070

71-
function! rustfmt#RustfmtConfigOptions()
72-
let default = '--edition 2018'
73-
74-
if !get(g:, 'rustfmt_find_toml', 0)
75-
return default
76-
endif
77-
71+
function! s:RustfmtConfigOptions()
7872
let l:rustfmt_toml = findfile('rustfmt.toml', expand('%:p:h') . ';')
7973
if l:rustfmt_toml !=# ''
8074
return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p"))
@@ -97,7 +91,7 @@ function! s:RustfmtCommandRange(filename, line1, line2)
9791

9892
let l:arg = {"file": shellescape(a:filename), "range": [a:line1, a:line2]}
9993
let l:write_mode = s:RustfmtWriteMode()
100-
let l:rustfmt_config = rustfmt#RustfmtConfigOptions()
94+
let l:rustfmt_config = s:RustfmtConfigOptions()
10195

10296
" FIXME: When --file-lines gets to be stable, add version range checking
10397
" accordingly.
@@ -112,7 +106,7 @@ endfunction
112106

113107
function! s:RustfmtCommand()
114108
let write_mode = g:rustfmt_emit_files ? '--emit=stdout' : '--write-mode=display'
115-
let config = rustfmt#RustfmtConfigOptions()
109+
let config = s:RustfmtConfigOptions()
116110
return join([g:rustfmt_command, write_mode, config, g:rustfmt_options])
117111
endfunction
118112

runtime/doc/ft_rust.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,6 @@ g:rustfmt_detect_version~
166166
Disabled by default for performance reasons
167167
>
168168
let g:rustfmt_detect_version = 1
169-
<
170-
*g:rustfmt_find_toml*
171-
g:rustfmt_emit_files~
172-
When set to 1, will try to find "rustfmt.toml" file by searching from
173-
current path upwards. Disabled by default for performance reasons
174-
>
175-
let g:rustfmt_find_toml = 1
176169
<
177170
*g:rust_playpen_url*
178171
g:rust_playpen_url~

runtime/ftplugin/rust.vim

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
" Maintainer: Chris Morgan <me@chrismorgan.info>
44
" Last Change: 2024 Mar 17
55
" 2024 May 23 by Riley Bruins <ribru17@gmail.com ('commentstring')
6-
" 2025 Mar 31 by Vim project (set 'formatprg' option)
76
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
87

98
if exists("b:did_ftplugin")
@@ -58,19 +57,6 @@ setlocal includeexpr=rust#IncludeExpr(v:fname)
5857

5958
setlocal suffixesadd=.rs
6059

61-
if executable(get(g:, 'rustfmt_command', 'rustfmt'))
62-
if get(g:, "rustfmt_fail_silently", 0)
63-
augroup rust.vim.FailSilently
64-
autocmd! * <buffer>
65-
autocmd ShellFilterPost <buffer> if v:shell_error | execute 'echom "shell filter returned error " . v:shell_error . ", undoing changes"' | undo | endif
66-
augroup END
67-
endif
68-
69-
let &l:formatprg = get(g:, 'rustfmt_command', 'rustfmt') . ' ' .
70-
\ get(g:, 'rustfmt_options', '') . ' ' .
71-
\ rustfmt#RustfmtConfigOptions()
72-
endif
73-
7460
if exists("g:ftplugin_rust_source_path")
7561
let &l:path=g:ftplugin_rust_source_path . ',' . &l:path
7662
endif
@@ -163,7 +149,7 @@ endif
163149

164150
let b:undo_ftplugin = "
165151
\ compiler make |
166-
\ setlocal formatoptions< comments< commentstring< include< includeexpr< suffixesadd< formatprg<
152+
\ setlocal formatoptions< comments< commentstring< include< includeexpr< suffixesadd<
167153
\|if exists('b:rust_set_style')
168154
\|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth<
169155
\|endif

0 commit comments

Comments
 (0)