runtime(rust): improve loading time
Commit:
https://github.com/vim/vim/commit/1afe8c3a4d9d61a4762c11ddf4c50050a92bd23e
Author: Christian Brabandt <[email protected]>
Date: Sun Jul 20 10:38:16 2025 +0200
runtime(rust): improve loading time
fixes: https://github.com/vim/vim/issues/17745
closes: https://github.com/vim/vim/issues/17749
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/autoload/rustfmt.vim b/runtime/autoload/rustfmt.vim
index f325df2fd..847b698b7 100644
--- a/runtime/autoload/rustfmt.vim
+++ b/runtime/autoload/rustfmt.vim
@@ -1,6 +1,8 @@
" Author: Stephen Sugden <[email protected]>
" Last Modified: 2023-09-11
-" Last Change: 2025 Mar 31 by Vim project (rename s:RustfmtConfigOptions())
+" Last Change:
+" 2025 Mar 31 by Vim project (rename s:RustfmtConfigOptions())
+" 2025 Jul 14 by Vim project (don't parse rustfmt version automatically #17745)
"
" Adapted from https://github.com/fatih/vim-go
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
@@ -22,6 +24,12 @@ if !exists("g:rustfmt_fail_silently")
endif
function! rustfmt#DetectVersion()
+ let s:rustfmt_version = "0"
+ let s:rustfmt_help = ""
+ let s:rustfmt_unstable_features = ""
+ if !get(g:, 'rustfmt_detect_version', 0)
+ return s:rustfmt_version
+ endif
" Save rustfmt '--help' for feature inspection
silent let s:rustfmt_help = system(g:rustfmt_command . " --help")
let s:rustfmt_unstable_features = s:rustfmt_help =~# "--unstable-features"
@@ -30,9 +38,7 @@ function! rustfmt#DetectVersion()
silent let l:rustfmt_version_full = system(g:rustfmt_command . "
--version")
let l:rustfmt_version_list = matchlist(l:rustfmt_version_full,
\ ' rustfmt ([0-9]+[.][0-9]+[.][0-9]+)')
- if len(l:rustfmt_version_list) < 3
- let s:rustfmt_version = "0"
- else
+ if len(l:rustfmt_version_list) >= 3
let s:rustfmt_version = l:rustfmt_version_list[1]
endif
return s:rustfmt_version
@@ -63,6 +69,12 @@ function! s:RustfmtWriteMode()
endfunction
function! rustfmt#RustfmtConfigOptions()
+ let default = '--edition 2018'
+
+ if !get(g:, 'rustfmt_find_toml', 0)
+ return default
+ endif
+
let l:rustfmt_toml = findfile('rustfmt.toml', expand('%:p:h') . ';')
if l:rustfmt_toml !=# ''
return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p"))
@@ -74,7 +86,7 @@ function! rustfmt#RustfmtConfigOptions()
endif
" Default to edition 2018 in case no rustfmt.toml was found.
- return '--edition 2018'
+ return default
endfunction
function! s:RustfmtCommandRange(filename, line1, line2)
diff --git a/runtime/doc/ft_rust.txt b/runtime/doc/ft_rust.txt
index 564f3e774..30b23ced1 100644
--- a/runtime/doc/ft_rust.txt
+++ b/runtime/doc/ft_rust.txt
@@ -159,7 +159,20 @@ g:rustfmt_emit_files~
determines whether to run rustfmt with '--emit=files' (when 1 is
provided) instead of '--write-mode=overwrite'. >
let g:rustfmt_emit_files = 0
-
+<
+
*g:rustfmt_detect_version*
+g:rustfmt_detect_version~
+ When set to 1, will try to parse the version output from "rustfmt".
+ Disabled by default for performance reasons
+>
+ let g:rustfmt_detect_version = 1
+<
+ *g:rustfmt_find_toml*
+g:rustfmt_emit_files~
+ When set to 1, will try to find "rustfmt.toml" file by searching from
+ current path upwards. Disabled by default for performance reasons
+>
+ let g:rustfmt_find_toml = 1
<
*g:rust_playpen_url*
g:rust_playpen_url~
diff --git a/runtime/doc/tags b/runtime/doc/tags
index d317ee7e7..b34b79a42 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -7851,8 +7851,10 @@ g:rustc_path ft_rust.txt /*g:rustc_path*
g:rustfmt_autosave ft_rust.txt /*g:rustfmt_autosave*
g:rustfmt_autosave_if_config_present ft_rust.txt
/*g:rustfmt_autosave_if_config_present*
g:rustfmt_command ft_rust.txt /*g:rustfmt_command*
+g:rustfmt_detect_version ft_rust.txt /*g:rustfmt_detect_version*
g:rustfmt_emit_files ft_rust.txt /*g:rustfmt_emit_files*
g:rustfmt_fail_silently ft_rust.txt /*g:rustfmt_fail_silently*
+g:rustfmt_find_toml ft_rust.txt /*g:rustfmt_find_toml*
g:rustfmt_options ft_rust.txt /*g:rustfmt_options*
g:statusline_winid options.txt /*g:statusline_winid*
g:syntax_on syntax.txt /*g:syntax_on*
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1udPfP-00GqN9-DR%40256bit.org.