0
0
mirror of https://github.com/vim/vim.git synced 2025-11-14 23:04:02 -05:00

runtime(rust): Do not use rustfmt as 'formatprg' by default

This reverts commit 4ac995bf93.

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>
This commit is contained in:
Aaron Jacobs
2025-10-27 17:46:11 +00:00
committed by Christian Brabandt
parent 7d3b647f88
commit eba51337d4
3 changed files with 6 additions and 33 deletions

View File

@@ -3,7 +3,6 @@
" Maintainer: Chris Morgan <me@chrismorgan.info>
" Last Change: 2024 Mar 17
" 2024 May 23 by Riley Bruins <ribru17@gmail.com ('commentstring')
" 2025 Mar 31 by Vim project (set 'formatprg' option)
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
if exists("b:did_ftplugin")
@@ -58,19 +57,6 @@ setlocal includeexpr=rust#IncludeExpr(v:fname)
setlocal suffixesadd=.rs
if executable(get(g:, 'rustfmt_command', 'rustfmt'))
if get(g:, "rustfmt_fail_silently", 0)
augroup rust.vim.FailSilently
autocmd! * <buffer>
autocmd ShellFilterPost <buffer> if v:shell_error | execute 'echom "shell filter returned error " . v:shell_error . ", undoing changes"' | undo | endif
augroup END
endif
let &l:formatprg = get(g:, 'rustfmt_command', 'rustfmt') . ' ' .
\ get(g:, 'rustfmt_options', '') . ' ' .
\ rustfmt#RustfmtConfigOptions()
endif
if exists("g:ftplugin_rust_source_path")
let &l:path=g:ftplugin_rust_source_path . ',' . &l:path
endif
@@ -163,7 +149,7 @@ endif
let b:undo_ftplugin = "
\ compiler make |
\ setlocal formatoptions< comments< commentstring< include< includeexpr< suffixesadd< formatprg<
\ setlocal formatoptions< comments< commentstring< include< includeexpr< suffixesadd<
\|if exists('b:rust_set_style')
\|setlocal tabstop< shiftwidth< softtabstop< expandtab< textwidth<
\|endif