vim-patch:5c2b594: runtime(rust): Update indentation after nested array literal (#37177)

fixes:  vim/vim#18974
closes: vim/vim#19042

5c2b594d0e

Co-authored-by: Brian Carbone <brian@briancarbone.com>
This commit is contained in:
zeertzjq
2025-12-31 18:53:06 +08:00
committed by GitHub
parent 8e80e54478
commit dddb125b0b

View File

@@ -4,6 +4,7 @@
" Last Change: 2023-09-11
" 2024 Jul 04 by Vim Project: use shiftwidth() instead of hard-coding shifted values #15138
" 2025 Dec 29 by Vim Project: clean up
" 2025 Dec 31 by Vim Project: correcly indent after nested array literal #19042
" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
" Note: upstream seems umaintained: https://github.com/rust-lang/rust.vim/issues/502
@@ -195,6 +196,22 @@ function GetRustIndent(lnum)
endif
endif
" Prevent cindent from becoming confused when pairing square brackets, as
" in
"
" let arr = [[u8; 4]; 2] = [
" [0; 4],
" [1, 3, 5, 9],
" ];
" | ← indentation placed here
"
" for which it calculates too much indentation in the line following the
" close of the array.
if prevline =~# '^\s*\]' && l:last_prevline_character ==# ';'
\ && line !~# '^\s*}'
return indent(prevlinenum)
endif
if l:last_prevline_character ==# ","
\ && s:get_line_trimmed(a:lnum) !~# '^\s*[\[\]{})]'
\ && prevline !~# '^\s*fn\s'