From ea82962b521a22776f084ffa335ade404ded8a3b Mon Sep 17 00:00:00 2001 From: cppcoffee Date: Sun, 13 Mar 2022 19:50:45 +0800 Subject: [PATCH 1/2] feat(rust): add global flag g:rustfmt_edition_opt --- README.md | 3 +++ autoload/neoformat/formatters/rust.vim | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 3379bea8..8cda9a0e 100644 --- a/README.md +++ b/README.md @@ -442,6 +442,9 @@ that caused Neoformat to be invoked. [`rubocop`](https://github.com/bbatsov/rubocop) - Rust - [`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) + ```vim + let g:rustfmt_edition_opt="2021" + ``` - Sass - [`sass-convert`](http://sass-lang.com/documentation/#executables), [`stylelint`](https://stylelint.io/), diff --git a/autoload/neoformat/formatters/rust.vim b/autoload/neoformat/formatters/rust.vim index 76254231..7377b5cb 100644 --- a/autoload/neoformat/formatters/rust.vim +++ b/autoload/neoformat/formatters/rust.vim @@ -3,8 +3,12 @@ function! neoformat#formatters#rust#enabled() abort endfunction function! neoformat#formatters#rust#rustfmt() abort + let opts = get(g:, 'rustfmt_edition_opt', '') + if opts != '' + let opts = '--edition ' . opts return { \ 'exe': 'rustfmt', + \ 'args': [opts], \ 'stdin': 1, \ } endfunction From 736140bcc3e4c7d0d89900abd5e0a68253891c7f Mon Sep 17 00:00:00 2001 From: cppcoffee Date: Tue, 15 Mar 2022 09:27:50 +0800 Subject: [PATCH 2/2] bugfix: fixed missing endif. --- autoload/neoformat/formatters/rust.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/autoload/neoformat/formatters/rust.vim b/autoload/neoformat/formatters/rust.vim index 7377b5cb..0dbcfb7c 100644 --- a/autoload/neoformat/formatters/rust.vim +++ b/autoload/neoformat/formatters/rust.vim @@ -6,6 +6,8 @@ function! neoformat#formatters#rust#rustfmt() abort let opts = get(g:, 'rustfmt_edition_opt', '') if opts != '' let opts = '--edition ' . opts + endif + return { \ 'exe': 'rustfmt', \ 'args': [opts],