11" Author: Stephen Sugden <[email protected] >22" Last Modified: 2023-09-11
3- " Last Change: 2025 Mar 31 by Vim project (rename s:RustfmtConfigOptions())
3+ " 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)
46"
57" Adapted from https://github.com/fatih/vim-go
68" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
@@ -22,6 +24,12 @@ if !exists("g:rustfmt_fail_silently")
2224endif
2325
2426function ! rustfmt#DetectVersion ()
27+ let s: rustfmt_version = " 0"
28+ let s: rustfmt_help = " "
29+ let s: rustfmt_unstable_features = " "
30+ if ! get (g: , ' rustfmt_detect_version' , 0 )
31+ return s: rustfmt_version
32+ endif
2533 " Save rustfmt '--help' for feature inspection
2634 silent let s: rustfmt_help = system (g: rustfmt_command . " --help" )
2735 let s: rustfmt_unstable_features = s: rustfmt_help = ~# " --unstable-features"
@@ -30,9 +38,7 @@ function! rustfmt#DetectVersion()
3038 silent let l: rustfmt_version_full = system (g: rustfmt_command . " --version" )
3139 let l: rustfmt_version_list = matchlist (l: rustfmt_version_full ,
3240 \ ' \vrustfmt ([0-9]+[.][0-9]+[.][0-9]+)' )
33- if len (l: rustfmt_version_list ) < 3
34- let s: rustfmt_version = " 0"
35- else
41+ if len (l: rustfmt_version_list ) >= 3
3642 let s: rustfmt_version = l: rustfmt_version_list [1 ]
3743 endif
3844 return s: rustfmt_version
@@ -63,6 +69,12 @@ function! s:RustfmtWriteMode()
6369endfunction
6470
6571function ! rustfmt#RustfmtConfigOptions ()
72+ let default = ' --edition 2018'
73+
74+ if ! get (g: , ' rustfmt_find_toml' , 0 )
75+ return default
76+ endif
77+
6678 let l: rustfmt_toml = findfile (' rustfmt.toml' , expand (' %:p:h' ) . ' ;' )
6779 if l: rustfmt_toml !=# ' '
6880 return ' --config-path ' .shellescape (fnamemodify (l: rustfmt_toml , " :p" ))
@@ -74,7 +86,7 @@ function! rustfmt#RustfmtConfigOptions()
7486 endif
7587
7688 " Default to edition 2018 in case no rustfmt.toml was found.
77- return ' --edition 2018 '
89+ return default
7890endfunction
7991
8092function ! s: RustfmtCommandRange (filename, line1, line2)
0 commit comments