Skip to content

Commit 1afe8c3

Browse files
committed
runtime(rust): improve loading time
fixes: #17745 closes: #17749 Signed-off-by: Christian Brabandt <[email protected]>
1 parent 31ec664 commit 1afe8c3

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

runtime/autoload/rustfmt.vim

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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")
2224
endif
2325

2426
function! 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()
6369
endfunction
6470

6571
function! 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
7890
endfunction
7991

8092
function! s:RustfmtCommandRange(filename, line1, line2)

runtime/doc/ft_rust.txt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,20 @@ g:rustfmt_emit_files~
159159
determines whether to run rustfmt with '--emit=files' (when 1 is
160160
provided) instead of '--write-mode=overwrite'. >
161161
let g:rustfmt_emit_files = 0
162-
162+
<
163+
*g:rustfmt_detect_version*
164+
g:rustfmt_detect_version~
165+
When set to 1, will try to parse the version output from "rustfmt".
166+
Disabled by default for performance reasons
167+
>
168+
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
163176
<
164177
*g:rust_playpen_url*
165178
g:rust_playpen_url~

runtime/doc/tags

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7851,8 +7851,10 @@ g:rustc_path ft_rust.txt /*g:rustc_path*
78517851
g:rustfmt_autosave ft_rust.txt /*g:rustfmt_autosave*
78527852
g:rustfmt_autosave_if_config_present ft_rust.txt /*g:rustfmt_autosave_if_config_present*
78537853
g:rustfmt_command ft_rust.txt /*g:rustfmt_command*
7854+
g:rustfmt_detect_version ft_rust.txt /*g:rustfmt_detect_version*
78547855
g:rustfmt_emit_files ft_rust.txt /*g:rustfmt_emit_files*
78557856
g:rustfmt_fail_silently ft_rust.txt /*g:rustfmt_fail_silently*
7857+
g:rustfmt_find_toml ft_rust.txt /*g:rustfmt_find_toml*
78567858
g:rustfmt_options ft_rust.txt /*g:rustfmt_options*
78577859
g:statusline_winid options.txt /*g:statusline_winid*
78587860
g:syntax_on syntax.txt /*g:syntax_on*

0 commit comments

Comments
 (0)