From b0bd82bfc43a8c5ac1a5c484e058564113eed26c Mon Sep 17 00:00:00 2001 From: mar Date: Fri, 15 Nov 2024 12:13:06 +0100 Subject: [PATCH 1/2] add support for reading rustfmt configs according to https://rust-lang.github.io/rustfmt/ --- autoload/rustfmt.vim | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/autoload/rustfmt.vim b/autoload/rustfmt.vim index 59a58e84..e7ea1762 100644 --- a/autoload/rustfmt.vim +++ b/autoload/rustfmt.vim @@ -61,6 +61,26 @@ function! s:RustfmtWriteMode() endfunction function! s:RustfmtConfigOptions() + let l:rustfmt_toml = findfile(expand('$HOME/rustfmt.toml'), expand('%:p:h') . ';') + if l:rustfmt_toml !=# '' + return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) + endif + + let l:rustfmt_toml = findfile(expand('$HOME/.rustfmt.toml'), expand('%:p:h') . ';') + if l:rustfmt_toml !=# '' + return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) + endif + + let l:rustfmt_toml = findfile(expand('$HOME/.config/rustfmt/rustfmt.toml'), expand('%:p:h') . ';') + if l:rustfmt_toml !=# '' + return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) + endif + + let l:rustfmt_toml = findfile(expand('$HOME/.config/rustfmt/.rustfmt.toml'), expand('%:p:h') . ';') + if l:rustfmt_toml !=# '' + return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) + endif + let l:rustfmt_toml = findfile('rustfmt.toml', expand('%:p:h') . ';') if l:rustfmt_toml !=# '' return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) From a029dc3e2ee97f626080ef54ef7ecb6972cd20bf Mon Sep 17 00:00:00 2001 From: mar Date: Fri, 15 Nov 2024 12:17:24 +0100 Subject: [PATCH 2/2] change the rustfmt.toml order to mimick rustfmt --- autoload/rustfmt.vim | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/autoload/rustfmt.vim b/autoload/rustfmt.vim index e7ea1762..0442a7ee 100644 --- a/autoload/rustfmt.vim +++ b/autoload/rustfmt.vim @@ -61,34 +61,34 @@ function! s:RustfmtWriteMode() endfunction function! s:RustfmtConfigOptions() - let l:rustfmt_toml = findfile(expand('$HOME/rustfmt.toml'), expand('%:p:h') . ';') + let l:rustfmt_toml = findfile('rustfmt.toml', expand('%:p:h') . ';') if l:rustfmt_toml !=# '' return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) endif - let l:rustfmt_toml = findfile(expand('$HOME/.rustfmt.toml'), expand('%:p:h') . ';') - if l:rustfmt_toml !=# '' - return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) + let l:_rustfmt_toml = findfile('.rustfmt.toml', expand('%:p:h') . ';') + if l:_rustfmt_toml !=# '' + return '--config-path '.shellescape(fnamemodify(l:_rustfmt_toml, ":p")) endif - let l:rustfmt_toml = findfile(expand('$HOME/.config/rustfmt/rustfmt.toml'), expand('%:p:h') . ';') + let l:rustfmt_toml = findfile(expand('$HOME/rustfmt.toml'), expand('%:p:h') . ';') if l:rustfmt_toml !=# '' return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) endif - let l:rustfmt_toml = findfile(expand('$HOME/.config/rustfmt/.rustfmt.toml'), expand('%:p:h') . ';') + let l:rustfmt_toml = findfile(expand('$HOME/.rustfmt.toml'), expand('%:p:h') . ';') if l:rustfmt_toml !=# '' return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) endif - let l:rustfmt_toml = findfile('rustfmt.toml', expand('%:p:h') . ';') + let l:rustfmt_toml = findfile(expand('$HOME/.config/rustfmt/rustfmt.toml'), expand('%:p:h') . ';') if l:rustfmt_toml !=# '' return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) endif - let l:_rustfmt_toml = findfile('.rustfmt.toml', expand('%:p:h') . ';') - if l:_rustfmt_toml !=# '' - return '--config-path '.shellescape(fnamemodify(l:_rustfmt_toml, ":p")) + let l:rustfmt_toml = findfile(expand('$HOME/.config/rustfmt/.rustfmt.toml'), expand('%:p:h') . ';') + if l:rustfmt_toml !=# '' + return '--config-path '.shellescape(fnamemodify(l:rustfmt_toml, ":p")) endif " Default to edition 2018 in case no rustfmt.toml was found.